diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4327633 Binary files /dev/null and b/.DS_Store differ diff --git a/board.cpp b/board.cpp index c3f5cba..25a08dc 100644 --- a/board.cpp +++ b/board.cpp @@ -7,12 +7,15 @@ int main(){ Board esp8266; // achat des senseurs et actionneurs AnalogSensorTemperature temperature(DELAY,TEMP); - DigitalActuatorLED led1(DELAY); + //DigitalActuatorLED led1(DELAY); + IntelligentDigitalActuatorLED led1(DELAY); I2CActuatorScreen screen; + AnalogSensorLuminosity luminosite(DELAY); // branchement des capteurs actionneurs esp8266.pin(1,temperature); esp8266.pin(0,led1); + esp8266.pin(2, luminosite); esp8266.i2c(1,screen); // allumage de la carte diff --git a/compile_mac.sh b/compile_mac.sh new file mode 100755 index 0000000..f96c12e --- /dev/null +++ b/compile_mac.sh @@ -0,0 +1,3 @@ + #!/usr/bin/bash +echo "g++ -Wall -std=c++11 board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp -o arduino" +g++ -Wall -std=c++11 board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp -o arduino diff --git a/mydevices.cpp b/mydevices.cpp index 3d0771b..ee5aa5a 100644 --- a/mydevices.cpp +++ b/mydevices.cpp @@ -1,5 +1,6 @@ #include "mydevices.h" +//int luminosite_environnement = 200; using namespace std; @@ -17,6 +18,22 @@ void AnalogSensorTemperature::run(){ } } +//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){ } @@ -33,6 +50,37 @@ void DigitalActuatorLED::run(){ } } + + +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){ + //AnalogSensorLuminosity::luminosite_environnement-= 50; + } + previousState = LOW; + } + else{ //state == HIGH + cout << "((((allume))))\n"; + if(state != previousState){ + //AnalogSensorLuminosity::luminosite_environnement+= 50; + } + previousState = HIGH; + } + sleep(temps); + } +} + + + + // classe I2CActuatorScreen I2CActuatorScreen::I2CActuatorScreen ():Device(){ } @@ -50,4 +98,3 @@ void I2CActuatorScreen::run(){ - diff --git a/mydevices.h b/mydevices.h index b619b4c..29a8bb4 100644 --- a/mydevices.h +++ b/mydevices.h @@ -7,6 +7,8 @@ #include #include "core_simulation.h" +int luminosite_environnement = 200; + // exemple de capteur analogique de temperature, ne pas oublier d'heriter de Device class AnalogSensorTemperature: public Device { @@ -25,6 +27,25 @@ public: virtual void run(); }; + +class AnalogSensorLuminosity: public Device{ +private: + int temps; + int val; + //static int luminosite_environnement; +public: + //static int luminosite_environnement; + AnalogSensorLuminosity(int t); + virtual void run(); +}; + + + + + + + + // exemple d'actionneur digital : une led, ne pas oublier d'heriter de Device class DigitalActuatorLED: public Device { private: @@ -40,6 +61,25 @@ public: virtual void run(); }; + + +class IntelligentDigitalActuatorLED: public Device{ + private: + // etat de la LED + int state; + // temps entre 2 affichage de l etat de la led + int temps; + + public: + // initialisation du temps de rafraichiisement + IntelligentDigitalActuatorLED(int t); + // thread representant l'actionneur et permettant de fonctionner independamment de la board + virtual void run(); + }; + + + + // exemple d'actionneur sur le bus I2C permettant d'echanger des tableaux de caracteres : un ecran, ne pas oublier d'heriter de Device class I2CActuatorScreen : public Device{ protected: @@ -53,4 +93,12 @@ public: virtual void run(); }; + + + +//class ExternalDigitalSensorButton: public Device + + + + #endif diff --git a/sketch_ino.cpp b/sketch_ino.cpp index f8147cb..fef0877 100644 --- a/sketch_ino.cpp +++ b/sketch_ino.cpp @@ -8,24 +8,34 @@ void Board::setup(){ // on fixe les pin en entree et en sorite en fonction des capteurs/actionneurs mis sur la carte pinMode(1,INPUT); pinMode(0,OUTPUT); + pinMode(2,INPUT); } // la boucle de controle arduino void Board::loop(){ char buf[100]; int val; + int val1; static int cpt=0; static int bascule=0; int i=0; for(i=0;i<10;i++){ // lecture sur la pin 1 : capteur de temperature - val=analogRead(1); - sprintf(buf,"temperature %d",val); + val1=analogRead(1); + sprintf(buf,"temperature %d",val1); Serial.println(buf); + + // lecture sur la pin 2 : capteur de temperature + val=analogRead(2); + sprintf(buf,"luminosite %d",val); + Serial.println(buf); + if(cpt%5==0){ // tous les 5 fois on affiche sur l ecran la temperature - sprintf(buf,"%d",val); + sprintf(buf,"%d",val1); bus.write(1,buf,100); + + } cpt++; sleep(1);