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.

97 lines
2.3 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_CO2,
  26. MAGNITUDE_MAX,
  27. } magnitude_t;
  28. #define SENSOR_ERROR_OK 0 // No error
  29. #define SENSOR_ERROR_OUT_OF_RANGE 1 // Result out of sensor range
  30. #define SENSOR_ERROR_WARM_UP 2 // Sensor is warming-up
  31. #define SENSOR_ERROR_TIMEOUT 3 // Response from sensor timed out
  32. #define SENSOR_ERROR_UNKNOWN_ID 4 // Sensor did not report a known ID
  33. #define SENSOR_ERROR_CRC 5 // Sensor data corrupted
  34. class BaseSensor {
  35. public:
  36. // Constructor
  37. BaseSensor() {}
  38. // Destructor
  39. ~BaseSensor() {}
  40. // General interrupt handler
  41. virtual void InterruptHandler() {}
  42. // Loop-like method, call it in your main loop
  43. virtual void tick() {}
  44. // Pre-read hook (usually to populate registers with up-to-date data)
  45. virtual void pre() {}
  46. // Post-read hook (usually to reset things)
  47. virtual void post() {}
  48. // Descriptive name of the sensor
  49. virtual String name() {}
  50. // Descriptive name of the slot # index
  51. virtual String slot(unsigned char index) {}
  52. // Type for slot # index
  53. virtual magnitude_t type(unsigned char index) {}
  54. // Current value for slot # index
  55. virtual double value(unsigned char index) {}
  56. // Return sensor status (true for ready)
  57. bool status() { return _error == 0; }
  58. // Return sensor last internal error
  59. int error() { return _error; }
  60. // Number of available slots
  61. unsigned char count() { return _count; }
  62. protected:
  63. int _error = 0;
  64. unsigned char _count = 0;
  65. };