Orefatoi / Mbed 2 deprecated afero_poc15_171201

Dependencies:   mbed vt100

Revision:
12:4c0bd7fce2fd
Parent:
10:88e5b8157167
--- a/edge_sensor/edge_pressure.cpp	Mon Dec 11 05:52:25 2017 +0000
+++ b/edge_sensor/edge_pressure.cpp	Tue Dec 12 02:28:51 2017 +0000
@@ -39,6 +39,9 @@
     _pse = pse ;
     _value = 0.0 ;
     _interval = 30 ;
+    _thr_mode = 0 ;
+    _thr_high = HIGH_THR ;
+    _thr_low = LOW_THR ;
 }
 
 edge_pressure::~edge_pressure(void)
@@ -72,17 +75,89 @@
     _sampled_time = edge_time ;
 }
 
+void edge_pressure::set_thr_high(int16_t thr_high)
+{
+    switch(_thr_mode) {
+    case 0: /* absolute value */
+        _thr_high = (float)thr_high/100.0 ;
+        break ;
+    case 1: /* persentage */
+        _thr_high = (float)(thr_high/100.0) ;
+        break ;
+    default:
+        printf("Unknown Threshold mode %d\n", _thr_mode) ;
+        _thr_high = (float)thr_high/100.0 ;
+        break ;
+    }
+printf("thr_high = %.3f\n", _thr_high) ;
+}
+
+float edge_pressure::get_thr_high(float expected)
+{
+    float thr_high ;
+    
+    switch(_thr_mode) {
+    case 0: /* absolute value */
+        thr_high = expected + _thr_high ;
+        break ;
+    case 1: /* persentage */
+        thr_high = expected * (1.0 + _thr_high) ;
+        break ;
+    default:
+        printf("Unknown Threshold mode %d\n", _thr_mode) ;
+        thr_high = expected + _thr_high ; /* use this as default */
+        break ;
+    }
+    return (thr_high) ;
+}
+
+void edge_pressure::set_thr_low(int16_t thr_low)
+{   
+    switch(_thr_mode) {
+    case 0: /* absolute value */
+        _thr_low = (float)thr_low/100.0 ;
+        break ;
+    case 1: /* persentage */
+        _thr_low = (float)(thr_low/100.0) ;
+        break ;
+    default:
+        printf("Unknown Threshold mode %d\n", _thr_mode) ;
+        _thr_low = (float)thr_low/100.0 ;
+        break ;
+    }
+printf("thr_low = %.3f\n", _thr_low) ;
+}
+
+float edge_pressure::get_thr_low(float expected)
+{
+    float thr_low ;
+    
+    switch(_thr_mode) {
+    case 0: /* absolute value */
+        thr_low = expected - _thr_low ;
+        break ;
+    case 1: /* persentage */
+        thr_low = expected * (1.0 - _thr_low) ;
+        break ;
+    default:
+        printf("Unknown Threshold mode %d\n", _thr_mode) ;
+        thr_low = expected + _thr_low ; /* use this as default */
+        break ;
+    }
+    return (thr_low) ;
+}
+
 int edge_pressure::deliver(void) 
 {
     char str_buf[32] ;
     char timestr[16] ;
     int result ;
-    float expected ;
+    float expected, higher, lower ;
     print_time(_sampled_time) ;
     if (current_temp != 0) {
-        sprintf(str_buf, "GAS:%.2f @ %.1fC", _value, *current_temp ) ;
+        sprintf(str_buf, "GAS:%.3f@%.1fC", _value, *current_temp ) ;
     } else {
-        sprintf(str_buf, "GAS:%.2f ", _value  ) ;
+        sprintf(str_buf, "GAS:%.3f ", _value  ) ;
     }
     printf(" ") ;
     printf(str_buf) ;
@@ -93,9 +168,12 @@
     }
     if (current_temp != 0) {
         expected = temp2expected(*current_temp) ;
-        if (_value > (expected + HIGH_THR)) {
+        higher = get_thr_high(expected) ;
+        lower = get_thr_low(expected) ;
+        printf(" (%.3f, %.3f) ", higher, lower) ;
+        if (_value > higher) {
             sprintf(str_buf, "High [exp %.2f]", expected) ;
-        } else if (_value < (expected - LOW_THR)) {
+        } else if (_value < lower) {
             sprintf(str_buf, "Low [exp %.2f]", expected) ;
         } else {
             sprintf(str_buf, "Normal") ;