Menu.cpp v0
This commit is contained in:
parent
8600c09ba2
commit
acb5c35fe1
8 changed files with 148 additions and 33 deletions
|
@ -3,3 +3,15 @@
|
|||
//
|
||||
|
||||
#include "../../include/I2CDevices/Keyboard.h"
|
||||
|
||||
Keyboard::Keyboard(): Device() {}
|
||||
|
||||
//void Keyboard::run() {}
|
||||
|
||||
void Keyboard::saisie() {
|
||||
cin >> buf;
|
||||
if (i2cbus!=NULL){
|
||||
while (!(i2cbus->isEmptyRegister(i2caddr))) {}
|
||||
Device::i2cbus->write(i2caddr, buf, I2C_BUFFER_SIZE);
|
||||
}
|
||||
}
|
||||
|
|
24
app/include/Menu.h
Normal file
24
app/include/Menu.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#ifndef PROJET_VICTORAVECUNK_MENU_H
|
||||
#define PROJET_VICTORAVECUNK_MENU_H
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
class Menu {
|
||||
protected:
|
||||
int id;
|
||||
int nbreChoices;
|
||||
int choice;
|
||||
std::list<std::pair<int,std::string>> list;
|
||||
public:
|
||||
Menu();
|
||||
std::string getMessage();
|
||||
void nextChoice();
|
||||
void update(std::string message);
|
||||
};
|
||||
|
||||
|
||||
#endif //PROJET_VICTORAVECUNK_MENU_H
|
63
app/src/Menu.cpp
Normal file
63
app/src/Menu.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#include "../include/Menu.h"
|
||||
|
||||
Menu::Menu() : id(0), choice(0) {
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(1,"liste tortue")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(1,"management tortue")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(1,"Gestion terrarium")));
|
||||
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(3,"ajouter tortue")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(3,"supprimer tortue")));
|
||||
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"Temperature max")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"Temperature min")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"Profondeur max")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"Profondeur min")));
|
||||
}
|
||||
|
||||
std::string Menu::getMessage() {
|
||||
int cpt = 0;
|
||||
std::string message = "";
|
||||
std::list<std::pair<int,std::string>>::iterator it;
|
||||
for (it = list.begin(); it != list.end() ; it++) {
|
||||
if (it->first == id){
|
||||
if (it->first == choice){
|
||||
message += "->" + it->second;
|
||||
} else {
|
||||
message += it->second;
|
||||
}
|
||||
++cpt;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
void Menu::nextChoice() {
|
||||
choice = (choice + 1) % nbreChoices;
|
||||
}
|
||||
|
||||
void Menu::update(std::string message) {
|
||||
if (message == "n"){
|
||||
nextChoice();
|
||||
} else if (message == "liste tortue"){
|
||||
id = 2;
|
||||
} else if (message == "management tortue"){
|
||||
id = 3;
|
||||
nbreChoices = 2;
|
||||
} else if (message == "gestion terrarium"){
|
||||
id = 4;
|
||||
nbreChoices = 4;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include "include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h"
|
||||
#include "include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h"
|
||||
#include "include/I2CDevices/Screen.h"
|
||||
#include "include/I2CDevices/Keyboard.h"
|
||||
|
||||
int main(){
|
||||
// creation d'une board
|
||||
|
@ -16,6 +17,7 @@ int main(){
|
|||
//DigitalActuatorLED led1(DELAY);
|
||||
IntelligentDigitalActuatorLED led1(DELAY);
|
||||
Screen screen;
|
||||
Keyboard keyboard;
|
||||
AnalogSensorLuminosity luminosite(DELAY);
|
||||
ExternalDigitalSensorButton button(DELAY);
|
||||
AnalogSensorManometre manometre(PRESSURE,DELAY);
|
||||
|
@ -27,10 +29,12 @@ int main(){
|
|||
esp8266.pin(1,temperature);
|
||||
//esp8266.pin(0,led1);
|
||||
esp8266.pin(2, electrovanne);
|
||||
esp8266.i2c(1,screen);
|
||||
esp8266.pin(4, button);
|
||||
esp8266.pin(5, manometre);
|
||||
esp8266.pin(0, radiator);
|
||||
|
||||
esp8266.i2c(1,screen);
|
||||
esp8266.i2c(2,keyboard);
|
||||
|
||||
// allumage de la carte
|
||||
esp8266.run();
|
||||
|
|
|
@ -174,3 +174,5 @@ void Board::i2c(int addr,Device& dev){
|
|||
tabthreadbus[addr]=new thread(&Device::run,&dev);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -126,6 +126,8 @@ public:
|
|||
void setup();
|
||||
// fonction arduino : boucle de controle de la carte arduino
|
||||
void loop();
|
||||
void TemperatureManagement();
|
||||
void PressureManagement();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,9 +5,15 @@
|
|||
#ifndef PROJET_VICTORAVECUNK_KEYBOARD_H
|
||||
#define PROJET_VICTORAVECUNK_KEYBOARD_H
|
||||
|
||||
#include "../../core_simulation.h"
|
||||
|
||||
class Keyboard {
|
||||
|
||||
class Keyboard : public Device{
|
||||
protected:
|
||||
char buf[I2C_BUFFER_SIZE];
|
||||
public:
|
||||
Keyboard();
|
||||
//virtual void run();
|
||||
void saisie();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -34,37 +34,9 @@ void Board::loop(){
|
|||
static int bascule=0;
|
||||
int i=0;
|
||||
//for(i=0;i<10;i++){
|
||||
// if (i%3==0) {
|
||||
// lecture sur la pin 1 : capteur de temperature
|
||||
temperature.setValue(analogRead(1));
|
||||
sprintf(buf, "temperature %f", temperature.getValue());
|
||||
Serial.println(buf);
|
||||
TemperatureManagement();
|
||||
PressureManagement();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
// lecture sur la pin 2 : capteur de temperature
|
||||
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);
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
@ -81,4 +53,34 @@ void Board::loop(){
|
|||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue