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.

70 lines
1.9 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  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. // Set ADC to TOUT pin
  8. #undef ADC_MODE_VALUE
  9. #define ADC_MODE_VALUE ADC_TOUT
  10. #include "Arduino.h"
  11. #include "BaseSensor.h"
  12. class AnalogSensor : public BaseSensor {
  13. public:
  14. // ---------------------------------------------------------------------
  15. // Public
  16. // ---------------------------------------------------------------------
  17. AnalogSensor(): BaseSensor() {
  18. _count = 1;
  19. _sensor_id = SENSOR_ANALOG_ID;
  20. }
  21. // ---------------------------------------------------------------------
  22. // Sensor API
  23. // ---------------------------------------------------------------------
  24. // Initialization method, must be idempotent
  25. void begin() {
  26. pinMode(0, INPUT);
  27. _ready = true;
  28. }
  29. // Descriptive name of the sensor
  30. String description() {
  31. return String("ANALOG @ TOUT");
  32. }
  33. // Descriptive name of the slot # index
  34. String slot(unsigned char index) {
  35. return description();
  36. };
  37. // Address of the sensor (it could be the GPIO or I2C address)
  38. String address(unsigned char index) {
  39. return String("0");
  40. }
  41. // Type for slot # index
  42. unsigned char type(unsigned char index) {
  43. if (index == 0) return MAGNITUDE_ANALOG;
  44. return MAGNITUDE_NONE;
  45. }
  46. // Current value for slot # index
  47. double value(unsigned char index) {
  48. if (index == 0) return analogRead(0);
  49. return 0;
  50. }
  51. };
  52. #endif // SENSOR_SUPPORT && ANALOG_SUPPORT