LOGGER
Logger
Data Logging using ESP8266
|
#include <arduino.h>
#include "pincounter.h"
#include "sensorlibrary.h"
#include "services.h"
#include "huzzahpins.h"
Macros | |
#define | pincounterEdit 1 |
version of this module | |
#define | MINIMUM_PULSE_LENGTH 10 |
Minimum time a pin must be low to count as a pulse (in ms). | |
#define | NUM_PULSE_RING 16 |
Functions | |
EXTERNDEF void | pincounterCountPulse (uint8_t pulseID) |
EXTERNDEF void | pincounterInit () |
Initialize the counting services, call once at system startup. | |
EXTERNDEF uint32_t | pincounterPulses (uint8_t *, uint8_t pinID) |
EXTERNDEF uint32_t | pincounterFrequency (uint8_t *, uint8_t pinID) |
EXTERNDEF void | pincounterSetPulsesSinceBoot (uint8_t pinID, uint32_t pulses, uint8_t sensorID) |
EXTERNDEF void | pincounterDump () |
Dump the status of the pin counting routines. | |
Services associated with counting the number of times a pin transitions.
#define NUM_PULSE_RING 16 |
Each time a pulse starts a time stamp delta is logged in a ring buffer. A running total of the members of the ring buffer is kept. The average is the running total divided by the number of entries. The running total is kept in the ISR so there will be no issues with the stamp values changing out from under the logging. NUM_PULSE_RING is the number of elements to average pulses over.
EXTERNDEF void pincounterCountPulse | ( | uint8_t | pulseID | ) |
Routine to call when a pin has transitioned to low. It is safe to call this from an ISR, but, typically it is called from code that polls sensor devices at a higher level.
pulseID | pulse ID is used as a table index |
EXTERNDEF uint32_t pincounterFrequency | ( | uint8_t * | , |
uint8_t | pinID | ||
) |
Report the frequency in thousands of pulses per minute that the counter is observing. There is some smoothing of the frequency by averaging over multiple counts.
The first parameter is to make the call compatible with sensor reading
pinID | ID of pin to read |
EXTERNDEF uint32_t pincounterPulses | ( | uint8_t * | unused, |
uint8_t | pinID | ||
) |
Report the number of pulses seen. Pulses are counted at each falling edge.
unused | to make the call compatible with sensor reading |
pinID | ID of pin to read |
EXTERNDEF void pincounterSetPulsesSinceBoot | ( | uint8_t | pinID, |
uint32_t | pulses, | ||
uint8_t | sensorID | ||
) |
Set the number of pulses seen since boot.
pinID | ID of pin to set count for |
pulses | pulses since boot for the pin |
sensorID | sensor that detects these pulses |