Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 12:4c0bd7fce2fd, committed 2017-12-12
- Comitter:
- Rhyme
- Date:
- Tue Dec 12 02:28:51 2017 +0000
- Parent:
- 11:99eb6741ada4
- Child:
- 13:88ee926c56ae
- Commit message:
- Threshold control mode/high/low added
Changed in this revision
--- a/af_utils/af_attriburtes.cpp Mon Dec 11 05:52:25 2017 +0000
+++ b/af_utils/af_attriburtes.cpp Tue Dec 12 02:28:51 2017 +0000
@@ -77,6 +77,9 @@
{ ATTR_GAS_ENABLE, "Gas Pressure Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
{ ATTR_GAS_INTERVAL, "Gas Pressure Interval", ATTRIBUTE_TYPE_SINT16, 2 },
{ ATTR_GAS_VALUE, "Gas Pressure Value", ATTRIBUTE_TYPE_FIXED_15_16, 4},
+ { ATTR_GAS_THR_MODE, "Gas Press Threshold Mode", ATTRIBUTE_TYPE_SINT8, 1 },
+ { ATTR_GAS_THR_HIGH, "Gas Press High Thresh", ATTRIBUTE_TYPE_SINT16, 2 },
+ { ATTR_GAS_THR_LOW, "Gas Press Low Thresh", ATTRIBUTE_TYPE_SINT16, 2 },
/* Software Reset Request */
{ ATTR_SOFTWARE_RESET, "Software Reset", ATTRIBUTE_TYPE_BOOLEAN, 1 },
@@ -485,6 +488,24 @@
afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
}
break ;
+ case ATTR_GAS_THR_MODE:
+ if (sensor[4]) {
+ ((edge_pressure*)sensor[4])->set_thr_mode(value[0]) ;
+ afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
+ }
+ break ;
+ case ATTR_GAS_THR_HIGH:
+ if (sensor[4]) {
+ ((edge_pressure*)sensor[4])->set_thr_high((value[1] << 8) | value[0]) ;
+ afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
+ }
+ break ;
+ case ATTR_GAS_THR_LOW:
+ if (sensor[4]) {
+ ((edge_pressure*)sensor[4])->set_thr_low((value[1] << 8) | value[0]) ;
+ afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
+ }
+ break ;
default:
break ;
}
--- a/af_utils/af_attributes.h Mon Dec 11 05:52:25 2017 +0000 +++ b/af_utils/af_attributes.h Tue Dec 12 02:28:51 2017 +0000 @@ -97,6 +97,9 @@ #define ATTR_GAS_ENABLE 401 #define ATTR_GAS_INTERVAL 402 #define ATTR_GAS_VALUE 403 +#define ATTR_GAS_THR_MODE 404 +#define ATTR_GAS_THR_HIGH 405 +#define ATTR_GAS_THR_LOW 406 /* current trans sensor */ #define ATTR_CURRENT_PRESENT 500
--- 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") ;
--- a/edge_sensor/edge_pressure.h Mon Dec 11 05:52:25 2017 +0000
+++ b/edge_sensor/edge_pressure.h Tue Dec 12 02:28:51 2017 +0000
@@ -17,10 +17,19 @@
virtual void recv_config(void) ; /* receive config data from cloud */
float get_value(void) ;
-
+ void set_thr_mode(int mode) { _thr_mode = mode ; }
+ int get_thr_mode(void) { return _thr_mode ; }
+ void set_thr_high(int16_t thr_high) ;
+ float get_thr_high(float expected) ;
+ void set_thr_low(int16_t thr_low) ;
+ float get_thr_low(float expected) ;
+
private:
PSE530 *_pse ;
float _value ;
+ float _thr_high ;
+ float _thr_low ;
+ int _thr_mode ;
} ;
float temp2expected(float temp) ;
--- a/edge_utils/edge_mgr.cpp Mon Dec 11 05:52:25 2017 +0000
+++ b/edge_utils/edge_mgr.cpp Tue Dec 12 02:28:51 2017 +0000
@@ -121,6 +121,9 @@
if (sensor[sensor_index]) {
afero->setAttributeBool(ATTR_GAS_PRESENT, true) ;
afero->setAttributeBool(ATTR_GAS_ENABLE, true) ;
+ afero->getAttribute(ATTR_GAS_THR_MODE) ;
+ afero->getAttribute(ATTR_GAS_THR_HIGH) ;
+ afero->getAttribute(ATTR_GAS_THR_LOW) ;
} else {
afero->setAttributeBool(ATTR_GAS_PRESENT, false) ;
}