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.

52 lines
1.3 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. _error = SENSOR_ERROR_OK;
  26. if (index == 0) return MAGNITUDE_ANALOG;
  27. _error = SENSOR_ERROR_OUT_OF_RANGE;
  28. return MAGNITUDE_NONE;
  29. }
  30. // Current value for slot # index
  31. double value(unsigned char index) {
  32. _error = SENSOR_ERROR_OK;
  33. if (index == 0) return analogRead(_gpio);
  34. _error = SENSOR_ERROR_OUT_OF_RANGE;
  35. return 0;
  36. }
  37. protected:
  38. unsigned char _gpio;
  39. };