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.

66 lines
1.8 KiB

  1. // -----------------------------------------------------------------------------
  2. // Analog Sensor (maps to an analogRead)
  3. // Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
  4. // -----------------------------------------------------------------------------
  5. #if SENSOR_SUPPORT && ANALOG_SUPPORT
  6. #pragma once
  7. #include "Arduino.h"
  8. #include "BaseSensor.h"
  9. class AnalogSensor : public BaseSensor {
  10. public:
  11. // ---------------------------------------------------------------------
  12. // Public
  13. // ---------------------------------------------------------------------
  14. AnalogSensor(): BaseSensor() {
  15. _count = 1;
  16. _sensor_id = SENSOR_ANALOG_ID;
  17. }
  18. // ---------------------------------------------------------------------
  19. // Sensor API
  20. // ---------------------------------------------------------------------
  21. // Initialization method, must be idempotent
  22. void begin() {
  23. pinMode(0, INPUT);
  24. _ready = true;
  25. }
  26. // Descriptive name of the sensor
  27. String description() {
  28. return String("ANALOG @ TOUT");
  29. }
  30. // Descriptive name of the slot # index
  31. String slot(unsigned char index) {
  32. return description();
  33. };
  34. // Address of the sensor (it could be the GPIO or I2C address)
  35. String address(unsigned char index) {
  36. return String("0");
  37. }
  38. // Type for slot # index
  39. unsigned char 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(0);
  46. return 0;
  47. }
  48. };
  49. #endif // SENSOR_SUPPORT && ANALOG_SUPPORT