Saltware / Mbed 2 deprecated Water Play

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
sbouber1
Date:
Sat Jun 11 13:19:20 2016 +0000
Parent:
12:c51f3aba84fe
Child:
14:fcb625520e77
Commit message:
.

Changed in this revision

MockSensorController.cpp Show annotated file Show diff for this revision Revisions of this file
MockSensorController.h Show annotated file Show diff for this revision Revisions of this file
TemperatureController.cpp Show annotated file Show diff for this revision Revisions of this file
TemperatureController.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/MockSensorController.cpp	Sat Jun 11 10:14:40 2016 +0000
+++ b/MockSensorController.cpp	Sat Jun 11 13:19:20 2016 +0000
@@ -9,5 +9,7 @@
 }
 
 float MockSensorController::getValue() { 
-    return (*this->func)(this->i++);
+    this->sum_t += t.read_ms();
+    t.reset();
+    return (*this->func)(this->i++, this->sum_t);
 }
\ No newline at end of file
--- a/MockSensorController.h	Sat Jun 11 10:14:40 2016 +0000
+++ b/MockSensorController.h	Sat Jun 11 13:19:20 2016 +0000
@@ -7,8 +7,9 @@
 
 class MockSensorController : public SensorController {
     public:
-        MockSensorController(bool threaded, int interval_ms, float (*func)(int)) : SensorController(threaded, interval_ms) {
-            this->func = func;    
+        MockSensorController(bool threaded, int interval_ms, float (*func)(int, int)) : SensorController(threaded, interval_ms) {
+            this->func = func;  
+            t.start();  
         }  
         
         virtual void update();
@@ -19,7 +20,9 @@
     
     private:
         int i;
-        float (*func)(int);
+        Timer t;
+        long int sum_t;
+        float (*func)(int, int);
 };
 
 #endif
\ No newline at end of file
--- a/TemperatureController.cpp	Sat Jun 11 10:14:40 2016 +0000
+++ b/TemperatureController.cpp	Sat Jun 11 13:19:20 2016 +0000
@@ -1,5 +1,6 @@
 #include "TemperatureController.h"
 #include "rtos.h"
+#include "testing.h"
 
 AnalogIn temperature_sensor(p20);
 DigitalOut heater(p18);
@@ -16,6 +17,29 @@
     this->temperature = readSensor();
 }
 
+bool TemperatureController::is_heating() {
+    return this->heating;    
+}
+
+void TemperatureController::set_heating(bool enabled) {
+    if(enabled == this->heating) return;
+    
+    this->heating = enabled;
+    if(enabled) {
+        #ifdef RUN_TESTS
+        printf("Should set heater to 1\r\n");
+        #else
+        heater = 1;
+        #endif            
+    } else {
+        #ifdef RUN_TESTS
+        printf("Should set heater to 0\r\n");
+        #else
+        heater = 0;
+        #endif    
+    }
+}
+
 // Function reads sensor values and averages N sensor values
 float TemperatureController::readSensor()
 {
@@ -121,13 +145,6 @@
 
 void TemperatureController::controlHeater()
 {
-    if(readSensor() < 32.0f)
-    {
-        //heater = 1;
-        printf("Should set heater to 1\r\n");
-    } else {
-        //heater = 0;
-        printf("Should set heater to 0\r\n");
-    }
+    this->set_heating(this->getValue() < 32.0f);
         
 }
\ No newline at end of file
--- a/TemperatureController.h	Sat Jun 11 10:14:40 2016 +0000
+++ b/TemperatureController.h	Sat Jun 11 13:19:20 2016 +0000
@@ -17,15 +17,21 @@
         virtual void update();
         
         virtual std::string get_name();
+        
+        bool is_heating();
+        
+        void set_heating(bool enabled);
     
     private:
         float temperature;
+        
+        bool heating;
     
         static float readSensor();
         
         static float analoginToCelsius(float);
         
-        static void controlHeater();
+        void controlHeater();
         
         static float getOffset(float);
         
--- a/main.cpp	Sat Jun 11 10:14:40 2016 +0000
+++ b/main.cpp	Sat Jun 11 13:19:20 2016 +0000
@@ -11,17 +11,33 @@
 
 #include "mbed.h"
 #include "rtos.h"
+#include "testing.h"
 
 #define MAIN_THREAD_DELAY_MS 1000
 
-#define MOCK(N, F) static inline float N(int i) {return (F);}
+#define MOCK(N, F) static inline float N(int i, int t) {return (F);}
+
+int main();
+int test_main();
+int real_main();
+
+
 
 
 MOCK(temp_mock, 20.0+0.01*i)
 MOCK(salt_mock, 3.0+0.001*i)
 MOCK(prox_mock, 10.0f)
 
-int main() 
+
+int main() {
+    return MAIN();    
+}
+
+int test_main() {
+    // run tests here    
+}
+
+int real_main() 
 {
     std::vector<void *> controllers;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testing.h	Sat Jun 11 13:19:20 2016 +0000
@@ -0,0 +1,7 @@
+// #define RUN_TESTS
+
+#ifdef RUN_TESTS
+#define MAIN test_main
+#else
+#define MAIN real_main
+#endif
\ No newline at end of file