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.

84 lines
1.8 KiB

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