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.
Diff: edge_sensor/edge_pressure.cpp
- Revision:
- 0:f0de320e23ac
- Child:
- 3:cac964851bb6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/edge_sensor/edge_pressure.cpp Fri Dec 01 06:16:31 2017 +0000
@@ -0,0 +1,121 @@
+#include "mbed.h"
+#include "edge_sensor.h"
+#include "edge_time.h"
+#include "PSE530.h"
+#include "edge_pressure.h"
+#include "SO1602A.h"
+
+extern SO1602A *so1602a ; /* OLED display on I2C */
+
+#define LOW_THR 0.2
+#define HIGH_THR 0.3
+#define MIN_TEMP 12.0
+#define MAX_TEMP 30.0
+
+/**
+ * SMC PSE530 pressure sensor
+ * analog output 1.0V - 5.0V
+ * 1.0V : 0
+ * 5.0V : 1MPa
+ * (at 0.6V : -0.1MPa)
+ * Our sensor I/F converts 0-5V to 0-3V
+ * So we suppose V = Analog Float Value : Pressure
+ * 0.6V = 0.2 : 0
+ * 3.0V = 1.0 : 1MPa
+ */
+
+float temp2expected(float temp)
+{
+ const float coef_A = 0.089 ;
+ const float coef_B = 0.831 ;
+ float pressure ;
+
+ pressure = temp * coef_A + coef_B ;
+ return( pressure ) ;
+}
+
+edge_pressure::edge_pressure(PSE530 *pse)
+{
+ _pse = pse ;
+ _value = 0.0 ;
+ _interval = 30 ;
+}
+
+edge_pressure::~edge_pressure(void)
+{
+ if (_pse) {
+ delete _pse ;
+ }
+ _value = 0.0 ;
+}
+
+float edge_pressure::get_value(void)
+{
+ float value = 0.0 ;
+ value = _pse->getPressure() ;
+ return( value ) ;
+}
+
+void edge_pressure::reset(void)
+{
+ _value = 0.0 ;
+ _sampled_time = 0 ;
+}
+
+void edge_pressure::prepare(void)
+{
+}
+
+void edge_pressure::sample(void)
+{
+ _value = get_value() ;
+ _sampled_time = edge_time ;
+}
+
+int edge_pressure::deliver(void)
+{
+ char str_buf[32] ;
+ int result ;
+ float expected ;
+ print_time(_sampled_time) ;
+ if (current_temp != 0) {
+ sprintf(str_buf, "GAS:%.2f @ %.1fC", _value, *current_temp ) ;
+ } else {
+ sprintf(str_buf, "GAS:%.2f ", _value ) ;
+ }
+ printf(str_buf) ;
+ if (so1602a != 0) {
+ so1602a->clearDisplay() ;
+ so1602a->locate(0, 0) ;
+ so1602a->putStr(str_buf) ;
+ }
+ if (current_temp != 0) {
+ expected = temp2expected(*current_temp) ;
+ if (_value > (expected + HIGH_THR)) {
+ sprintf(str_buf, "High [exp %.2f]", expected) ;
+ } else if (_value < (expected - LOW_THR)) {
+ sprintf(str_buf, "Low [exp %.2f]", expected) ;
+ } else {
+ sprintf(str_buf, "Normal") ;
+ }
+ }
+ if (so1602a != 0) {
+ so1602a->locate(0, 1) ;
+ so1602a->putStr(str_buf) ;
+ }
+ printf(str_buf) ;
+ printf("\n") ;
+ sprintf(_str_buf,
+ "{\"DEVICE\":\"GAS\",\"PN\":\"PSE530\",\"PRESSURE\":\"%.3f\",\"UNIT\":\"kgf/cm2\",\"S\":\"%06d\",\"E\":\"%d\"}",
+ _value, time2seq(_sampled_time), _error_count) ;
+ result = afero->setAttribute(1, _str_buf) ;
+ return( result == afSUCCESS ) ;
+}
+
+void edge_pressure::recv_config(void)
+{
+}
+
+void edge_pressure::send_config(void)
+{
+}
\ No newline at end of file