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.
Dependencies: mbed MMA8451Q USBDevice WakeUp vt100
Fork of afero_node_suntory_2017_06_15 by
Diff: sensors/LiquidPressure/LiquidPressure.cpp
- Revision:
- 1:b2a9a6f2c30e
- Child:
- 2:dfe671e31221
diff -r 20bce0dcc921 -r b2a9a6f2c30e sensors/LiquidPressure/LiquidPressure.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensors/LiquidPressure/LiquidPressure.cpp Thu Jan 19 09:17:16 2017 +0000 @@ -0,0 +1,62 @@ +#include "LiquidPressure.hpp" + +namespace MaruSolSensorManager +{ + LiquidPressure::LiquidPressure() + { + if(PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE]<=0) + { + PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE] = 5; + } + ain = new AnalogIn((PinName)PINS::LIQUID::AIN); + read(); + } + + LiquidPressure::~LiquidPressure() + { + delete ain; + ain = NULL; + } + + float + LiquidPressure::calc() + { + SERIAL_PRINT_DBG_FUNCNAME(); + float &v_ref = SENSORS::GP_M010_KEYENCE::V_REF; + float &shut_r = SENSORS::GP_M010_KEYENCE::SHUNT_R; + float &lowest_cur = SENSORS::GP_M010_KEYENCE::LOWEST_CUR; + float &pressure_coef = SENSORS::GP_M010_KEYENCE::PRESSURE_COEF; + float &val = packet.pressure.val; + float ret; + //(Vref*ain01/ShuntR-LowestCur)*PressureCoef + ret = (v_ref * val / shut_r - lowest_cur) * pressure_coef; + return ret < 0 ? 0 : ret; + } + + void + LiquidPressure::toJSON(char* buf) + { + char* &fmt = SENSORS::GP_M010_KEYENCE::JSON_FMT; + char* &type = SENSORS::GP_M010_KEYENCE::TYPE; + char* &pn = SENSORS::GP_M010_KEYENCE::PN; + char* &unit = SENSORS::GP_M010_KEYENCE::UNIT; + time_t &time = packet.pressure.timeStamp; + sprintf(buf,fmt,type,pn,time,calc(),unit); + } + void + LiquidPressure::getBytes(uint8_t*) + { + } + + void + LiquidPressure::go() + { + SERIAL_PRINT_DBG_FUNCNAME(); + timeout.attach(&onRead, PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE]); + packet.pressure.val = ain->read(); + SERIAL_PRINT_DBG_FUNCNAME(); + RTC_GET_UTC(packet.pressure.timeStamp); + ToDoQ::queuePut(this); + backToNOP(); + } +}; \ No newline at end of file