34 lines
648 B
C++
34 lines
648 B
C++
|
#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;
|
||
|
}
|