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.

68 lines
1.6 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. }
  12. // Pre-read hook (usually to populate registers with up-to-date data)
  13. void pre() {}
  14. // Post-read hook (usually to reset things)
  15. void post() {}
  16. // Return sensor status (true for ready)
  17. bool status() {
  18. return true;
  19. }
  20. // Return sensor last internal error
  21. int error() {
  22. return 0;
  23. }
  24. // Number of available slots
  25. unsigned char count() {
  26. return 1;
  27. }
  28. // Descriptive name of the sensor
  29. String name() {
  30. char buffer[20];
  31. snprintf(buffer, sizeof(buffer), "ANALOG @ GPIO%d", _gpio);
  32. return String(buffer);
  33. }
  34. // Descriptive name of the slot # index
  35. String slot(unsigned char index) {
  36. return name();
  37. }
  38. // Type for slot # index
  39. magnitude_t type(unsigned char index) {
  40. if (index == 0) return MAGNITUDE_ANALOG;
  41. return MAGNITUDE_NONE;
  42. }
  43. // Current value for slot # index
  44. double value(unsigned char index) {
  45. if (index == 0) return analogRead(_gpio);
  46. return 0;
  47. }
  48. private:
  49. unsigned char _gpio;
  50. };