Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.0 KiB

  1. // -----------------------------------------------------------------------------
  2. // Median Filter
  3. // -----------------------------------------------------------------------------
  4. #pragma once
  5. #include <Arduino.h>
  6. typedef enum magnitude_t {
  7. MAGNITUDE_NONE = 0,
  8. MAGNITUDE_TEMPERATURE,
  9. MAGNITUDE_HUMIDITY,
  10. MAGNITUDE_PRESSURE,
  11. MAGNITUDE_CURRENT,
  12. MAGNITUDE_VOLTAGE,
  13. MAGNITUDE_POWER_ACTIVE,
  14. MAGNITUDE_POWER_APPARENT,
  15. MAGNITUDE_POWER_REACTIVE,
  16. MAGNITUDE_ENERGY,
  17. MAGNITUDE_ENERGY_DELTA,
  18. MAGNITUDE_POWER_FACTOR,
  19. MAGNITUDE_ANALOG,
  20. MAGNITUDE_DIGITAL,
  21. MAGNITUDE_EVENTS,
  22. MAGNITUDE_PM1dot0,
  23. MAGNITUDE_PM2dot5,
  24. MAGNITUDE_PM10,
  25. MAGNITUDE_MAX,
  26. } magnitude_t;
  27. #define SENSOR_ERROR_OK 0
  28. #define SENSOR_ERROR_OUT_OF_RANGE 1
  29. #define SENSOR_ERROR_WARM_UP 2
  30. class BaseSensor {
  31. public:
  32. // Constructor
  33. BaseSensor() {}
  34. // Destructor
  35. ~BaseSensor() {}
  36. // General interrupt handler
  37. virtual void InterruptHandler() {}
  38. // Loop-like method, call it in your main loop
  39. virtual void tick() {}
  40. // Pre-read hook (usually to populate registers with up-to-date data)
  41. virtual void pre() {}
  42. // Post-read hook (usually to reset things)
  43. virtual void post() {}
  44. // Descriptive name of the sensor
  45. virtual String name() {}
  46. // Descriptive name of the slot # index
  47. virtual String slot(unsigned char index) {}
  48. // Type for slot # index
  49. virtual magnitude_t type(unsigned char index) {}
  50. // Current value for slot # index
  51. virtual double value(unsigned char index) {}
  52. // Return sensor status (true for ready)
  53. bool status() { return _error == 0; }
  54. // Return sensor last internal error
  55. int error() { return _error; }
  56. // Number of available slots
  57. unsigned char count() { return _count; }
  58. protected:
  59. int _error = 0;
  60. unsigned char _count = 0;
  61. };