Browse Source

Probleme Capteur Fantome

Joao Conceicao Nunes 3 years ago
parent
commit
5d6495715a

+ 3
- 0
src/#compile_linux.sh# View File

@@ -0,0 +1,3 @@
1
+#!/bin/bash
2
+set -x
3
+g++  -Wextra -std=c++11 -pthread board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp  modemGSM.cpp -o arduino

src/Maison/Chambre/on.txt → src/Boutons/Alarm/alarm.txt View File


src/LED/Actif_Max/on.txt → src/Boutons/Mode/mode2.txt View File


+ 0
- 0
src/Boutons/Sonnerie/sonnerie.txt View File


+ 0
- 0
src/LED/Actif_Intelligent/on.txt View File


+ 0
- 0
src/LED/Sonnerie/on.txt View File


BIN
src/arduino View File


+ 28
- 2
src/board.cpp View File

@@ -4,6 +4,7 @@
4 4
 
5 5
 
6 6
 
7
+
7 8
 int main(){
8 9
   // creation d'une board
9 10
   Board esp8266;
@@ -18,14 +19,32 @@ int main(){
18 19
   I2CActuatorScreen screen;
19 20
   AnalogSensorMovement Capt1(DELAY);
20 21
   AnalogSensorMovement Capt2(DELAY);
21
-  DigitalLED ledSonnerie(DELAY,"sonnerie.txt","Sonnerie");
22
+  //AnalogSensorMovement Capt3(DELAY);
23
+  AnalogSensorMovement Capt4(DELAY);
24
+  AnalogSensorMovement Capt5(DELAY);
25
+  AnalogSensorMovement Capt6(DELAY);
26
+  DigitalLED ledSonnerie(DELAY,"LED/Sonnerie/on.txt","Sonnerie");
22 27
   DigitalLED ledModeMax(DELAY, "LED/Actif_Max/on.txt","Mode Max Alert");
23 28
   DigitalLED ledModeIntelligent(DELAY,"LED/Actif_Intelligent/on.txt","Mode Intelligent");
29
+  ExternalDigitalSensorButton BoutonAlarm(DELAY);
30
+  ExternalDigitalSensorButton BoutonSonnerie(DELAY);
31
+  ExternalSwitchButton BoutonMode(DELAY);
32
+ 
33
+  
24 34
 
25 35
 
26
-  //Configuration des Capteurs
36
+  //Configuration des Capteurs et Boutons
27 37
   Capt1.config();
28 38
   Capt2.config();
39
+  //Capt3.config();
40
+  Capt4.config();
41
+  Capt5.config();
42
+  Capt6.config();
43
+
44
+  BoutonAlarm.config("Alarme","Boutons/Alarm/alarm.txt","LED/Alarm/on.txt");
45
+  BoutonSonnerie.config("Sonnerie","Boutons/Sonnerie/sonnerie.txt","LED/Sonnerie/on.txt");
46
+  BoutonMode.config("Mode","Boutons/Mode/mode1.txt","Boutons/Mode/mode2.txt","LED/Actif_Max/on.txt","LED/Actif_Intelligent/on.txt");
47
+  
29 48
   
30 49
  
31 50
 
@@ -41,6 +60,13 @@ int main(){
41 60
   esp8266.pin(4,ledModeIntelligent);
42 61
   esp8266.pin(5,Capt1);
43 62
   esp8266.pin(6,Capt2);
63
+  esp8266.pin(7,BoutonAlarm);
64
+  esp8266.pin(8,BoutonSonnerie);
65
+  esp8266.pin(9,BoutonMode);
66
+  //esp8266.pin(10,Capt3);
67
+  esp8266.pin(11,Capt4);
68
+  esp8266.pin(12,Capt5);
69
+  esp8266.pin(13,Capt6);
44 70
   //esp8266.pin(1,temperature);
45 71
   //esp8266.pin(2,luminosite);
46 72
   //esp8266.pin(4,bouton1);

+ 1
- 1
src/compile_linux.sh View File

@@ -1,3 +1,3 @@
1 1
 #!/bin/bash
2 2
 set -x
3
-g++  -Wextra -std=c++11 -pthread board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp  -o arduino
3
+g++  -Wextra -std=c++11 -pthread board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp  modemGSM.cpp -o arduino

+ 0
- 3
src/core_simulation.h View File

@@ -113,9 +113,6 @@ public:
113 113
   thread *tabthreadbus[MAX_I2C_DEVICES];
114 114
 
115 115
   
116
-
117
-  //Gestion Capteurs alarme
118
-  void gestionAlarme();
119 116
  
120 117
 // simulation de la boucle de controle arduino
121 118
     void run();

+ 41
- 0
src/modemGSM.cpp View File

@@ -0,0 +1,41 @@
1
+#include "modemGSM.h"
2
+
3
+
4
+using namespace std;
5
+modemGSM::modemGSM(){
6
+  state=0;}
7
+
8
+void modemGSM::setState(int s){
9
+  state =s;}
10
+
11
+void modemGSM::run(){
12
+  while(1){
13
+    
14
+    if (state==1){
15
+
16
+      if(ifstream("ModemGSM/Reception/alarmOn.txt")){
17
+	ofstream outfile;
18
+	outfile.open("LED/Alarm/on.txt");
19
+	outfile << "test\n";
20
+	outfile.close();
21
+      }
22
+      else if(ifstream("ModemGSM/Reception/alarmOff.txt")){
23
+	int bin;
24
+	bin=remove("LED/Alarm/on.txt");
25
+      }
26
+      else if(ifstream("ModemGSM/Reception/sonnerieOn.txt")){
27
+	ofstream outfile;
28
+	outfile.open("LED/Sonnerie/sonnerie.txt");
29
+	outfile << "test\n";
30
+	outfile.close();
31
+      }
32
+      else if (ifstream("ModemGSM/Reception/sonnerieOff.txt")){
33
+	int bin;
34
+	bin=remove("LED/Sonnerie/sonnerie.txt");}
35
+	
36
+	
37
+
38
+    }
39
+
40
+  }
41
+}

+ 41
- 0
src/modemGSM.cpp~ View File

@@ -0,0 +1,41 @@
1
+#include "modemGSM.h"
2
+
3
+
4
+using namespace std;
5
+modemGSM::modemGSM(){
6
+  state=0;}
7
+
8
+void modemGSM::setState(int s){
9
+  state =s;}
10
+
11
+void modemGSM::run(){
12
+  while(1){
13
+    
14
+    if (state==1){
15
+
16
+      if(ifstream("ModemGSM/Reception/alarmOn.txt")){
17
+	ofstream outfile;
18
+	outfile.open("LED/Alarm/alarm.txt");
19
+	outfile << "test\n";
20
+	outfile.close();
21
+      }
22
+      else if(ifstream("ModemGSM/Reception/alarmOff.txt")){
23
+	int bin;
24
+	bin=remove("LED/Alarm/alarm.txt");
25
+      }
26
+      else if(ifstream("ModemGSM/Reception/sonnerieOn.txt")){
27
+	ofstream outfile;
28
+	outfile.open("LED/Sonnerie/sonnerie.txt");
29
+	outfile << "test\n";
30
+	outfile.close();
31
+      }
32
+      else if (ifstream("ModemGSM/Reception/sonnerieOff.txt")){
33
+	int bin;
34
+	bin=remove("LED/Sonnerie/sonnerie.txt");}
35
+	
36
+	
37
+
38
+    }
39
+
40
+  }
41
+}

+ 18
- 0
src/modemGSM.h View File

@@ -0,0 +1,18 @@
1
+#include <iostream>
2
+#include <thread>
3
+#include <unistd.h>
4
+#include <string.h>
5
+#include <stdio.h>
6
+#include <fstream>
7
+
8
+
9
+class modemGSM {
10
+ private:
11
+  int state;
12
+
13
+ public:
14
+
15
+  modemGSM();
16
+  void setState(int s);
17
+  void run();
18
+  };

+ 0
- 0
src/modemGSM.h~ View File


+ 89
- 38
src/mydevices.cpp View File

@@ -42,26 +42,78 @@ void Actionneur::run() {
42 42
   
43 43
 
44 44
 //Interaction Exterieure
45
-  ExternalDigitalSensorButton::ExternalDigitalSensorButton(int t): Actionneur(1,t,0){
46
-  
47
-  
45
+ExternalDigitalSensorButton::ExternalDigitalSensorButton(int t): Actionneur(1,t,0){
46
+}
48 47
 
48
+void ExternalDigitalSensorButton::setNom(string n){
49
+  nom=n;}
50
+void ExternalDigitalSensorButton::setPathBouton(string pb){
51
+  pathBouton = pb;}
52
+void ExternalDigitalSensorButton::setPathAction(string pa){
53
+  pathAction = pa;}
54
+
55
+void ExternalDigitalSensorButton::config(string n, string pb, string pa){
56
+  setNom(n);
57
+  setPathBouton(pb);
58
+  setPathAction(pa);
59
+  setState(0);
49 60
 }
50 61
 void ExternalDigitalSensorButton::run(){
51
-  if(ifstream("on.txt")){
52
-    setState(1);
53
-    
54
-    
62
+  while (1){
63
+    if(ifstream(pathBouton)){
64
+      setState(1);
65
+      ofstream outfile;
66
+      outfile.open(pathAction);
67
+      outfile << "pathfile \n";
68
+      outfile.close();   
55 69
     }
56
-  else{
57
-    setState(0);
70
+    else{
71
+      int bin;
72
+      bin=remove(pathAction.c_str());
73
+      setState(0);
58 74
    
75
+    }
59 76
   }
77
+}
60 78
 
61
-  
79
+
80
+ExternalSwitchButton::ExternalSwitchButton(int t): Actionneur(1,t,0){
81
+}
82
+
83
+void ExternalSwitchButton::config(string n, string pb1, string pb2, string pa1, string pa2){
84
+  nom=n;
85
+  pathBouton1 = pb1;
86
+  pathBouton2 = pb2;
87
+  pathAction1 = pa1;
88
+  pathAction2 = pa2;
89
+  setState(0);
90
+}
91
+
92
+void ExternalSwitchButton::run(){
93
+  while(1){
94
+    if(ifstream(pathBouton1)){
95
+      int bin;
96
+      bin=remove(pathAction2.c_str());
97
+      
98
+
99
+      ofstream outfile;
100
+      outfile.open(pathAction1);
101
+      outfile << "pathfile \n";
102
+      outfile.close();
103
+    } else if (ifstream(pathBouton2)){
104
+      int bin;
105
+      bin=remove(pathAction1.c_str());
106
+      ofstream outfile;
107
+      outfile.open(pathAction2);
108
+      outfile << "pathfile \n";
109
+      outfile.close();
110
+    }
62 111
 
63 112
   }
64
-	
113
+}
114
+
115
+
116
+
65 117
 
66 118
 //Classe Capteur
67 119
 Capteur::Capteur(int ty, int t):Device(),temps(t),type(ty),alea(1){
@@ -128,7 +180,7 @@ void AnalogSensorLuminosity::run(){
128 180
 AnalogSensorMovement::AnalogSensorMovement(int d):Capteur(3,d){
129 181
   mode =1;
130 182
   nom ="Default";
131
-  path = "Maison/on.txt";
183
+  path = "null";
132 184
 }
133 185
 void AnalogSensorMovement::setPath(string p){
134 186
   path =p;
@@ -153,11 +205,14 @@ void AnalogSensorMovement::config(){
153 205
   cout << "Quel mode voulez-vous lui donner? 1-> Alerte Max, 2-> Ne sera pas actif si le mode Intelligent est activé" << endl;
154 206
   cin >> m;
155 207
   mode = m;
156
-  cout << "Dans quelle pièce de la maison allez-vous le placer? 1-> Chambre, 2-Salon, 3-> Garage" << endl;
208
+  cout << "Dans quelle pièce de la maison allez-vous le placer? 1-> Chambre, 2-Salon, 3-> Garage, 4-> Rangement Jardin, 5-> Entree" << endl;
157 209
   cin >> p;
158 210
   if(p==1){setPath("Maison/Chambre/on.txt");}
159 211
   else if(p==2){setPath("Maison/Salon/on.txt");}
160 212
   else if(p==3){setPath("Maison/Garage/on.txt");}
213
+  else if(p==4){setPath("Maison/Rangement_Jardin/on.txt");}
214
+  else if(p==5){setPath("Maison/Entree/on.txt");}
215
+  
161 216
 
162 217
 
163 218
   cout << "Le capteur rentré est : "<< endl;
@@ -166,18 +221,15 @@ void AnalogSensorMovement::config(){
166 221
   cout << getMode() << endl;
167 222
 }
168 223
 void AnalogSensorMovement::detectMovement(){
169
-  int bin;
170
-  if (valeur == 0){
171
-    bin = remove("sonnerie.txt");
172
-  }
173
-  else if (valeur==1){
224
+  string test = "Boutons/Sonnerie/sonnerie.txt";
225
+  if (valeur==1){
174 226
     if (ifstream("LED/Actif_Max/on.txt")){
175 227
       cout << "Il y a eu du mouvement "<< endl;
176 228
       cout << "Capteur : "<< nom << endl;
177
-      std::ofstream outfile("sonnerie.txt");
229
+      ofstream outfile;
230
+      outfile.open(test.c_str());
231
+      //outfile << "test\n";
178 232
       outfile.close();
179
-    
180
-    
181 233
       sleep(2);
182 234
     }
183 235
     else if (ifstream("LED/Actif_Intelligent/on.txt")){
@@ -185,18 +237,16 @@ void AnalogSensorMovement::detectMovement(){
185 237
       if (mode == 1){
186 238
 	cout << "Il y a eu du mouvement "<< endl;
187 239
 	cout << "Capteur : "<< nom << endl;
188
-        std::ofstream outfile("sonnerie.txt");
189
-	outfile.close();
190
-     
240
+        ofstream outfile;
191 241
 	
242
+	outfile.open(test.c_str());
243
+	//outfile << "test\n";
244
+	outfile.close();
192 245
 	sleep(2);
193 246
       }
194 247
       else if( mode ==2){
195 248
 	//Pas de sonnerie déclenché
196 249
       }
197
-    
198
-    
199
-    
200 250
     } 
201 251
   }
202 252
 }
@@ -206,19 +256,20 @@ void AnalogSensorMovement::detectMovement(){
206 256
   
207 257
 void AnalogSensorMovement::run(){
208 258
   while(1){
209
-    detectMovement();
210
-    if(ifstream(path)){
211
-      valeur = 1;
259
+    if (ifstream("Boutons/Alarm/alarm.txt")){
260
+      detectMovement();
261
+      if(ifstream(path)){
262
+	valeur = 1;
212 263
       
213
-    }
214
-    else {
215
-      valeur =0;
264
+      }
265
+      else {
266
+	valeur =0;
216 267
       
217
-    *ptrmem=valeur; 
218
-  }
219
- 
220
-  if(ptrmem!=NULL){   
221
-    *ptrmem=valeur;}
268
+	*ptrmem=valeur; 
269
+      }
270
+    }
271
+    if(ptrmem!=NULL){   
272
+      *ptrmem=valeur;}
222 273
   }
223 274
   
224 275
 }

+ 24
- 3
src/mydevices.h View File

@@ -2,7 +2,6 @@
2 2
 #define MYDEVICES_H
3 3
 
4 4
 #include <iostream>
5
-//#include <ofstream>
6 5
 #include <thread>
7 6
 #include <unistd.h>
8 7
 #include <string.h>
@@ -45,7 +44,7 @@ class Actionneur : public Device{
45 44
   //Pour avoir le type
46 45
   int getType();
47 46
   //Methode Run  redefinir pour chaque type de Bouton
48
-  void run();
47
+  virtual void run();
49 48
 
50 49
   
51 50
 
@@ -104,7 +103,7 @@ class AnalogSensorLuminosity : public Capteur {
104 103
  public:
105 104
   AnalogSensorLuminosity (int d);
106 105
 
107
-  virtual void run();
106
+   void run();
108 107
 
109 108
 };
110 109
 
@@ -155,13 +154,35 @@ class IntelligentDigitalActuatorLED : public Device{
155 154
 
156 155
 //Interaction Exterieure
157 156
 class ExternalDigitalSensorButton: public Actionneur{
157
+private:
158
+  string nom;
159
+  string pathBouton;
160
+  string pathAction;
158 161
  
159 162
 
160 163
  public:
161 164
   ExternalDigitalSensorButton(int t);
162 165
   virtual void run();
166
+  void setNom(string n);
167
+  void setPathBouton(string pb);
168
+  void setPathAction(string pa);
169
+  void config(string n, string pb, string pa);
163 170
 
171
+};
172
+
173
+//Switch Button
174
+class ExternalSwitchButton : public Actionneur{
175
+private:
176
+  string nom;
177
+  string pathBouton1;
178
+  string pathBouton2;
179
+  string pathAction1;
180
+  string pathAction2;
164 181
 
182
+public:
183
+  ExternalSwitchButton(int t);
184
+  virtual void run();
185
+  void config(string n, string pb1, string pb2, string pa1, string pa2);
165 186
 
166 187
 };
167 188
 

+ 14
- 2
src/sketch_ino.cpp View File

@@ -1,8 +1,9 @@
1 1
 #include <unistd.h>
2
-
2
+#include "modemGSM.h"
3 3
 #include "core_simulation.h"
4 4
 
5 5
 
6
+
6 7
 // la fonction d'initialisation d'arduino
7 8
 void Board::setup(){
8 9
   // on configure la vitesse de la liaison
@@ -15,6 +16,13 @@ void Board::setup(){
15 16
   pinMode(4,OUTPUT);
16 17
   pinMode(5,INPUT);
17 18
   pinMode(6,INPUT);
19
+  pinMode(7,INPUT);
20
+  pinMode(8,INPUT);
21
+  pinMode(9,INPUT);
22
+  pinMode(10,INPUT);
23
+  pinMode(11,INPUT);
24
+  pinMode(12,INPUT);
25
+  pinMode(13,INPUT);
18 26
 }
19 27
 
20 28
 
@@ -26,9 +34,13 @@ void Board::loop(){
26 34
   static int cpt=0;
27 35
   static int bascule=0;
28 36
   int i=0;
29
-
37
+  modemGSM modem;
38
+  modem = modemGSM();
39
+  modem.setState(1);
40
+  modem.run();
30 41
   
31 42
   for(i=0;i<10;i++){
43
+    
32 44
     /*
33 45
     // lecture sur la pin 1 : capteur de temperature
34 46
     val=analogRead(1);

Loading…
Cancel
Save