132 lines
2.7 KiB
C++
132 lines
2.7 KiB
C++
|
|
#include "mydevices.h"
|
|
//int luminosite_environnement = 200;
|
|
|
|
using namespace std;
|
|
|
|
//DigitalDevice ///////////////////
|
|
DigitalDevice::DigitalDevice(int temps) : Device(), temps(temps), state(0) {}
|
|
|
|
int DigitalDevice::getState() const {
|
|
return state;
|
|
}
|
|
|
|
int DigitalDevice::getTemps() const {
|
|
return temps;
|
|
}
|
|
|
|
//AnalogDevice ///////////////////
|
|
|
|
AnalogDevice::AnalogDevice(int val, int temps) : Device(), val(val), temps(temps) {}
|
|
|
|
int AnalogDevice::getVal() const {
|
|
return val;
|
|
}
|
|
|
|
int AnalogDevice::getTemps() const {
|
|
return temps;
|
|
}
|
|
|
|
//classe AnalogSensorTemperature
|
|
AnalogSensorTemperature::AnalogSensorTemperature(int val,int temps):AnalogDevice(val,temps){
|
|
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);
|
|
}
|
|
}
|
|
|
|
// IntelligentDigitalActuatorLED //////////////////
|
|
IntelligentDigitalActuatorLED::IntelligentDigitalActuatorLED(int t):DigitalDevice(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);
|
|
}
|
|
}
|
|
|
|
|
|
//ExternalDigDevice/////////////////////////
|
|
|
|
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps):DigitalDevice(temps) {}
|
|
|
|
int ExternalDigitalSensorButton::getState(){
|
|
setState(); //determine if on.txt exists before getting state
|
|
return state;
|
|
}
|
|
|
|
void ExternalDigitalSensorButton::setState() {
|
|
if (ifstream("on.txt")){
|
|
state = 1;
|
|
} else {
|
|
state = 0;
|
|
}
|
|
}
|
|
|
|
|
|
void ExternalDigitalSensorButton::run() {
|
|
while (1) {
|
|
*ptrmem = this->getState();
|
|
sleep(temps);
|
|
}
|
|
}
|
|
//
|
|
|
|
|
|
|
|
|