Domotique/WifiControlSensor/GPIOSensor.cpp

34 lines
648 B
C++
Raw Normal View History

2016-11-20 18:08:15 +01:00
#include "GPIOSensor.h"
GPIOSensor::GPIOSensor(char *sName, char *mName,
uint8_t gpioPin, bool analog, int8_t power):
sensorName(sName), measureName(mName),
gpio(gpioPin), isAnalog(analog), powerGpio(power), lastMeasure(0){
if(powerGpio >= 0){
pinMode(powerGpio, OUTPUT);
}
}
int GPIOSensor::getMeasure(int &level){
if(powerGpio >= 0){
digitalWrite(powerGpio, HIGH);
delay(50);
}
if(isAnalog)
level = analogRead(gpio);
else
level = digitalRead(gpio);
if(powerGpio >= 0){
digitalWrite(powerGpio, LOW);
delay(50);
}
lastMeasure = level;
return 0;
}
int GPIOSensor::getLastMeasure(){
return lastMeasure;
}