Projet_VictorAvecUnK/mydevices.cpp

101 lines
2 KiB
C++
Raw Normal View History

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;
//classe AnalogSensorTemperature
AnalogSensorTemperature::AnalogSensorTemperature(int d,int t):Device(),val(t),temps(d){
alea=1;
}
void AnalogSensorTemperature::run(){
while(1){
alea=1-alea;
if(ptrmem!=NULL)
*ptrmem=val+alea;
sleep(temps);
}
}
2020-05-12 11:22:59 +02:00
//int AnalogSensorLuminosity::luminosite_environnement = 200;
AnalogSensorLuminosity::AnalogSensorLuminosity(int t):Device(), temps(t){
}
void AnalogSensorLuminosity::run(){
while(1){
val = luminosite_environnement;
if(ptrmem!=NULL){
*ptrmem = val;
}
sleep(temps);
}
}
2020-05-12 09:52:03 +02:00
//classe DigitalActuatorLED
DigitalActuatorLED::DigitalActuatorLED(int t):Device(),state(LOW),temps(t){
}
void DigitalActuatorLED::run(){
while(1){
if(ptrmem!=NULL)
state=*ptrmem;
if (state==LOW)
cout << "((((eteint))))\n";
else
cout << "((((allume))))\n";
sleep(temps);
}
}
2020-05-12 11:22:59 +02:00
IntelligentDigitalActuatorLED::IntelligentDigitalActuatorLED(int t):Device(),state(LOW),temps(t){
}
void IntelligentDigitalActuatorLED::run(){
int previousState = LOW; //initialisée 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);
}
}