Probleme Capteur Fantome
This commit is contained in:
parent
22f3fa9f7b
commit
5d6495715a
17 changed files with 259 additions and 49 deletions
3
src/#compile_linux.sh#
Executable file
3
src/#compile_linux.sh#
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
set -x
|
||||
g++ -Wextra -std=c++11 -pthread board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp modemGSM.cpp -o arduino
|
0
src/Boutons/Sonnerie/sonnerie.txt
Normal file
0
src/Boutons/Sonnerie/sonnerie.txt
Normal file
0
src/LED/Actif_Intelligent/on.txt
Normal file
0
src/LED/Actif_Intelligent/on.txt
Normal file
0
src/LED/Sonnerie/on.txt
Normal file
0
src/LED/Sonnerie/on.txt
Normal file
BIN
src/arduino
BIN
src/arduino
Binary file not shown.
|
@ -4,6 +4,7 @@
|
|||
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
// creation d'une board
|
||||
Board esp8266;
|
||||
|
@ -18,14 +19,32 @@ int main(){
|
|||
I2CActuatorScreen screen;
|
||||
AnalogSensorMovement Capt1(DELAY);
|
||||
AnalogSensorMovement Capt2(DELAY);
|
||||
DigitalLED ledSonnerie(DELAY,"sonnerie.txt","Sonnerie");
|
||||
//AnalogSensorMovement Capt3(DELAY);
|
||||
AnalogSensorMovement Capt4(DELAY);
|
||||
AnalogSensorMovement Capt5(DELAY);
|
||||
AnalogSensorMovement Capt6(DELAY);
|
||||
DigitalLED ledSonnerie(DELAY,"LED/Sonnerie/on.txt","Sonnerie");
|
||||
DigitalLED ledModeMax(DELAY, "LED/Actif_Max/on.txt","Mode Max Alert");
|
||||
DigitalLED ledModeIntelligent(DELAY,"LED/Actif_Intelligent/on.txt","Mode Intelligent");
|
||||
ExternalDigitalSensorButton BoutonAlarm(DELAY);
|
||||
ExternalDigitalSensorButton BoutonSonnerie(DELAY);
|
||||
ExternalSwitchButton BoutonMode(DELAY);
|
||||
|
||||
|
||||
|
||||
|
||||
//Configuration des Capteurs
|
||||
//Configuration des Capteurs et Boutons
|
||||
Capt1.config();
|
||||
Capt2.config();
|
||||
//Capt3.config();
|
||||
Capt4.config();
|
||||
Capt5.config();
|
||||
Capt6.config();
|
||||
|
||||
BoutonAlarm.config("Alarme","Boutons/Alarm/alarm.txt","LED/Alarm/on.txt");
|
||||
BoutonSonnerie.config("Sonnerie","Boutons/Sonnerie/sonnerie.txt","LED/Sonnerie/on.txt");
|
||||
BoutonMode.config("Mode","Boutons/Mode/mode1.txt","Boutons/Mode/mode2.txt","LED/Actif_Max/on.txt","LED/Actif_Intelligent/on.txt");
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -41,6 +60,13 @@ int main(){
|
|||
esp8266.pin(4,ledModeIntelligent);
|
||||
esp8266.pin(5,Capt1);
|
||||
esp8266.pin(6,Capt2);
|
||||
esp8266.pin(7,BoutonAlarm);
|
||||
esp8266.pin(8,BoutonSonnerie);
|
||||
esp8266.pin(9,BoutonMode);
|
||||
//esp8266.pin(10,Capt3);
|
||||
esp8266.pin(11,Capt4);
|
||||
esp8266.pin(12,Capt5);
|
||||
esp8266.pin(13,Capt6);
|
||||
//esp8266.pin(1,temperature);
|
||||
//esp8266.pin(2,luminosite);
|
||||
//esp8266.pin(4,bouton1);
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#!/bin/bash
|
||||
set -x
|
||||
g++ -Wextra -std=c++11 -pthread board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp -o arduino
|
||||
g++ -Wextra -std=c++11 -pthread board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp modemGSM.cpp -o arduino
|
||||
|
|
|
@ -113,9 +113,6 @@ public:
|
|||
thread *tabthreadbus[MAX_I2C_DEVICES];
|
||||
|
||||
|
||||
|
||||
//Gestion Capteurs alarme
|
||||
void gestionAlarme();
|
||||
|
||||
// simulation de la boucle de controle arduino
|
||||
void run();
|
||||
|
|
41
src/modemGSM.cpp
Normal file
41
src/modemGSM.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "modemGSM.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
modemGSM::modemGSM(){
|
||||
state=0;}
|
||||
|
||||
void modemGSM::setState(int s){
|
||||
state =s;}
|
||||
|
||||
void modemGSM::run(){
|
||||
while(1){
|
||||
|
||||
if (state==1){
|
||||
|
||||
if(ifstream("ModemGSM/Reception/alarmOn.txt")){
|
||||
ofstream outfile;
|
||||
outfile.open("LED/Alarm/on.txt");
|
||||
outfile << "test\n";
|
||||
outfile.close();
|
||||
}
|
||||
else if(ifstream("ModemGSM/Reception/alarmOff.txt")){
|
||||
int bin;
|
||||
bin=remove("LED/Alarm/on.txt");
|
||||
}
|
||||
else if(ifstream("ModemGSM/Reception/sonnerieOn.txt")){
|
||||
ofstream outfile;
|
||||
outfile.open("LED/Sonnerie/sonnerie.txt");
|
||||
outfile << "test\n";
|
||||
outfile.close();
|
||||
}
|
||||
else if (ifstream("ModemGSM/Reception/sonnerieOff.txt")){
|
||||
int bin;
|
||||
bin=remove("LED/Sonnerie/sonnerie.txt");}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
41
src/modemGSM.cpp~
Normal file
41
src/modemGSM.cpp~
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "modemGSM.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
modemGSM::modemGSM(){
|
||||
state=0;}
|
||||
|
||||
void modemGSM::setState(int s){
|
||||
state =s;}
|
||||
|
||||
void modemGSM::run(){
|
||||
while(1){
|
||||
|
||||
if (state==1){
|
||||
|
||||
if(ifstream("ModemGSM/Reception/alarmOn.txt")){
|
||||
ofstream outfile;
|
||||
outfile.open("LED/Alarm/alarm.txt");
|
||||
outfile << "test\n";
|
||||
outfile.close();
|
||||
}
|
||||
else if(ifstream("ModemGSM/Reception/alarmOff.txt")){
|
||||
int bin;
|
||||
bin=remove("LED/Alarm/alarm.txt");
|
||||
}
|
||||
else if(ifstream("ModemGSM/Reception/sonnerieOn.txt")){
|
||||
ofstream outfile;
|
||||
outfile.open("LED/Sonnerie/sonnerie.txt");
|
||||
outfile << "test\n";
|
||||
outfile.close();
|
||||
}
|
||||
else if (ifstream("ModemGSM/Reception/sonnerieOff.txt")){
|
||||
int bin;
|
||||
bin=remove("LED/Sonnerie/sonnerie.txt");}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
18
src/modemGSM.h
Normal file
18
src/modemGSM.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
class modemGSM {
|
||||
private:
|
||||
int state;
|
||||
|
||||
public:
|
||||
|
||||
modemGSM();
|
||||
void setState(int s);
|
||||
void run();
|
||||
};
|
0
src/modemGSM.h~
Normal file
0
src/modemGSM.h~
Normal file
|
@ -42,26 +42,78 @@ void Actionneur::run() {
|
|||
|
||||
|
||||
//Interaction Exterieure
|
||||
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int t): Actionneur(1,t,0){
|
||||
|
||||
|
||||
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int t): Actionneur(1,t,0){
|
||||
}
|
||||
|
||||
void ExternalDigitalSensorButton::setNom(string n){
|
||||
nom=n;}
|
||||
void ExternalDigitalSensorButton::setPathBouton(string pb){
|
||||
pathBouton = pb;}
|
||||
void ExternalDigitalSensorButton::setPathAction(string pa){
|
||||
pathAction = pa;}
|
||||
|
||||
void ExternalDigitalSensorButton::config(string n, string pb, string pa){
|
||||
setNom(n);
|
||||
setPathBouton(pb);
|
||||
setPathAction(pa);
|
||||
setState(0);
|
||||
}
|
||||
void ExternalDigitalSensorButton::run(){
|
||||
if(ifstream("on.txt")){
|
||||
setState(1);
|
||||
|
||||
|
||||
while (1){
|
||||
if(ifstream(pathBouton)){
|
||||
setState(1);
|
||||
ofstream outfile;
|
||||
outfile.open(pathAction);
|
||||
outfile << "pathfile \n";
|
||||
outfile.close();
|
||||
}
|
||||
else{
|
||||
setState(0);
|
||||
else{
|
||||
int bin;
|
||||
bin=remove(pathAction.c_str());
|
||||
setState(0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ExternalSwitchButton::ExternalSwitchButton(int t): Actionneur(1,t,0){
|
||||
}
|
||||
|
||||
void ExternalSwitchButton::config(string n, string pb1, string pb2, string pa1, string pa2){
|
||||
nom=n;
|
||||
pathBouton1 = pb1;
|
||||
pathBouton2 = pb2;
|
||||
pathAction1 = pa1;
|
||||
pathAction2 = pa2;
|
||||
setState(0);
|
||||
}
|
||||
|
||||
void ExternalSwitchButton::run(){
|
||||
while(1){
|
||||
if(ifstream(pathBouton1)){
|
||||
int bin;
|
||||
bin=remove(pathAction2.c_str());
|
||||
|
||||
|
||||
ofstream outfile;
|
||||
outfile.open(pathAction1);
|
||||
outfile << "pathfile \n";
|
||||
outfile.close();
|
||||
} else if (ifstream(pathBouton2)){
|
||||
int bin;
|
||||
bin=remove(pathAction1.c_str());
|
||||
ofstream outfile;
|
||||
outfile.open(pathAction2);
|
||||
outfile << "pathfile \n";
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Classe Capteur
|
||||
Capteur::Capteur(int ty, int t):Device(),temps(t),type(ty),alea(1){
|
||||
|
@ -128,7 +180,7 @@ void AnalogSensorLuminosity::run(){
|
|||
AnalogSensorMovement::AnalogSensorMovement(int d):Capteur(3,d){
|
||||
mode =1;
|
||||
nom ="Default";
|
||||
path = "Maison/on.txt";
|
||||
path = "null";
|
||||
}
|
||||
void AnalogSensorMovement::setPath(string p){
|
||||
path =p;
|
||||
|
@ -153,11 +205,14 @@ void AnalogSensorMovement::config(){
|
|||
cout << "Quel mode voulez-vous lui donner? 1-> Alerte Max, 2-> Ne sera pas actif si le mode Intelligent est activé" << endl;
|
||||
cin >> m;
|
||||
mode = m;
|
||||
cout << "Dans quelle pièce de la maison allez-vous le placer? 1-> Chambre, 2-Salon, 3-> Garage" << endl;
|
||||
cout << "Dans quelle pièce de la maison allez-vous le placer? 1-> Chambre, 2-Salon, 3-> Garage, 4-> Rangement Jardin, 5-> Entree" << endl;
|
||||
cin >> p;
|
||||
if(p==1){setPath("Maison/Chambre/on.txt");}
|
||||
else if(p==2){setPath("Maison/Salon/on.txt");}
|
||||
else if(p==3){setPath("Maison/Garage/on.txt");}
|
||||
else if(p==4){setPath("Maison/Rangement_Jardin/on.txt");}
|
||||
else if(p==5){setPath("Maison/Entree/on.txt");}
|
||||
|
||||
|
||||
|
||||
cout << "Le capteur rentré est : "<< endl;
|
||||
|
@ -166,18 +221,15 @@ void AnalogSensorMovement::config(){
|
|||
cout << getMode() << endl;
|
||||
}
|
||||
void AnalogSensorMovement::detectMovement(){
|
||||
int bin;
|
||||
if (valeur == 0){
|
||||
bin = remove("sonnerie.txt");
|
||||
}
|
||||
else if (valeur==1){
|
||||
string test = "Boutons/Sonnerie/sonnerie.txt";
|
||||
if (valeur==1){
|
||||
if (ifstream("LED/Actif_Max/on.txt")){
|
||||
cout << "Il y a eu du mouvement "<< endl;
|
||||
cout << "Capteur : "<< nom << endl;
|
||||
std::ofstream outfile("sonnerie.txt");
|
||||
ofstream outfile;
|
||||
outfile.open(test.c_str());
|
||||
//outfile << "test\n";
|
||||
outfile.close();
|
||||
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
else if (ifstream("LED/Actif_Intelligent/on.txt")){
|
||||
|
@ -185,18 +237,16 @@ void AnalogSensorMovement::detectMovement(){
|
|||
if (mode == 1){
|
||||
cout << "Il y a eu du mouvement "<< endl;
|
||||
cout << "Capteur : "<< nom << endl;
|
||||
std::ofstream outfile("sonnerie.txt");
|
||||
outfile.close();
|
||||
|
||||
ofstream outfile;
|
||||
|
||||
outfile.open(test.c_str());
|
||||
//outfile << "test\n";
|
||||
outfile.close();
|
||||
sleep(2);
|
||||
}
|
||||
else if( mode ==2){
|
||||
//Pas de sonnerie déclenché
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -206,19 +256,20 @@ void AnalogSensorMovement::detectMovement(){
|
|||
|
||||
void AnalogSensorMovement::run(){
|
||||
while(1){
|
||||
detectMovement();
|
||||
if(ifstream(path)){
|
||||
valeur = 1;
|
||||
if (ifstream("Boutons/Alarm/alarm.txt")){
|
||||
detectMovement();
|
||||
if(ifstream(path)){
|
||||
valeur = 1;
|
||||
|
||||
}
|
||||
else {
|
||||
valeur =0;
|
||||
|
||||
*ptrmem=valeur;
|
||||
}
|
||||
}
|
||||
else {
|
||||
valeur =0;
|
||||
|
||||
*ptrmem=valeur;
|
||||
}
|
||||
|
||||
if(ptrmem!=NULL){
|
||||
*ptrmem=valeur;}
|
||||
if(ptrmem!=NULL){
|
||||
*ptrmem=valeur;}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define MYDEVICES_H
|
||||
|
||||
#include <iostream>
|
||||
//#include <ofstream>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
@ -45,7 +44,7 @@ class Actionneur : public Device{
|
|||
//Pour avoir le type
|
||||
int getType();
|
||||
//Methode Run redefinir pour chaque type de Bouton
|
||||
void run();
|
||||
virtual void run();
|
||||
|
||||
|
||||
|
||||
|
@ -104,7 +103,7 @@ class AnalogSensorLuminosity : public Capteur {
|
|||
public:
|
||||
AnalogSensorLuminosity (int d);
|
||||
|
||||
virtual void run();
|
||||
void run();
|
||||
|
||||
};
|
||||
|
||||
|
@ -155,13 +154,35 @@ class IntelligentDigitalActuatorLED : public Device{
|
|||
|
||||
//Interaction Exterieure
|
||||
class ExternalDigitalSensorButton: public Actionneur{
|
||||
private:
|
||||
string nom;
|
||||
string pathBouton;
|
||||
string pathAction;
|
||||
|
||||
|
||||
public:
|
||||
ExternalDigitalSensorButton(int t);
|
||||
virtual void run();
|
||||
void setNom(string n);
|
||||
void setPathBouton(string pb);
|
||||
void setPathAction(string pa);
|
||||
void config(string n, string pb, string pa);
|
||||
|
||||
};
|
||||
|
||||
//Switch Button
|
||||
class ExternalSwitchButton : public Actionneur{
|
||||
private:
|
||||
string nom;
|
||||
string pathBouton1;
|
||||
string pathBouton2;
|
||||
string pathAction1;
|
||||
string pathAction2;
|
||||
|
||||
public:
|
||||
ExternalSwitchButton(int t);
|
||||
virtual void run();
|
||||
void config(string n, string pb1, string pb2, string pa1, string pa2);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "modemGSM.h"
|
||||
#include "core_simulation.h"
|
||||
|
||||
|
||||
|
||||
// la fonction d'initialisation d'arduino
|
||||
void Board::setup(){
|
||||
// on configure la vitesse de la liaison
|
||||
|
@ -15,6 +16,13 @@ void Board::setup(){
|
|||
pinMode(4,OUTPUT);
|
||||
pinMode(5,INPUT);
|
||||
pinMode(6,INPUT);
|
||||
pinMode(7,INPUT);
|
||||
pinMode(8,INPUT);
|
||||
pinMode(9,INPUT);
|
||||
pinMode(10,INPUT);
|
||||
pinMode(11,INPUT);
|
||||
pinMode(12,INPUT);
|
||||
pinMode(13,INPUT);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,9 +34,13 @@ void Board::loop(){
|
|||
static int cpt=0;
|
||||
static int bascule=0;
|
||||
int i=0;
|
||||
|
||||
modemGSM modem;
|
||||
modem = modemGSM();
|
||||
modem.setState(1);
|
||||
modem.run();
|
||||
|
||||
for(i=0;i<10;i++){
|
||||
|
||||
/*
|
||||
// lecture sur la pin 1 : capteur de temperature
|
||||
val=analogRead(1);
|
||||
|
|
Loading…
Reference in a new issue