Browse Source

Playing with the sensor interrupt routines

fastled
Xose Pérez 7 years ago
parent
commit
1fd5cbe5fd
3 changed files with 18 additions and 16 deletions
  1. +1
    -1
      code/espurna/config/sensors.h
  2. +16
    -14
      code/espurna/sensor.ino
  3. +1
    -1
      code/espurna/sensors/BaseSensor.h

+ 1
- 1
code/espurna/config/sensors.h View File

@ -153,7 +153,7 @@
#endif
#define COUNTER_REPORT_EVERY 12 // Report counter every this updates (1 minute)
#define COUNTER_DEBOUNCE 10 // Do not register events within less than 10 millis
#define COUNTER_DEBOUNCE 50 // Do not register events within less than 10 millis
#define COUNTER_TOPIC "counter" // Default topic for MQTT, API and InfluxDB
//--------------------------------------------------------------------------------


+ 16
- 14
code/espurna/sensor.ino View File

@ -88,7 +88,7 @@ String _sensorUnits(magnitude_t type) {
if (type == MAGNITUDE_POWER_FACTOR) return String("%");
if (type == MAGNITUDE_ENERGY) return String("J");
if (type == MAGNITUDE_ENERGY_DELTA) return String("J");
if (type == MAGNITUDE_EVENTS) return String("/m");
if (type == MAGNITUDE_EVENTS) return String("/min");
if (type == MAGNITUDE_PM1dot0) return String("µg/m3");
if (type == MAGNITUDE_PM2dot5) return String("µg/m3");
if (type == MAGNITUDE_PM10) return String("µg/m3");
@ -186,13 +186,21 @@ void _sensorPost() {
}
// -----------------------------------------------------------------------------
// Values
// Interrupts
// -----------------------------------------------------------------------------
#if COUNTER_SUPPORT
void sensorISR() {
_sensors[_sensor_isr]->InterruptHandler();
unsigned char _event_sensor_id = 0;
void isrEventSensor() {
_sensors[_event_sensor_id]->InterruptHandler();
}
#endif // COUNTER_SUPPORT
// -----------------------------------------------------------------------------
// Values
// -----------------------------------------------------------------------------
void sensorRegister(BaseSensor * sensor) {
_sensors.push_back(sensor);
}
@ -220,11 +228,6 @@ unsigned char magnitudeType(unsigned char index) {
return MAGNITUDE_NONE;
}
void sensorInterrupt(unsigned char sensor_id, unsigned char gpio, int mode) {
_sensor_isr = sensor_id;
attachInterrupt(gpio, sensorISR, mode);
}
void sensorInit() {
#if DHT_SUPPORT
@ -273,11 +276,10 @@ void sensorInit() {
#endif
#if COUNTER_SUPPORT
if (_sensor_isr == 0xFF) {
#include "sensors/EventSensor.h"
sensorRegister(new EventSensor(COUNTER_PIN, COUNTER_PIN_MODE, COUNTER_DEBOUNCE));
sensorInterrupt(sensorCount()-1, COUNTER_PIN, COUNTER_INTERRUPT_MODE);
}
#include "sensors/EventSensor.h"
sensorRegister(new EventSensor(COUNTER_PIN, COUNTER_PIN_MODE, COUNTER_DEBOUNCE));
_event_sensor_id = sensorCount() - 1;
attachInterrupt(COUNTER_PIN, isrEventSensor, COUNTER_INTERRUPT_MODE);
#endif
}


+ 1
- 1
code/espurna/sensors/BaseSensor.h View File

@ -49,7 +49,7 @@ class BaseSensor {
~BaseSensor() {}
// General interrupt handler
void InterruptHandler() {}
virtual void InterruptHandler() {}
// Loop-like method, call it in your main loop
virtual void tick() {}


Loading…
Cancel
Save