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.

48 lines
1.1 KiB

  1. // -----------------------------------------------------------------------------
  2. // DHT Sensor
  3. // -----------------------------------------------------------------------------
  4. #pragma once
  5. #include "Arduino.h"
  6. #include "BaseSensor.h"
  7. class AnalogSensor : public BaseSensor {
  8. public:
  9. AnalogSensor(unsigned char gpio): BaseSensor() {
  10. _gpio = gpio;
  11. _count = 1;
  12. }
  13. // Descriptive name of the sensor
  14. String name() {
  15. char buffer[20];
  16. snprintf(buffer, sizeof(buffer), "ANALOG @ GPIO%d", _gpio);
  17. return String(buffer);
  18. }
  19. // Descriptive name of the slot # index
  20. String slot(unsigned char index) {
  21. return name();
  22. }
  23. // Type for slot # index
  24. magnitude_t type(unsigned char index) {
  25. if (index == 0) return MAGNITUDE_ANALOG;
  26. return MAGNITUDE_NONE;
  27. }
  28. // Current value for slot # index
  29. double value(unsigned char index) {
  30. if (index == 0) return analogRead(_gpio);
  31. return 0;
  32. }
  33. protected:
  34. unsigned char _gpio;
  35. };