Browse Source

Simplify AnalogSensor

fastled
Xose Pérez 6 years ago
parent
commit
bb82a4936e
3 changed files with 7 additions and 26 deletions
  1. +0
    -8
      code/espurna/config/sensors.h
  2. +0
    -1
      code/espurna/sensor.ino
  3. +7
    -17
      code/espurna/sensors/AnalogSensor.h

+ 0
- 8
code/espurna/config/sensors.h View File

@ -74,14 +74,6 @@
#define ANALOG_SUPPORT 0
#endif
#ifndef ANALOG_PIN
#define ANALOG_PIN 0
#endif
#ifndef ANALOG_PIN_MODE
#define ANALOG_PIN_MODE INPUT
#endif
#if ANALOG_SUPPORT
#undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0


+ 0
- 1
code/espurna/sensor.ino View File

@ -204,7 +204,6 @@ void _sensorInit() {
#if ANALOG_SUPPORT
{
AnalogSensor * sensor = new AnalogSensor();
sensor->setGPIO(ANALOG_PIN, ANALOG_PIN_MODE);
_sensorRegister(sensor);
}
#endif


+ 7
- 17
code/espurna/sensors/AnalogSensor.h View File

@ -20,20 +20,18 @@ class AnalogSensor : public BaseSensor {
_count = 1;
}
void setGPIO(unsigned char gpio, unsigned char mode = INPUT) {
_gpio = gpio;
pinMode(_gpio, mode);
}
// ---------------------------------------------------------------------
// Sensor API
// ---------------------------------------------------------------------
// Initialization method, must be idempotent
void begin() {
pinMode(0, INPUT);
}
// Descriptive name of the sensor
String name() {
char buffer[20];
snprintf(buffer, sizeof(buffer), "ANALOG @ GPIO%d", _gpio);
return String(buffer);
return String("ANALOG @ GPIO0");
}
// Descriptive name of the slot # index
@ -52,18 +50,10 @@ class AnalogSensor : public BaseSensor {
// Current value for slot # index
double value(unsigned char index) {
_error = SENSOR_ERROR_OK;
if (index == 0) return analogRead(_gpio);
if (index == 0) return analogRead(0);
_error = SENSOR_ERROR_OUT_OF_RANGE;
return 0;
}
protected:
// ---------------------------------------------------------------------
// Protected
// ---------------------------------------------------------------------
unsigned char _gpio;
};

Loading…
Cancel
Save