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.

83 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_ACTIVE_POWER,
  11. MAGNITUDE_APPARENT_POWER,
  12. MAGNITUDE_REACTIVE_POWER,
  13. MAGNITUDE_VOLTAGE_POWER,
  14. MAGNITUDE_CURRENT_POWER,
  15. MAGNITUDE_ENERGY_POWER,
  16. MAGNITUDE_POWER_FACTOR,
  17. MAGNITUDE_ANALOG,
  18. MAGNITUDE_EVENTS,
  19. MAGNITUDE_MAX,
  20. } magnitude_t;
  21. #define SENSOR_ERROR_OK 0
  22. #define SENSOR_ERROR_OUT_OF_RANGE 1
  23. class BaseSensor {
  24. public:
  25. // Constructor
  26. BaseSensor() {}
  27. // Destructor
  28. ~BaseSensor() {}
  29. // General interrupt handler
  30. void InterruptHandler() {}
  31. // Loop-like method, call it in your main loop
  32. virtual void tick() {}
  33. // Pre-read hook (usually to populate registers with up-to-date data)
  34. virtual void pre() {}
  35. // Post-read hook (usually to reset things)
  36. virtual void post() {}
  37. // Descriptive name of the sensor
  38. virtual String name();
  39. // Descriptive name of the slot # index
  40. virtual String slot(unsigned char index);
  41. // Type for slot # index
  42. virtual magnitude_t type(unsigned char index);
  43. // Current value for slot # index
  44. virtual double value(unsigned char index);
  45. // Return sensor status (true for ready)
  46. bool status() { return _error == 0; }
  47. // Return sensor last internal error
  48. int error() { return _error; }
  49. // Number of available slots
  50. unsigned char count() { return _count; }
  51. protected:
  52. int _error = 0;
  53. unsigned char _count = 0;
  54. };