Release candidate version. The pointer in GAS Pressure display is changed to a triangle.

Dependencies:   UniGraphic mbed vt100

Please note, at 2-Mar-2018 the current version of mbed-lib has a defect in Ticker.
https://os.mbed.com/forum/bugs-suggestions/topic/29287/

So, mbed lib version 157 is intentionally being used.
Please do not update mbed library until the problem in the above URL is fixed.

In this version, format of GAS Pressure Display has been changed.
/media/uploads/Rhyme/low.jpg

/media/uploads/Rhyme/good.jpg

/media/uploads/Rhyme/high.jpg

moto

Committer:
Rhyme
Date:
Fri Mar 02 07:56:09 2018 +0000
Revision:
0:774324cbc5a6
Release candidate version. GAS Pressure pointer is now a triangle.; Some source file clean-up was done.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:774324cbc5a6 1 #include "mbed.h"
Rhyme 0:774324cbc5a6 2 #include "edge_mgr.h"
Rhyme 0:774324cbc5a6 3 #include "af_attributes.h"
Rhyme 0:774324cbc5a6 4
Rhyme 0:774324cbc5a6 5 #include "edge_time.h"
Rhyme 0:774324cbc5a6 6 #include "edge_pin.h"
Rhyme 0:774324cbc5a6 7 #include "MMA8451Q.h"
Rhyme 0:774324cbc5a6 8 #include "VEML6040.h"
Rhyme 0:774324cbc5a6 9 #include "LM75B.h"
Rhyme 0:774324cbc5a6 10 #include "SMTC502AT.h"
Rhyme 0:774324cbc5a6 11 #include "PSE530.h"
Rhyme 0:774324cbc5a6 12 #include <ILI9341.h>
Rhyme 0:774324cbc5a6 13 #include "Arial12x12.h"
Rhyme 0:774324cbc5a6 14 #include "Arial24x23.h"
Rhyme 0:774324cbc5a6 15 #include "Arial28x28.h"
Rhyme 0:774324cbc5a6 16
Rhyme 0:774324cbc5a6 17 #include "edge_sensor.h"
Rhyme 0:774324cbc5a6 18 #include "edge_accel.h"
Rhyme 0:774324cbc5a6 19 #include "edge_color.h"
Rhyme 0:774324cbc5a6 20 #include "edge_temp.h"
Rhyme 0:774324cbc5a6 21 #include "edge_pressure.h"
Rhyme 0:774324cbc5a6 22 #include "edge_reset_mgr.h"
Rhyme 0:774324cbc5a6 23 #include "edge_chart.h"
Rhyme 0:774324cbc5a6 24
Rhyme 0:774324cbc5a6 25 #define MMA8451Q_I2C_ADDRESS 0x1C
Rhyme 0:774324cbc5a6 26 #define VEML6040_I2C_ADDRESS 0x10
Rhyme 0:774324cbc5a6 27 #define LM75B_I2C_ADDRESS 0x48
Rhyme 0:774324cbc5a6 28 #define SO1602A_I2C_ADDRESS 0x3C
Rhyme 0:774324cbc5a6 29
Rhyme 0:774324cbc5a6 30 #define NUM_MAX_SENSOR 5
Rhyme 0:774324cbc5a6 31
Rhyme 0:774324cbc5a6 32 uint16_t attr_to_set[] = {
Rhyme 0:774324cbc5a6 33 ATTR_ACCEL_PRESENT,
Rhyme 0:774324cbc5a6 34 ATTR_COLOR0_PRESENT,
Rhyme 0:774324cbc5a6 35 ATTR_COLOR1_PRESENT,
Rhyme 0:774324cbc5a6 36 ATTR_TEMP0_PRESENT,
Rhyme 0:774324cbc5a6 37 ATTR_GAS_PRESENT,
Rhyme 0:774324cbc5a6 38 } ;
Rhyme 0:774324cbc5a6 39
Rhyme 0:774324cbc5a6 40 uint16_t attr_to_get[] = {
Rhyme 0:774324cbc5a6 41 // accel
Rhyme 0:774324cbc5a6 42 ATTR_ACCEL_ENABLE,
Rhyme 0:774324cbc5a6 43 ATTR_ACCEL_INTERVAL,
Rhyme 0:774324cbc5a6 44 // Color0
Rhyme 0:774324cbc5a6 45 ATTR_COLOR0_ENABLE,
Rhyme 0:774324cbc5a6 46 ATTR_COLOR0_INTERVAL,
Rhyme 0:774324cbc5a6 47 ATTR_COLOR0_ITIME,
Rhyme 0:774324cbc5a6 48 ATTR_COLOR0_PWM_PERIOD,
Rhyme 0:774324cbc5a6 49 ATTR_COLOR0_PWM_TARGET,
Rhyme 0:774324cbc5a6 50 ATTR_COLOR0_PWM_R,
Rhyme 0:774324cbc5a6 51 ATTR_COLOR0_PWM_G,
Rhyme 0:774324cbc5a6 52 ATTR_COLOR0_PWM_B,
Rhyme 0:774324cbc5a6 53 // Color1
Rhyme 0:774324cbc5a6 54 ATTR_COLOR1_ENABLE,
Rhyme 0:774324cbc5a6 55 ATTR_COLOR1_INTERVAL,
Rhyme 0:774324cbc5a6 56 ATTR_COLOR1_ITIME,
Rhyme 0:774324cbc5a6 57 ATTR_COLOR1_PWM_PERIOD,
Rhyme 0:774324cbc5a6 58 ATTR_COLOR1_PWM_TARGET,
Rhyme 0:774324cbc5a6 59 ATTR_COLOR1_PWM_R,
Rhyme 0:774324cbc5a6 60 ATTR_COLOR1_PWM_G,
Rhyme 0:774324cbc5a6 61 ATTR_COLOR1_PWM_B,
Rhyme 0:774324cbc5a6 62 // Temp
Rhyme 0:774324cbc5a6 63 ATTR_TEMP0_INTERVAL,
Rhyme 0:774324cbc5a6 64 ATTR_TEMP0_ENABLE,
Rhyme 0:774324cbc5a6 65 // Gas Pressure
Rhyme 0:774324cbc5a6 66 ATTR_GAS_ENABLE,
Rhyme 0:774324cbc5a6 67 ATTR_GAS_INTERVAL,
Rhyme 0:774324cbc5a6 68 ATTR_GAS_THR_MODE,
Rhyme 0:774324cbc5a6 69 ATTR_GAS_THR_HIGH,
Rhyme 0:774324cbc5a6 70 ATTR_GAS_THR_LOW,
Rhyme 0:774324cbc5a6 71 0 } ;
Rhyme 0:774324cbc5a6 72
Rhyme 0:774324cbc5a6 73 bool verbos = true ;
Rhyme 0:774324cbc5a6 74 edge_sensor *sensor[NUM_MAX_SENSOR] ;
Rhyme 0:774324cbc5a6 75 int num_sensor = 0 ;
Rhyme 0:774324cbc5a6 76
Rhyme 0:774324cbc5a6 77 edge_accel *accel = 0 ;
Rhyme 0:774324cbc5a6 78 edge_color *color[2] = {0, 0} ;
Rhyme 0:774324cbc5a6 79 edge_temp *temp = 0 ;
Rhyme 0:774324cbc5a6 80 edge_pressure *pressure = 0 ;
Rhyme 0:774324cbc5a6 81
Rhyme 0:774324cbc5a6 82 PwmOut *led[3] = {0, 0, 0} ;
Rhyme 0:774324cbc5a6 83 uint16_t pwm[3] = { 0x5FA2, 0xB09B, 0x83DF } ;
Rhyme 0:774324cbc5a6 84 I2C *edge_i2c0 = 0 ;
Rhyme 0:774324cbc5a6 85 I2C *edge_i2c1 = 0 ;
Rhyme 0:774324cbc5a6 86 ILI9341 *display = 0 ;
Rhyme 0:774324cbc5a6 87 MMA8451Q *mma8451q = 0 ;
Rhyme 0:774324cbc5a6 88 VEML6040 *veml6040[2] = { 0, 0 } ;
Rhyme 0:774324cbc5a6 89 LM75B *lm75b0 = 0 ; /* for temp1 */
Rhyme 0:774324cbc5a6 90 AnalogIn *an0 = 0 ; /* for temp2 */
Rhyme 0:774324cbc5a6 91 SMTC502AT *smtc502at0 = 0 ;
Rhyme 0:774324cbc5a6 92 AnalogIn *an1 = 0 ; /* for temp3 */
Rhyme 0:774324cbc5a6 93 SMTC502AT *smtc502at1 = 0 ;
Rhyme 0:774324cbc5a6 94 LM75B *lm75b1 = 0 ; /* for temp4 */
Rhyme 0:774324cbc5a6 95 AnalogIn *an2 = 0 ; /* for gas pressure */
Rhyme 0:774324cbc5a6 96 PSE530 *pse530 = 0 ; /* gas pressure sensor */
Rhyme 0:774324cbc5a6 97
Rhyme 0:774324cbc5a6 98 DigitalOut *tft_reset = 0 ;
Rhyme 0:774324cbc5a6 99 DigitalOut *tft_backlight = 0 ;
Rhyme 0:774324cbc5a6 100 DigitalOut *tft_cs = 0 ;
Rhyme 0:774324cbc5a6 101 DigitalOut *pse530_en = 0 ;
Rhyme 0:774324cbc5a6 102
Rhyme 0:774324cbc5a6 103 static int error_tolerance = 100 ;
Rhyme 0:774324cbc5a6 104 static int loop_interval = 100 ; // 1000 ;
Rhyme 0:774324cbc5a6 105 static int accel_interval = 10 ;
Rhyme 0:774324cbc5a6 106 int edge_mgr_status = EDGE_MGR_INIT ;
Rhyme 0:774324cbc5a6 107 char *reset_reason_str = 0 ;
Rhyme 0:774324cbc5a6 108 int display_mode = 1 ;
Rhyme 0:774324cbc5a6 109 bool reboot_requested = false ;
Rhyme 0:774324cbc5a6 110
Rhyme 0:774324cbc5a6 111 void init_display(void)
Rhyme 0:774324cbc5a6 112 {
Rhyme 0:774324cbc5a6 113 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 114 printf("TFT Initializing\n") ;
Rhyme 0:774324cbc5a6 115 tft_reset = new DigitalOut(PIN_RESET_TFT, 1) ;
Rhyme 0:774324cbc5a6 116 tft_backlight = new DigitalOut(PIN_BL_TFT, 0) ;
Rhyme 0:774324cbc5a6 117 tft_cs = new DigitalOut(PIN_CS_TFT, 1) ;
Rhyme 0:774324cbc5a6 118
Rhyme 0:774324cbc5a6 119 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 120 display = new ILI9341(SPI_8, 10000000,
Rhyme 0:774324cbc5a6 121 PIN_MOSI, PIN_MISO, PIN_SCK,
Rhyme 0:774324cbc5a6 122 PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "LaSuno") ;
Rhyme 0:774324cbc5a6 123
Rhyme 0:774324cbc5a6 124 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 125 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 126 display->set_orientation(1) ;
Rhyme 0:774324cbc5a6 127
Rhyme 0:774324cbc5a6 128 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 129 display->cls() ;
Rhyme 0:774324cbc5a6 130 *tft_backlight = 1 ;
Rhyme 0:774324cbc5a6 131 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 132 printf("TFT Initialized\n") ;
Rhyme 0:774324cbc5a6 133 }
Rhyme 0:774324cbc5a6 134
Rhyme 0:774324cbc5a6 135 void edge_splash(void)
Rhyme 0:774324cbc5a6 136 {
Rhyme 0:774324cbc5a6 137 printf("Sensor loop started!\n") ;
Rhyme 0:774324cbc5a6 138 if (display) {
Rhyme 0:774324cbc5a6 139 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 140 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 141 display->cls() ;
Rhyme 0:774324cbc5a6 142 display->foreground(Green) ;
Rhyme 0:774324cbc5a6 143 display->locate(40, 20) ;
Rhyme 0:774324cbc5a6 144 display->printf("Sensor Loop") ;
Rhyme 0:774324cbc5a6 145 display->locate(40, 60) ;
Rhyme 0:774324cbc5a6 146 display->printf(" Started!") ;
Rhyme 0:774324cbc5a6 147 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 148 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 149 }
Rhyme 0:774324cbc5a6 150 }
Rhyme 0:774324cbc5a6 151
Rhyme 0:774324cbc5a6 152 int init_edge_attribute(void)
Rhyme 0:774324cbc5a6 153 {
Rhyme 0:774324cbc5a6 154 static int sensor_index = 0 ;
Rhyme 0:774324cbc5a6 155 static int attr_index = 0 ;
Rhyme 0:774324cbc5a6 156 static int error_count = 0 ;
Rhyme 0:774324cbc5a6 157 int return_value = 1 ;
Rhyme 0:774324cbc5a6 158 int result ;
Rhyme 0:774324cbc5a6 159
Rhyme 0:774324cbc5a6 160 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 161
Rhyme 0:774324cbc5a6 162 if (reset_reason_str) {
Rhyme 0:774324cbc5a6 163 result = afero->setAttribute(ATTR_MCU_RESET_REASON, reset_reason_str) ;
Rhyme 0:774324cbc5a6 164 if (result == afSUCCESS) {
Rhyme 0:774324cbc5a6 165 error_count = 0 ;
Rhyme 0:774324cbc5a6 166 reset_reason_str = 0 ;
Rhyme 0:774324cbc5a6 167 } else {
Rhyme 0:774324cbc5a6 168 error_count++ ;
Rhyme 0:774324cbc5a6 169 }
Rhyme 0:774324cbc5a6 170 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 171 }
Rhyme 0:774324cbc5a6 172 if (sensor_index < NUM_MAX_SENSOR) {// for each sensor send presence
Rhyme 0:774324cbc5a6 173 // printf("Setting sensor[%d] presence\n", sensor_index) ;
Rhyme 0:774324cbc5a6 174 if (sensor_index == 3) { /* for temp lm75b0 is used */
Rhyme 0:774324cbc5a6 175 result = afero->setAttributeBool(attr_to_set[sensor_index], lm75b0) ;
Rhyme 0:774324cbc5a6 176 } else {
Rhyme 0:774324cbc5a6 177 result = afero->setAttributeBool(attr_to_set[sensor_index], sensor[sensor_index]) ;
Rhyme 0:774324cbc5a6 178 }
Rhyme 0:774324cbc5a6 179 if (result == afSUCCESS) {
Rhyme 0:774324cbc5a6 180 error_count = 0 ;
Rhyme 0:774324cbc5a6 181 sensor_index++ ;
Rhyme 0:774324cbc5a6 182 } else {
Rhyme 0:774324cbc5a6 183 error_count++ ;
Rhyme 0:774324cbc5a6 184 }
Rhyme 0:774324cbc5a6 185 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 186 } else { // all sensor presence sent, now get attributes
Rhyme 0:774324cbc5a6 187 if (attr_to_get[attr_index] != 0) {
Rhyme 0:774324cbc5a6 188 // printf("getting attribute [%d]\n", attr_index) ;
Rhyme 0:774324cbc5a6 189 result = afero->getAttribute(attr_to_get[attr_index]) ;
Rhyme 0:774324cbc5a6 190 if (result == afSUCCESS) {
Rhyme 0:774324cbc5a6 191 error_count = 0 ;
Rhyme 0:774324cbc5a6 192 attr_index++ ;
Rhyme 0:774324cbc5a6 193 } else {
Rhyme 0:774324cbc5a6 194 error_count++ ;
Rhyme 0:774324cbc5a6 195 }
Rhyme 0:774324cbc5a6 196 }
Rhyme 0:774324cbc5a6 197 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 198 }
Rhyme 0:774324cbc5a6 199
Rhyme 0:774324cbc5a6 200 if (error_count > error_tolerance) { // too many fails, trying reset
Rhyme 0:774324cbc5a6 201 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 202 reboot_edge() ;
Rhyme 0:774324cbc5a6 203 }
Rhyme 0:774324cbc5a6 204
Rhyme 0:774324cbc5a6 205 if ((sensor_index >= NUM_MAX_SENSOR)&&(attr_to_get[attr_index] == 0)) { /* all sensors attributes done */
Rhyme 0:774324cbc5a6 206 sensor_index = 0 ;
Rhyme 0:774324cbc5a6 207 attr_index = 0 ;
Rhyme 0:774324cbc5a6 208 return_value = 0 ;
Rhyme 0:774324cbc5a6 209 }
Rhyme 0:774324cbc5a6 210 return(return_value) ;
Rhyme 0:774324cbc5a6 211 }
Rhyme 0:774324cbc5a6 212
Rhyme 0:774324cbc5a6 213 void edge_loop(uint32_t count_robin)
Rhyme 0:774324cbc5a6 214 {
Rhyme 0:774324cbc5a6 215 static int sensor_index = 0 ;
Rhyme 0:774324cbc5a6 216 int result ;
Rhyme 0:774324cbc5a6 217
Rhyme 0:774324cbc5a6 218 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 219
Rhyme 0:774324cbc5a6 220 if ((count_robin % accel_interval) == 0) {
Rhyme 0:774324cbc5a6 221 if (accel) {
Rhyme 0:774324cbc5a6 222 accel->accum() ; /* get and accum accel data */
Rhyme 0:774324cbc5a6 223 }
Rhyme 0:774324cbc5a6 224 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 225 }
Rhyme 0:774324cbc5a6 226
Rhyme 0:774324cbc5a6 227 if ((count_robin % loop_interval) == 0) {
Rhyme 0:774324cbc5a6 228 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 229 loop_interval = 10 ;
Rhyme 0:774324cbc5a6 230 if ((sensor[sensor_index])&&(sensor[sensor_index]->isEnabled())) {
Rhyme 0:774324cbc5a6 231 switch(sensor_index) {
Rhyme 0:774324cbc5a6 232 case SENSOR_ID_COLOR1: /* color0 */
Rhyme 0:774324cbc5a6 233 if (((edge_color*)sensor[sensor_index])->calibration_requested()) {
Rhyme 0:774324cbc5a6 234 ((edge_color*)sensor[sensor_index])->calibrate(color0_target, color0_pwm, 10) ;
Rhyme 0:774324cbc5a6 235 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 236 while((result = afero->setAttribute32(ATTR_COLOR0_PWM_R, color0_pwm[0])) != afSUCCESS) {
Rhyme 0:774324cbc5a6 237 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 238 print_af_error(result) ;
Rhyme 0:774324cbc5a6 239 wait_ms(10) ;
Rhyme 0:774324cbc5a6 240 }
Rhyme 0:774324cbc5a6 241 while((result = afero->setAttribute32(ATTR_COLOR0_PWM_G, color0_pwm[1])) != afSUCCESS) {
Rhyme 0:774324cbc5a6 242 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 243 print_af_error(result) ;
Rhyme 0:774324cbc5a6 244 wait_ms(10) ;
Rhyme 0:774324cbc5a6 245 }
Rhyme 0:774324cbc5a6 246 while((result = afero->setAttribute32(ATTR_COLOR0_PWM_B, color0_pwm[2])) != afSUCCESS) {
Rhyme 0:774324cbc5a6 247 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 248 print_af_error(result) ;
Rhyme 0:774324cbc5a6 249 wait_ms(10) ;
Rhyme 0:774324cbc5a6 250 }
Rhyme 0:774324cbc5a6 251 while((afero->setAttributeBool(ATTR_COLOR0_CALIBRATE, false)) != afSUCCESS) {
Rhyme 0:774324cbc5a6 252 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 253 print_af_error(result) ;
Rhyme 0:774324cbc5a6 254 wait_ms(10) ;
Rhyme 0:774324cbc5a6 255 }
Rhyme 0:774324cbc5a6 256 } else {
Rhyme 0:774324cbc5a6 257 sensor[sensor_index]->runStateMachine() ;
Rhyme 0:774324cbc5a6 258 }
Rhyme 0:774324cbc5a6 259 break ;
Rhyme 0:774324cbc5a6 260 case SENSOR_ID_COLOR2: /* color1 */
Rhyme 0:774324cbc5a6 261 if (((edge_color*)sensor[sensor_index])->calibration_requested()) {
Rhyme 0:774324cbc5a6 262 ((edge_color*)sensor[sensor_index])->calibrate(color1_target, color1_pwm, 10) ;
Rhyme 0:774324cbc5a6 263 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 264 if ((result = afero->setAttribute32(ATTR_COLOR1_PWM_R, color1_pwm[0])) != afSUCCESS) {
Rhyme 0:774324cbc5a6 265 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 266 print_af_error(result) ;
Rhyme 0:774324cbc5a6 267 wait_ms(10) ;
Rhyme 0:774324cbc5a6 268 }
Rhyme 0:774324cbc5a6 269 if ((result = afero->setAttribute32(ATTR_COLOR1_PWM_G, color1_pwm[1])) != afSUCCESS) {
Rhyme 0:774324cbc5a6 270 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 271 print_af_error(result) ;
Rhyme 0:774324cbc5a6 272 wait_ms(10) ;
Rhyme 0:774324cbc5a6 273 }
Rhyme 0:774324cbc5a6 274 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 275 if ((result = afero->setAttribute32(ATTR_COLOR1_PWM_B, color1_pwm[2])) != afSUCCESS) {
Rhyme 0:774324cbc5a6 276 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 277 print_af_error(result) ;
Rhyme 0:774324cbc5a6 278 wait_ms(10) ;
Rhyme 0:774324cbc5a6 279 }
Rhyme 0:774324cbc5a6 280 while((afero->setAttributeBool(ATTR_COLOR1_CALIBRATE, false)) != afSUCCESS) {
Rhyme 0:774324cbc5a6 281 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 282 print_af_error(result) ;
Rhyme 0:774324cbc5a6 283 wait_ms(10) ;
Rhyme 0:774324cbc5a6 284 }
Rhyme 0:774324cbc5a6 285 } else {
Rhyme 0:774324cbc5a6 286 sensor[sensor_index]->runStateMachine() ;
Rhyme 0:774324cbc5a6 287 }
Rhyme 0:774324cbc5a6 288 break ;
Rhyme 0:774324cbc5a6 289 default:
Rhyme 0:774324cbc5a6 290 sensor[sensor_index]->runStateMachine() ;
Rhyme 0:774324cbc5a6 291 break ;
Rhyme 0:774324cbc5a6 292 }
Rhyme 0:774324cbc5a6 293 }
Rhyme 0:774324cbc5a6 294 sensor_index = (sensor_index + 1) % NUM_MAX_SENSOR ;
Rhyme 0:774324cbc5a6 295 }
Rhyme 0:774324cbc5a6 296 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 297 }
Rhyme 0:774324cbc5a6 298
Rhyme 0:774324cbc5a6 299 int is_present(I2C *i2c, int address)
Rhyme 0:774324cbc5a6 300 {
Rhyme 0:774324cbc5a6 301 char t[1] = { 0 } ;
Rhyme 0:774324cbc5a6 302 char data[2] = { 0, 0 } ;
Rhyme 0:774324cbc5a6 303 int result ;
Rhyme 0:774324cbc5a6 304 address <<= 1 ;
Rhyme 0:774324cbc5a6 305 result = i2c->write(address, t, 1, true) ;
Rhyme 0:774324cbc5a6 306 if (result == 0) {
Rhyme 0:774324cbc5a6 307 result = i2c->read(address, data, 2) ;
Rhyme 0:774324cbc5a6 308 }
Rhyme 0:774324cbc5a6 309 return((result == 0)) ;
Rhyme 0:774324cbc5a6 310 }
Rhyme 0:774324cbc5a6 311
Rhyme 0:774324cbc5a6 312 void init_sensors(void)
Rhyme 0:774324cbc5a6 313 {
Rhyme 0:774324cbc5a6 314 printf("=== Initializing Sensor(s) ===\n") ;
Rhyme 0:774324cbc5a6 315 edge_i2c0 = new I2C(PIN_I2C0_SDA, PIN_I2C0_SCL) ;
Rhyme 0:774324cbc5a6 316 edge_i2c1 = new I2C(PIN_I2C1_SDA, PIN_I2C1_SCL) ;
Rhyme 0:774324cbc5a6 317
Rhyme 0:774324cbc5a6 318 if (display) {
Rhyme 0:774324cbc5a6 319 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 320 printf("printing inital string to TFT\n") ;
Rhyme 0:774324cbc5a6 321 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 322
Rhyme 0:774324cbc5a6 323
Rhyme 0:774324cbc5a6 324 display->background(Black) ;
Rhyme 0:774324cbc5a6 325 display->foreground(White) ;
Rhyme 0:774324cbc5a6 326 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 327 display->cls() ;
Rhyme 0:774324cbc5a6 328 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 329 display->set_font((unsigned char*) Arial24x23);
Rhyme 0:774324cbc5a6 330 display->foreground(Green) ;
Rhyme 0:774324cbc5a6 331 display->locate(70, 5) ;
Rhyme 0:774324cbc5a6 332 display->printf("Suntory") ;
Rhyme 0:774324cbc5a6 333 display->locate(30, 30) ;
Rhyme 0:774324cbc5a6 334 display->printf("Server Monitor") ;
Rhyme 0:774324cbc5a6 335 display->set_font((unsigned char*) Arial28x28);
Rhyme 0:774324cbc5a6 336 display->foreground(White) ;
Rhyme 0:774324cbc5a6 337 display->locate(30, 60) ;
Rhyme 0:774324cbc5a6 338 display->printf("La Suno") ;
Rhyme 0:774324cbc5a6 339 display->locate(30, 100) ;
Rhyme 0:774324cbc5a6 340 display->foreground(Red) ;
Rhyme 0:774324cbc5a6 341 display->printf("Preparing...") ;
Rhyme 0:774324cbc5a6 342 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 343 printf("Done\n") ;
Rhyme 0:774324cbc5a6 344 wait(0.1) ;
Rhyme 0:774324cbc5a6 345 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 346 display->cls() ;
Rhyme 0:774324cbc5a6 347 display->foreground(Yellow) ;
Rhyme 0:774324cbc5a6 348 display->locate(40, 5) ;
Rhyme 0:774324cbc5a6 349 display->printf("Probing sensors...") ;
Rhyme 0:774324cbc5a6 350 display->foreground(Green) ;
Rhyme 0:774324cbc5a6 351 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 352 }
Rhyme 0:774324cbc5a6 353 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 354 if (is_present(edge_i2c1, MMA8451Q_I2C_ADDRESS)) {
Rhyme 0:774324cbc5a6 355 printf("MMA8451Q on I2C1 is present\n") ;
Rhyme 0:774324cbc5a6 356 if (display) {
Rhyme 0:774324cbc5a6 357 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 358 display->locate(30, num_sensor * 30 + 40) ;
Rhyme 0:774324cbc5a6 359 display->printf("ACCEL is present") ;
Rhyme 0:774324cbc5a6 360 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 361 }
Rhyme 0:774324cbc5a6 362 mma8451q = new MMA8451Q(edge_i2c1, MMA8451Q_I2C_ADDRESS) ;
Rhyme 0:774324cbc5a6 363 accel = new edge_accel(mma8451q) ;
Rhyme 0:774324cbc5a6 364 sensor[SENSOR_ID_ACCEL] = accel ;
Rhyme 0:774324cbc5a6 365 sensor[SENSOR_ID_ACCEL]->setId(SENSOR_ID_ACCEL) ;
Rhyme 0:774324cbc5a6 366 num_sensor++ ;
Rhyme 0:774324cbc5a6 367 } else {
Rhyme 0:774324cbc5a6 368 sensor[SENSOR_ID_ACCEL] = 0 ;
Rhyme 0:774324cbc5a6 369 printf("MMA8451Q is absent\n") ;
Rhyme 0:774324cbc5a6 370 }
Rhyme 0:774324cbc5a6 371 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 372 if (is_present(edge_i2c1, VEML6040_I2C_ADDRESS)) {
Rhyme 0:774324cbc5a6 373 printf("VEML6040 on I2C1 is present\n") ;
Rhyme 0:774324cbc5a6 374 if (display) {
Rhyme 0:774324cbc5a6 375 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 376 display->locate(30, num_sensor * 30 + 40) ;
Rhyme 0:774324cbc5a6 377 display->printf("COLOR1 is present") ;
Rhyme 0:774324cbc5a6 378 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 379 }
Rhyme 0:774324cbc5a6 380 veml6040[0] = new VEML6040(edge_i2c1, VEML6040_I2C_ADDRESS) ;
Rhyme 0:774324cbc5a6 381 led[0] = new PwmOut(PIN_LED_R) ;
Rhyme 0:774324cbc5a6 382 led[1] = new PwmOut(PIN_LED_G) ;
Rhyme 0:774324cbc5a6 383 led[2] = new PwmOut(PIN_LED_B) ;
Rhyme 0:774324cbc5a6 384 color[0] = new edge_color(veml6040[0], led, pwm) ;
Rhyme 0:774324cbc5a6 385 sensor[SENSOR_ID_COLOR1] = color[0] ;
Rhyme 0:774324cbc5a6 386 sensor[SENSOR_ID_COLOR1]->setId(SENSOR_ID_COLOR1) ;
Rhyme 0:774324cbc5a6 387 num_sensor++ ;
Rhyme 0:774324cbc5a6 388 } else {
Rhyme 0:774324cbc5a6 389 sensor[SENSOR_ID_COLOR1] = 0 ;
Rhyme 0:774324cbc5a6 390 printf("VEML6040 on I2C1 is absent\n") ;
Rhyme 0:774324cbc5a6 391 }
Rhyme 0:774324cbc5a6 392 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 393 if (is_present(edge_i2c0, VEML6040_I2C_ADDRESS)) {
Rhyme 0:774324cbc5a6 394 printf("VEML6040 on I2C0 is present\n") ;
Rhyme 0:774324cbc5a6 395 if (display) {
Rhyme 0:774324cbc5a6 396 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 397 display->locate(30, num_sensor * 30 + 40) ;
Rhyme 0:774324cbc5a6 398 display->printf("COLOR2 is present") ;
Rhyme 0:774324cbc5a6 399 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 400 }
Rhyme 0:774324cbc5a6 401 veml6040[1] = new VEML6040(edge_i2c0, VEML6040_I2C_ADDRESS) ;
Rhyme 0:774324cbc5a6 402 if (led[0] == 0) {
Rhyme 0:774324cbc5a6 403 led[0] = new PwmOut(PIN_LED_R) ;
Rhyme 0:774324cbc5a6 404 led[1] = new PwmOut(PIN_LED_G) ;
Rhyme 0:774324cbc5a6 405 led[2] = new PwmOut(PIN_LED_B) ;
Rhyme 0:774324cbc5a6 406 }
Rhyme 0:774324cbc5a6 407 color[1] = new edge_color(veml6040[1], led, pwm) ;
Rhyme 0:774324cbc5a6 408 sensor[SENSOR_ID_COLOR2] = color[1] ;
Rhyme 0:774324cbc5a6 409 sensor[SENSOR_ID_COLOR2]->setId(SENSOR_ID_COLOR2) ;
Rhyme 0:774324cbc5a6 410 num_sensor++ ;
Rhyme 0:774324cbc5a6 411 } else {
Rhyme 0:774324cbc5a6 412 sensor[SENSOR_ID_COLOR2] = 0 ;
Rhyme 0:774324cbc5a6 413 printf("VEML6040 on I2C0 is absent\n") ;
Rhyme 0:774324cbc5a6 414 }
Rhyme 0:774324cbc5a6 415 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 416 if (is_present(edge_i2c1, LM75B_I2C_ADDRESS)) {
Rhyme 0:774324cbc5a6 417 printf("LM75B on I2C1 is present\n") ;
Rhyme 0:774324cbc5a6 418 if (display) {
Rhyme 0:774324cbc5a6 419 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 420 display->locate(30, num_sensor * 30 + 40) ;
Rhyme 0:774324cbc5a6 421 display->printf("TEMP1 is present") ;
Rhyme 0:774324cbc5a6 422 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 423 }
Rhyme 0:774324cbc5a6 424 lm75b0 = new LM75B(edge_i2c1, LM75B_I2C_ADDRESS) ;
Rhyme 0:774324cbc5a6 425 } else {
Rhyme 0:774324cbc5a6 426 printf("LM75B on I2C1 is absent\n") ;
Rhyme 0:774324cbc5a6 427 }
Rhyme 0:774324cbc5a6 428 #if 0
Rhyme 0:774324cbc5a6 429 if (is_present(edge_i2c0, LM75B_I2C_ADDRESS)) {
Rhyme 0:774324cbc5a6 430 printf("LM75B on I2C0 is present\n") ;
Rhyme 0:774324cbc5a6 431 lm75b1 = new LM75B(edge_i2c0, LM75B_I2C_ADDRESS) ;
Rhyme 0:774324cbc5a6 432 } else {
Rhyme 0:774324cbc5a6 433 printf("LM75B on I2C0 is absent\n") ;
Rhyme 0:774324cbc5a6 434 }
Rhyme 0:774324cbc5a6 435 #endif
Rhyme 0:774324cbc5a6 436 if (display) { /* press is present anyway */
Rhyme 0:774324cbc5a6 437 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 438 if (lm75b0) {
Rhyme 0:774324cbc5a6 439 display->locate(30, (num_sensor+1) * 30 + 40) ;
Rhyme 0:774324cbc5a6 440 } else {
Rhyme 0:774324cbc5a6 441 display->locate(30, num_sensor * 30 + 40) ;
Rhyme 0:774324cbc5a6 442 }
Rhyme 0:774324cbc5a6 443 display->printf("PRESS is present") ;
Rhyme 0:774324cbc5a6 444 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 445 }
Rhyme 0:774324cbc5a6 446 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 447 an0 = new AnalogIn(PIN_AN0) ;
Rhyme 0:774324cbc5a6 448 smtc502at0 = new SMTC502AT(an0) ;
Rhyme 0:774324cbc5a6 449 an1 = new AnalogIn(PIN_AN1) ;
Rhyme 0:774324cbc5a6 450 smtc502at1 = new SMTC502AT(an1) ;
Rhyme 0:774324cbc5a6 451 temp = new edge_temp(lm75b0, smtc502at0, smtc502at1, lm75b1) ;
Rhyme 0:774324cbc5a6 452 sensor[SENSOR_ID_TEMP] = temp ;
Rhyme 0:774324cbc5a6 453 sensor[SENSOR_ID_TEMP]->setId(SENSOR_ID_TEMP) ;
Rhyme 0:774324cbc5a6 454 num_sensor++ ;
Rhyme 0:774324cbc5a6 455
Rhyme 0:774324cbc5a6 456
Rhyme 0:774324cbc5a6 457 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 458 an2 = new AnalogIn(PIN_AN2) ;
Rhyme 0:774324cbc5a6 459 pse530_en = new DigitalOut(PIN_PRESS_EN, 0) ;
Rhyme 0:774324cbc5a6 460 pse530 = new PSE530(an2) ;
Rhyme 0:774324cbc5a6 461 pressure = new edge_pressure(pse530, pse530_en) ;
Rhyme 0:774324cbc5a6 462 sensor[SENSOR_ID_PRESS] = pressure ;
Rhyme 0:774324cbc5a6 463 sensor[SENSOR_ID_PRESS]->setId(SENSOR_ID_PRESS) ;
Rhyme 0:774324cbc5a6 464 num_sensor++ ;
Rhyme 0:774324cbc5a6 465
Rhyme 0:774324cbc5a6 466 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 467 if (num_sensor > 0) {
Rhyme 0:774324cbc5a6 468 printf("%d edge_sensor(s) registered\n", num_sensor) ;
Rhyme 0:774324cbc5a6 469 printf("Edge is waiting for ASR to link\n") ;
Rhyme 0:774324cbc5a6 470 if (display) {
Rhyme 0:774324cbc5a6 471 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 472 display->foreground(White) ;
Rhyme 0:774324cbc5a6 473 display->locate(40, 200) ;
Rhyme 0:774324cbc5a6 474 display->printf("Waiting for ASR") ;
Rhyme 0:774324cbc5a6 475 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 476 }
Rhyme 0:774324cbc5a6 477 }
Rhyme 0:774324cbc5a6 478 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 479 }
Rhyme 0:774324cbc5a6 480
Rhyme 0:774324cbc5a6 481 void enable_sensors(void)
Rhyme 0:774324cbc5a6 482 {
Rhyme 0:774324cbc5a6 483 int i ;
Rhyme 0:774324cbc5a6 484 for (i = 0 ; i < NUM_MAX_SENSOR ; i++ ) {
Rhyme 0:774324cbc5a6 485 if (sensor[i]) {
Rhyme 0:774324cbc5a6 486 sensor[i]->enable() ;
Rhyme 0:774324cbc5a6 487 }
Rhyme 0:774324cbc5a6 488 }
Rhyme 0:774324cbc5a6 489 }
Rhyme 0:774324cbc5a6 490
Rhyme 0:774324cbc5a6 491 void disable_sensors(void)
Rhyme 0:774324cbc5a6 492 {
Rhyme 0:774324cbc5a6 493 int i ;
Rhyme 0:774324cbc5a6 494 for (i = 0 ; i < NUM_MAX_SENSOR ; i++ ) {
Rhyme 0:774324cbc5a6 495 if (sensor[i]) {
Rhyme 0:774324cbc5a6 496 sensor[i]->disable() ;
Rhyme 0:774324cbc5a6 497 }
Rhyme 0:774324cbc5a6 498 }
Rhyme 0:774324cbc5a6 499 }
Rhyme 0:774324cbc5a6 500
Rhyme 0:774324cbc5a6 501 void reboot_edge(void)
Rhyme 0:774324cbc5a6 502 {
Rhyme 0:774324cbc5a6 503 int i ;
Rhyme 0:774324cbc5a6 504 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 505 disable_sensors() ;
Rhyme 0:774324cbc5a6 506 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 507 if (display) {
Rhyme 0:774324cbc5a6 508 delete display ;
Rhyme 0:774324cbc5a6 509 display = 0 ;
Rhyme 0:774324cbc5a6 510 }
Rhyme 0:774324cbc5a6 511 for (i = 0 ; i < NUM_MAX_SENSOR ; i++ ) {
Rhyme 0:774324cbc5a6 512 if (sensor[i]) {
Rhyme 0:774324cbc5a6 513 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 514 delete sensor[i] ;
Rhyme 0:774324cbc5a6 515 sensor[i] = 0 ;
Rhyme 0:774324cbc5a6 516 }
Rhyme 0:774324cbc5a6 517 }
Rhyme 0:774324cbc5a6 518 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 519 software_reset() ;
Rhyme 0:774324cbc5a6 520 }