179 lines
5.9 KiB
C++
179 lines
5.9 KiB
C++
#include <unistd.h>
|
|
#include "core_simulation.h"
|
|
#include "app/include/Terrarium.h"
|
|
#include "app/include/TerrariumParameter.h"
|
|
#include "app/include/Menu.h"
|
|
#include "app/include/Tortue.h"
|
|
|
|
|
|
Terrarium *terrarium = new Terrarium(1);
|
|
TerrariumParameter *temperature = new TerrariumParameter(25,
|
|
20);
|
|
TerrariumParameter *pressure = new TerrariumParameter(3000,
|
|
2990);
|
|
|
|
Menu *menu = new Menu();
|
|
|
|
list<Tortue> tortues;
|
|
list<Tortue>::iterator iteratorT;
|
|
|
|
string message;
|
|
string input;
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
tortues.push_back(*(new Tortue("Marvin","male")));
|
|
tortues.push_back(*(new Tortue("Clara","female")));
|
|
tortues.push_back(*(new Tortue("Camille","non binary")));
|
|
}
|
|
|
|
// la boucle de controle arduino
|
|
void Board::loop() {
|
|
char buf[150];
|
|
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) {
|
|
message = menu->displayDefault(temperature->getValue(),
|
|
pressure->getValue(),
|
|
terrarium->getRadState(),
|
|
terrarium->getTapState(),
|
|
0);
|
|
/*strcpy(buf, menu->displayDefault(temperature.getValue(),
|
|
pressure.getValue(),
|
|
terrarium.getRadState(),
|
|
terrarium.getTapState(),
|
|
0).c_str());*/
|
|
} else if (menu->getMessage().c_str() != NULL){
|
|
message = menu->getMessage();
|
|
//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 (menu->getId() == 2){
|
|
iteratorT = tortues.begin();
|
|
for (int j = 0; j < menu->getChoice(); ++j) {
|
|
iteratorT++;
|
|
}
|
|
//cout << iteratorT->getInfo() << endl;
|
|
message += iteratorT->getInfo();
|
|
}
|
|
if (cpt % 5 == 0) {
|
|
strcpy(buf, message.c_str());
|
|
bus.write(1, buf, 150);
|
|
}
|
|
|
|
if (menu->getId() == 5){
|
|
Tortue * newTortue;
|
|
cin >> input;
|
|
newTortue->setNom(input);
|
|
tortues.push_back(*newTortue);
|
|
menu->menuNext();
|
|
} else if (menu->getId() == 11){
|
|
cin >> input;
|
|
tortues.back().setNaissance(input);
|
|
menu->menuNext();
|
|
} else if (menu->getId() == 12){
|
|
cin >> input;
|
|
tortues.back().setSexe(input);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|