2020-05-12 09:52:03 +02:00
|
|
|
|
|
|
|
#include "mydevices.h"
|
2020-05-12 11:22:59 +02:00
|
|
|
//int luminosite_environnement = 200;
|
2020-05-12 09:52:03 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2020-05-13 16:12:29 +02:00
|
|
|
//DigitalDevice ///////////////////
|
2020-05-13 16:16:45 +02:00
|
|
|
DigitalDevice::DigitalDevice(int temps) : Device(), state(0), temps(temps) {}
|
2020-05-13 16:12:29 +02:00
|
|
|
|
|
|
|
int DigitalDevice::getState() const {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DigitalDevice::getTemps() const {
|
|
|
|
return temps;
|
|
|
|
}
|
|
|
|
|
|
|
|
//AnalogDevice ///////////////////
|
|
|
|
|
2020-05-13 16:15:59 +02:00
|
|
|
AnalogDevice::AnalogDevice(int val, int temps) : Device(), val(val), temps(temps) {}
|
2020-05-13 16:12:29 +02:00
|
|
|
|
|
|
|
int AnalogDevice::getVal() const {
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AnalogDevice::getTemps() const {
|
|
|
|
return temps;
|
|
|
|
}
|
|
|
|
|
2020-05-12 09:52:03 +02:00
|
|
|
//classe AnalogSensorTemperature
|
2020-05-13 16:12:29 +02:00
|
|
|
AnalogSensorTemperature::AnalogSensorTemperature(int val,int temps):AnalogDevice(val,temps){
|
2020-05-12 09:52:03 +02:00
|
|
|
alea=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnalogSensorTemperature::run(){
|
|
|
|
while(1){
|
|
|
|
alea=1-alea;
|
|
|
|
if(ptrmem!=NULL)
|
|
|
|
*ptrmem=val+alea;
|
|
|
|
sleep(temps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 17:10:05 +02:00
|
|
|
//AnalogSensorLuminosity ///////////////////////////
|
|
|
|
AnalogSensorLuminosity::AnalogSensorLuminosity(int temps):AnalogDevice(200, temps){}
|
2020-05-12 11:22:59 +02:00
|
|
|
|
|
|
|
void AnalogSensorLuminosity::run(){
|
|
|
|
while(1){
|
|
|
|
val = luminosite_environnement;
|
|
|
|
if(ptrmem!=NULL){
|
|
|
|
*ptrmem = val;
|
|
|
|
}
|
|
|
|
sleep(temps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 16:12:29 +02:00
|
|
|
// IntelligentDigitalActuatorLED //////////////////
|
|
|
|
IntelligentDigitalActuatorLED::IntelligentDigitalActuatorLED(int t):DigitalDevice(t){
|
2020-05-12 11:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntelligentDigitalActuatorLED::run(){
|
2020-05-13 17:10:05 +02:00
|
|
|
int previousState = LOW; //initialisee a eteint
|
2020-05-12 11:43:08 +02:00
|
|
|
while(1){
|
|
|
|
if(ptrmem!=NULL)
|
|
|
|
state=*ptrmem;
|
|
|
|
if (state==LOW ){
|
|
|
|
cout << "((((eteint))))\n";
|
|
|
|
if(state != previousState){
|
|
|
|
luminosite_environnement-= 50;
|
|
|
|
}
|
|
|
|
previousState = state;
|
2020-05-12 11:22:59 +02:00
|
|
|
}
|
2020-05-12 11:43:08 +02:00
|
|
|
else{ //state == HIGH
|
|
|
|
cout << "((((allume))))\n";
|
|
|
|
if(state != previousState){
|
|
|
|
luminosite_environnement+= 50;
|
|
|
|
}
|
|
|
|
previousState = state;
|
2020-05-12 11:22:59 +02:00
|
|
|
}
|
2020-05-12 11:43:08 +02:00
|
|
|
sleep(temps);
|
2020-05-12 11:22:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-12 09:52:03 +02:00
|
|
|
// classe I2CActuatorScreen
|
|
|
|
I2CActuatorScreen::I2CActuatorScreen ():Device(){
|
|
|
|
}
|
|
|
|
|
|
|
|
void I2CActuatorScreen::run(){
|
|
|
|
while(1){
|
|
|
|
if ( (i2cbus!=NULL)&&!(i2cbus->isEmptyRegister(i2caddr))){
|
|
|
|
Device::i2cbus->requestFrom(i2caddr, buf, I2C_BUFFER_SIZE);
|
|
|
|
cout << "---screen :"<< buf << endl;
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-13 16:12:29 +02:00
|
|
|
//ExternalDigDevice/////////////////////////
|
|
|
|
|
|
|
|
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps):DigitalDevice(temps) {}
|
|
|
|
|
2020-05-12 12:33:35 +02:00
|
|
|
int ExternalDigitalSensorButton::getState(){
|
2020-05-13 16:12:29 +02:00
|
|
|
setState(); //determine if on.txt exists before getting state
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalDigitalSensorButton::setState() {
|
2020-05-12 12:33:35 +02:00
|
|
|
if (ifstream("on.txt")){
|
|
|
|
state = 1;
|
|
|
|
} else {
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 09:52:03 +02:00
|
|
|
|
|
|
|
|
2020-05-12 12:33:35 +02:00
|
|
|
void ExternalDigitalSensorButton::run() {
|
|
|
|
while (1) {
|
|
|
|
*ptrmem = this->getState();
|
|
|
|
sleep(temps);
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 17:10:05 +02:00
|
|
|
//TODO Capteur de temperature a revoir avec conditions
|
|
|
|
//TODO Electrovanne / moteur (a voir food)
|
|
|
|
//TODO Radiateur rechauffer terrarium
|
|
|
|
//TODO PHmetre pour qualite de l'eau
|
|
|
|
//TODO regarder les manometre
|
|
|
|
//TODO Electrovanne pour remplir la piscine
|
|
|
|
|
|
|
|
//TODO Ecran d'affichage avec infos de temps, derniere bouffe, infos sur tortues
|
|
|
|
//TODO Bouton pour sauter prochaine bouffe (I2C)
|
2020-05-13 16:12:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|