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.

96 lines
1.9 KiB

  1. /*
  2. Example for SENSOR MODULE
  3. Copyright (C) 2020 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
  4. */
  5. // In sensor.cpp:
  6. // - #include "sensors/DummySensor.h"
  7. // - add `_sensors.push_back(new DummySensor());` at the end of _sensorLoad();
  8. #include "BaseSensor.h"
  9. struct DummySensor : public BaseSensor {
  10. DummySensor() :
  11. _temperature(25.0),
  12. _humidity(50.0),
  13. _pressure(1000.0),
  14. _lux(0.0)
  15. {
  16. _count = 4;
  17. }
  18. void begin() override {
  19. _ready = true;
  20. _error = SENSOR_ERROR_OK;
  21. }
  22. String description() override {
  23. static String dummy(F("Dummy"));
  24. return dummy;
  25. }
  26. String description(unsigned char) override {
  27. return description();
  28. }
  29. String address(unsigned char) override {
  30. static String dummy(F("/dev/null"));
  31. return dummy;
  32. }
  33. unsigned char type(unsigned char index) override {
  34. switch (index) {
  35. case 0: return MAGNITUDE_TEMPERATURE;
  36. case 1: return MAGNITUDE_HUMIDITY;
  37. case 2: return MAGNITUDE_PRESSURE;
  38. case 3: return MAGNITUDE_LUX;
  39. }
  40. return MAGNITUDE_NONE;
  41. }
  42. double value(unsigned char index) override {
  43. switch (index) {
  44. case 0: return _temperature;
  45. case 1: return _humidity;
  46. case 2: return _pressure;
  47. case 3: return _lux;
  48. }
  49. return 0.0;
  50. }
  51. void pre() override {
  52. ++_temperature;
  53. ++_humidity;
  54. ++_pressure;
  55. ++_lux;
  56. if (_temperature >= 40.0) {
  57. _temperature = 0.0;
  58. }
  59. if (_humidity >= 100.0) {
  60. _humidity = 20.0;
  61. }
  62. if (_pressure >= 1024.0) {
  63. _pressure = 980.0;
  64. }
  65. if (_lux >= 100.0) {
  66. _lux = 0.0;
  67. }
  68. }
  69. private:
  70. double _temperature;
  71. double _humidity;
  72. double _pressure;
  73. double _lux;
  74. };