Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
239:cfb1a917e7f7
Parent:
208:784c46652863
Child:
242:3b0086a6d625
--- a/src/ConfigurationHandler/Controls/SetpointControl.cpp	Wed Oct 19 16:26:02 2016 +0000
+++ b/src/ConfigurationHandler/Controls/SetpointControl.cpp	Wed Oct 19 23:44:38 2016 +0000
@@ -126,8 +126,10 @@
                 // stop the feed
                 this->stopFeed();
                 this->currentState = STATE_CONTROL_OFF;
-            } else {
-                // do nothing
+            } else if ( this->overFailsafeLimit() ) {
+                // TODO: check for a failsafe condition
+                printf("\rDEBUG: FAILSAFE ON\n");
+                this->currentState = STATE_FAILSAFE_ON;
             }
             break;
         case STATE_CONTROL_OFF:
@@ -135,10 +137,15 @@
                 // start the feed
                 this->startFeed();
                 this->currentState = STATE_CONTROL_ON;
-            } else {
-                // do nothing
+            } else if ( this->underFailsafeLimit() ) {
+                // TODO: check for a failsafe condition
+                printf("\rDEBUG: FAILSAFE OFF\n");
+                this->currentState = STATE_FAILSAFE_OFF;
             }
             break;
+        case STATE_FAILSAFE_ON:
+        case STATE_FAILSAFE_OFF:
+            break;
             //case STATE_CONTROL_DISABLED:
             //case STATE_CONTROL_PAUSED:
         default:
@@ -170,6 +177,27 @@
 }
 
 //
+// method:              overFailsafeLimit()
+// description:         (see @return)
+//
+// @param               none
+// @return              true if product is over the upper limit for normal mode
+//                      or under the limit for reverse mode; false otherwise
+//
+bool SetpointControl::overFailsafeLimit(void)
+{
+    ModbusValue value;
+    ModbusMasterReadRegister( input, &value );
+    
+    printf("\ractingDir = %d:%f(%f : %f\n", actingDir, value.value, highFailsafe, lowFailsafe);    
+    if ( !actingDir ) {
+        return (value.value > lowFailsafe);
+    } else {
+        return (value.value < highFailsafe);
+    }
+}
+
+//
 // method:              underLimit
 // description:         (see @return)
 //
@@ -193,6 +221,26 @@
 }
 
 //
+// method:              underLimit
+// description:         (see @return)
+//
+// @param               none
+// @return              true if product is under lower limit for normal mode or
+//                      over the upper limit for reverse mode; false otherwise
+//
+bool SetpointControl::underFailsafeLimit(void)
+{
+    ModbusValue value;
+    ModbusMasterReadRegister( input, &value );
+    
+    if ( !actingDir ) {
+        return (value.value < lowFailsafe);
+    } else { 
+        return (value.value > highFailsafe);
+    }
+}
+
+//
 // method:              startFeed()
 // description:         send ON indication to Output Master for this control's
 //                      relay
@@ -281,6 +329,8 @@
                         "STARTUP",
                         "CONTROL_OFF",
                         "CONTROL_ON",
+                        "FAILSAFE_ON",
+                        "FAILSAFE_OFF",
                         "CONTROL_DISABLE",
                         "CONTROL_PAUSE",
                         "CONTROL_MAX"
@@ -303,6 +353,7 @@
     std::cout << right << setw(8)  << setfill(' ') << setpoint + tolerance << " <- ";
     std::cout << left << setw(8)  << setfill(' ') << inputValue.value << " -> ";
     std::cout << left << setw(8)  << setfill(' ') << setpoint - tolerance;
+    std::cout << left << setw(10) << setfill(' ') << highFailsafe << " : " << lowFailsafe; 
 
     std::cout.flush();
 }
\ No newline at end of file