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.

55 lines
1.6 KiB

  1. // -----------------------------------------------------------------------------
  2. // Analog Sensor (maps to an analogRead)
  3. // Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. // -----------------------------------------------------------------------------
  5. #pragma once
  6. #include "Arduino.h"
  7. #include "BaseSensor.h"
  8. class AnalogSensor : public BaseSensor {
  9. public:
  10. // ---------------------------------------------------------------------
  11. // Public
  12. // ---------------------------------------------------------------------
  13. AnalogSensor(): BaseSensor() {
  14. _count = 1;
  15. _sensor_id = SENSOR_ANALOG_ID;
  16. }
  17. // ---------------------------------------------------------------------
  18. // Sensor API
  19. // ---------------------------------------------------------------------
  20. // Initialization method, must be idempotent
  21. void begin() {
  22. pinMode(0, INPUT);
  23. }
  24. // Descriptive name of the sensor
  25. String description() {
  26. return String("ANALOG @ GPIO0");
  27. }
  28. // Type for slot # index
  29. magnitude_t type(unsigned char index) {
  30. _error = SENSOR_ERROR_OK;
  31. if (index == 0) return MAGNITUDE_ANALOG;
  32. _error = SENSOR_ERROR_OUT_OF_RANGE;
  33. return MAGNITUDE_NONE;
  34. }
  35. // Current value for slot # index
  36. double value(unsigned char index) {
  37. _error = SENSOR_ERROR_OK;
  38. if (index == 0) return analogRead(0);
  39. _error = SENSOR_ERROR_OUT_OF_RANGE;
  40. return 0;
  41. }
  42. };