134 lines
4.3 KiB
C++
134 lines
4.3 KiB
C++
#include <unistd.h>
|
|
#include "core_simulation.h"
|
|
#include "app/include/Terrarium.h"
|
|
#include "app/include/TerrariumParameter.h"
|
|
#include "app/include/Menu.h"
|
|
|
|
|
|
Terrarium terrarium(1);
|
|
TerrariumParameter temperature(25, 20);
|
|
TerrariumParameter pressure(3000,2990);
|
|
TerrariumParameter ph(8,6);
|
|
|
|
Menu *menu = new Menu();
|
|
|
|
|
|
|
|
|
|
// la fonction d'initialisation d'arduino
|
|
void Board::setup(){
|
|
// on configure la vitesse de la liaison
|
|
Serial.begin(9600);
|
|
// on fixe les pin en entree et en sorite en fonction des capteurs/actionneurs mis sur la carte
|
|
pinMode(1, INPUT);
|
|
pinMode(4, INPUT);
|
|
pinMode(5, INPUT);
|
|
pinMode(3, INPUT);
|
|
pinMode(6, INPUT);
|
|
pinMode(7, INPUT);
|
|
|
|
pinMode(0, OUTPUT);
|
|
pinMode(2, OUTPUT);
|
|
|
|
digitalWrite(0,LOW);
|
|
//pinMode(6, OUTPUT);
|
|
}
|
|
|
|
// la boucle de controle arduino
|
|
void Board::loop() {
|
|
char buf[100];
|
|
static int cpt = 0;
|
|
static int bascule = 0;
|
|
int i = 0;
|
|
std::string toDisplay;
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
TemperatureManagement();
|
|
PressureManagement();
|
|
|
|
|
|
if (menu->getId() == 0 && menu->displayDefault(temperature.getValue(),
|
|
pressure.getValue(),
|
|
terrarium.getRadState(),
|
|
terrarium.getTapState(),
|
|
0).c_str() != NULL) {
|
|
strcpy(buf, menu->displayDefault(temperature.getValue(),
|
|
pressure.getValue(),
|
|
terrarium.getRadState(),
|
|
terrarium.getTapState(),
|
|
0).c_str());
|
|
} else if (menu->getMessage().c_str() != NULL){
|
|
strcpy(buf, menu->getMessage().c_str());
|
|
}
|
|
|
|
if (i % 2 == 0) {
|
|
if (analogRead(3) == HIGH && (terrarium.getPrevState() != analogRead(3))) {
|
|
terrarium.setPrevState(HIGH);
|
|
menu->previousChoice();
|
|
} else if (analogRead(3) == LOW && (terrarium.getPrevState() != analogRead(3))) {
|
|
terrarium.setPrevState(LOW);
|
|
}
|
|
if (analogRead(4) == HIGH && (terrarium.getNextState() != analogRead(4))) {
|
|
terrarium.setNextState(HIGH);
|
|
menu->nextChoice();
|
|
} else if (analogRead(4) == LOW && (terrarium.getNextState() != analogRead(4))) {
|
|
terrarium.setNextState(LOW);
|
|
}
|
|
if (analogRead(6) == HIGH && (terrarium.getOkState() != analogRead(6))) {
|
|
terrarium.setOkState(HIGH);
|
|
cout << "OK" << endl;
|
|
menu->menuNext();
|
|
} else if (analogRead(6) == LOW && (terrarium.getOkState() != analogRead(6))) {
|
|
terrarium.setOkState(LOW);
|
|
cout << "NOK" << endl;
|
|
}
|
|
if (analogRead(7) == HIGH && (terrarium.getBackState() != analogRead(7))) {
|
|
terrarium.setBackState(HIGH);
|
|
menu->menuBack();
|
|
} else if (analogRead(7) == LOW && (terrarium.getBackState() != analogRead(7))) {
|
|
terrarium.setBackState(LOW);
|
|
}
|
|
}
|
|
|
|
// cout << buf << endl;
|
|
//sprintf(buf,"%s",menu.getMessage().c_str());
|
|
|
|
//sprintf(buf,"%f",temperature.getValue());
|
|
if (cpt % 5 == 0) bus.write(1, buf, 100);
|
|
cpt++;
|
|
sleep(1);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
void Board::TemperatureManagement() {
|
|
char buf[100];
|
|
temperature.setValue(analogRead(1));
|
|
//sprintf(buf, "temperature %f", temperature.getValue());
|
|
//Serial.println(buf);
|
|
|
|
if ((temperature.is2Low()) && (terrarium.getRadState() == LOW)) {
|
|
digitalWrite(0, HIGH);
|
|
terrarium.setRadState(HIGH);
|
|
} else if ((temperature.is2High()) && (terrarium.getRadState() == HIGH)) {
|
|
digitalWrite(0, LOW);
|
|
terrarium.setRadState(LOW);
|
|
}
|
|
}
|
|
|
|
void Board::PressureManagement() {
|
|
char buf[100];
|
|
pressure.setValue(analogRead(5));
|
|
//sprintf(buf, "pressure %f", pressure.getValue());
|
|
//Serial.println(buf);
|
|
|
|
if ((pressure.is2Low()) && (terrarium.getTapState() == LOW)) {
|
|
digitalWrite(2, HIGH);
|
|
terrarium.setTapState(HIGH);
|
|
} else if ((pressure.is2High()) && (terrarium.getTapState() == HIGH)) {
|
|
digitalWrite(2, LOW);
|
|
terrarium.setTapState(LOW);
|
|
}
|
|
}
|