Saltware / Mbed 2 deprecated Water Play

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
joran
Date:
Wed Jun 15 07:25:53 2016 +0000
Parent:
39:cb67926712d4
Child:
41:dce2c29f49cd
Commit message:
Do not raise alarm for temp if we are heating, do not raise alarm for salt if we are pumping. I might have broken testing.

Changed in this revision

AlarmController.cpp Show annotated file Show diff for this revision Revisions of this file
AlarmController.h Show annotated file Show diff for this revision Revisions of this file
PIDController.cpp Show annotated file Show diff for this revision Revisions of this file
PIDController.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
testing.h Show annotated file Show diff for this revision Revisions of this file
--- a/AlarmController.cpp	Tue Jun 14 19:11:19 2016 +0000
+++ b/AlarmController.cpp	Wed Jun 15 07:25:53 2016 +0000
@@ -105,6 +105,7 @@
 
 void AlarmController::raiseAlarmTemp(bool isCrit)
 { 
+    if (this->pidc->is_heating()) return; //Do not raise alarm when we are trying to fix it.
     this->tempiscrit = isCrit;
     int readtimer = temptimer.read();
     if (isCrit) printf("Received a critical temperature alarm (%.1f), timer is at %d\r\n",readtemp,readtimer);
@@ -129,6 +130,7 @@
 
 void AlarmController::raiseAlarmSalt(bool isCrit)
 {
+    if (this->pidc->is_pumping()) return; //Do not raise alarm if we are trying to fix it.
     this->saltiscrit = isCrit;
     int readtimer = salttimer.read();
     if (isCrit) printf("Received a critical salt alarm (%.3f), timer is at %d\r\n",readsalt,readtimer);
--- a/AlarmController.h	Tue Jun 14 19:11:19 2016 +0000
+++ b/AlarmController.h	Wed Jun 15 07:25:53 2016 +0000
@@ -3,6 +3,7 @@
 
 #include "mbed.h"
 #include "SensorController.h"
+#include "PIDController.h"
 
 #define STARTUP_ITERATIONS 10
 
@@ -11,15 +12,17 @@
 
     
     public:
-        AlarmController(bool threaded, int interval_ms, SensorController *temp, SensorController *salt, SensorController *proximity)
+        AlarmController(bool threaded, int interval_ms, SensorController *temp, SensorController *salt, SensorController *proximity, PIDController *pidc)
          : Controller(threaded, interval_ms) {
             this->temp = temp;
             this->salt = salt;
             this->proximity = proximity;     
+            this->pidc = pidc;
             this->error = false;
             this->tempiscrit = false;
             this->saltiscrit = false;
             this->overflowiscrit = false;
+            
         }
         
         virtual void update();
@@ -40,6 +43,7 @@
         SensorController *temp;
         SensorController *salt;
         SensorController *proximity;
+        PIDController *pidc;
         
         bool error;
         char *error_msg;       
--- a/PIDController.cpp	Tue Jun 14 19:11:19 2016 +0000
+++ b/PIDController.cpp	Wed Jun 15 07:25:53 2016 +0000
@@ -69,7 +69,7 @@
 }
 
 void PIDController::pump_water(DRV8825 *mtr, int ml) {
-    
+    this->pumping = true;
     int j = 5010 * (ml - 1);
     
     for (int i = 500; i < MAX_SPEED; i += 5) {
@@ -99,6 +99,7 @@
     }
     
     wait(3);    
+    this->pumping = false;
 }
 
 
@@ -122,6 +123,10 @@
     return this->heating;    
 }
 
+bool PIDController::is_pumping() {
+    return this->pumping;    
+}
+
 void PIDController::set_heating(bool enabled) {
     if(enabled == this->heating) return;
     
--- a/PIDController.h	Tue Jun 14 19:11:19 2016 +0000
+++ b/PIDController.h	Wed Jun 15 07:25:53 2016 +0000
@@ -24,6 +24,7 @@
             this->temp = temp;
             this->salt = salt;
             this->proximity = proximity;
+            this->pumping = false;
         }
         
         virtual void update();
@@ -31,12 +32,16 @@
         virtual std::string get_name();
         
         bool is_heating();
+        bool is_pumping();
     
     private:
         SensorController *temp;
         SensorController *salt;
         SensorController *proximity;
+        
+        
         bool heating;
+        bool pumping;
         
         void pump_salt_water(int ml);
         
--- a/main.cpp	Tue Jun 14 19:11:19 2016 +0000
+++ b/main.cpp	Wed Jun 15 07:25:53 2016 +0000
@@ -54,11 +54,13 @@
     MockSensorController salt(false,0,salt_mock);
     controllers.push_back((void *)&salt);
     
-    AlarmController alarm(false,0,&temperature,&salt,&proximity);
+    PIDController pidc(false,0,&temperature,&salt,&proximity);
+    controllers.push_back((void *)&pidc);
+    
+    AlarmController alarm(false,0,&temperature,&salt,&proximity, &pidc);
     controllers.push_back((void *)&alarm);
     
-    PIDController pidc(false,0,&temperature,&salt,&proximity);
-    controllers.push_back((void *)&pidc);
+    
     // -----------------------------------------------------------------------------
     
     
--- a/testing.h	Tue Jun 14 19:11:19 2016 +0000
+++ b/testing.h	Wed Jun 15 07:25:53 2016 +0000
@@ -18,7 +18,7 @@
 
 #define ALARM_TEST(N,T,S,P,TIME) bool N(TestCase *tc) { \
     DEF_MOCKS(T,S,P); \
-    AlarmController alarm(false,0,&temp,&salt,&prox); \
+    AlarmController alarm(false,0,&temp,&salt,&prox,NULL); \
     for(int i = 0; i < TIME; i++) { \
         alarm.run(); \
         Thread::wait(1000); \