Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
51:66b820f203a5
Parent:
46:4cb96ab2d1c8
Child:
56:225786c56315
diff -r 1c7861d80d16 -r 66b820f203a5 src/ConfigurationHandler/Controls/SetpointControl.cpp
--- a/src/ConfigurationHandler/Controls/SetpointControl.cpp	Tue Sep 13 16:00:45 2016 +0000
+++ b/src/ConfigurationHandler/Controls/SetpointControl.cpp	Tue Sep 13 21:29:24 2016 +0000
@@ -7,18 +7,19 @@
 #include "SetpointControl.h"
 #include "mDot.h"
 #include "MbedJSONValue.h"
+#include "global.h"
 #include <string>
 
 extern mDot *GLOBAL_mdot;
 
 bool SetpointControl::load(string _controlFile)
 {
-    MbedJSONValue json_value;           // JSON parsing element 
-    controlFile = _controlFile;    
- 
-    // try to open the control file
+    MbedJSONValue json_value;           // JSON parsing element
+    controlFile = _controlFile;
+
+    // open and read from the control file 
     mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY);
-    if ( file.fd < 0 ) 
+    if ( file.fd < 0 )
         return false;
 
     // read the data into a buffer
@@ -28,16 +29,16 @@
     if ( bytes_read != sizeof(dataBuf) ) {
         logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str());
         // we can't throw exceptions in mbed, so just return false. the calling function will
-        // destroy the object 
+        // destroy the object
         return false;
     }
-    
-    // close the file 
+
+    // close the file
     GLOBAL_mdot->closeUserFile(file);
 
-    // parse the json data 
+    // parse the json data
     parse(json_value, dataBuf);
-    
+
     id              = json_value["id"].get<string>();
     name            = json_value["name"].get<string>();
     priority        = atoi(json_value["priority"].get<string>().c_str());
@@ -50,6 +51,81 @@
     lowFailsafe     = atof(json_value["lfs"].get<string>().c_str());
     tol             = atof(json_value["tol"].get<string>().c_str());
 
-    return true;
+    return true;        // object created successfully 
+}
+
+void SetpointControl::registerControl(void)
+{
+    if ( GLOBAL_outputTask_thread ) {
+        // register our priority with the output master 
+    }
+}
+
+void SetpointControl::start(void)
+{
+    // this is the initial state, let's determine what needs to be done
+    this->currentState = STATE_STARTUP;
 }
 
+void SetpointControl::update(void)
+{
+    printf("\r%s is working on %s\n", __func__, controlFile.c_str()); 
+    switch (this->currentState) {
+        case STATE_STARTUP:
+            if ( this->underLimit() ) {
+                // start the feed right away
+                this->startFeed();
+                this->currentState = STATE_CONTROL_ON;
+            } else {
+                this->currentState = STATE_CONTROL_OFF;
+            }
+            break;
+        case STATE_CONTROL_ON:
+            if ( this->overLimit() ) {
+                // stop the feed
+                this->stopFeed();
+                this->currentState = STATE_CONTROL_OFF;
+            } else {
+                // do nothing
+            }
+            break;
+        case STATE_CONTROL_OFF:
+            if ( this->underLimit() ) {
+                // start the feed
+                this->startFeed();
+                this->currentState = STATE_CONTROL_ON;
+            } else {
+                // do nothing
+            }
+            break;
+        //case STATE_CONTROL_DISABLED:
+        //case STATE_CONTROL_PAUSED:
+        default:
+            break;
+    }
+}
+
+bool SetpointControl::overLimit(void)
+{
+    return false;
+}
+
+bool SetpointControl::underLimit(void)
+{
+    return false;
+}
+
+void SetpointControl::startFeed(void)
+{
+    logInfo("%s attempting to start feed on relay %s\n", 
+        controlFile.c_str(), output.c_str());
+        
+    // TODO: send a message to the output task to turn the relay ON
+}
+
+void SetpointControl::stopFeed(void)
+{
+    logInfo("%s attempting to stop feed on relay %s\n",
+        controlFile.c_str(), output.c_str());
+    // TODO: send a message to the output task to turn the relay OFF
+}
\ No newline at end of file