118 lines
2.4 KiB
C++
118 lines
2.4 KiB
C++
|
|
#include "mydevices.h"
|
|
//int luminosite_environnement = 200;
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
//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);
|
|
}
|
|
}
|
|
|
|
|
|
//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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
IntelligentDigitalActuatorLED::IntelligentDigitalActuatorLED(int t):Device(),state(LOW),temps(t){
|
|
}
|
|
|
|
void IntelligentDigitalActuatorLED::run(){
|
|
int previousState = LOW; //initialisée a eteint
|
|
while(1){
|
|
if(ptrmem!=NULL)
|
|
state=*ptrmem;
|
|
if (state==LOW ){
|
|
cout << "((((eteint))))\n";
|
|
if(state != previousState){
|
|
luminosite_environnement-= 50;
|
|
}
|
|
previousState = state;
|
|
}
|
|
else{ //state == HIGH
|
|
cout << "((((allume))))\n";
|
|
if(state != previousState){
|
|
luminosite_environnement+= 50;
|
|
}
|
|
previousState = state;
|
|
}
|
|
sleep(temps);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
|
|
int ExternalDigitalSensorButton::getState(){
|
|
if (ifstream("on.txt")){
|
|
state = 1;
|
|
} else {
|
|
state = 0;
|
|
}
|
|
return state;
|
|
}
|
|
|
|
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps) {
|
|
state = 0;
|
|
this->temps = temps;
|
|
}
|
|
|
|
void ExternalDigitalSensorButton::run() {
|
|
while (1) {
|
|
*ptrmem = this->getState();
|
|
sleep(temps);
|
|
}
|
|
}
|