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.

91 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_EVENTS,
  21. MAGNITUDE_PM1dot0,
  22. MAGNITUDE_PM2dot5,
  23. MAGNITUDE_PM10,
  24. MAGNITUDE_MAX,
  25. } magnitude_t;
  26. #define SENSOR_ERROR_OK 0
  27. #define SENSOR_ERROR_OUT_OF_RANGE 1
  28. #define SENSOR_ERROR_WARM_UP 2
  29. class BaseSensor {
  30. public:
  31. // Constructor
  32. BaseSensor() {}
  33. // Destructor
  34. ~BaseSensor() {}
  35. // General interrupt handler
  36. void InterruptHandler() {}
  37. // Loop-like method, call it in your main loop
  38. virtual void tick() {}
  39. // Pre-read hook (usually to populate registers with up-to-date data)
  40. virtual void pre() {}
  41. // Post-read hook (usually to reset things)
  42. virtual void post() {}
  43. // Descriptive name of the sensor
  44. virtual String name() {}
  45. // Descriptive name of the slot # index
  46. virtual String slot(unsigned char index) {}
  47. // Type for slot # index
  48. virtual magnitude_t type(unsigned char index) {}
  49. // Current value for slot # index
  50. virtual double value(unsigned char index) {}
  51. // Return sensor status (true for ready)
  52. bool status() { return _error == 0; }
  53. // Return sensor last internal error
  54. int error() { return _error; }
  55. // Number of available slots
  56. unsigned char count() { return _count; }
  57. protected:
  58. int _error = 0;
  59. unsigned char _count = 0;
  60. };