Temporary Connector Reversed Version

Dependencies:   UniGraphic mbed vt100

afero_poc15_180403R , J1 のピン配置を反転させたヴァージョンです。

Color2系を使用するためには以下のピンをジャンパで接続してください。
J1-D7 <-> J1-D0
J1-D6 <-> J1-D1

(調査中) また、こちらでテストした範囲では、
FRDM-KL25Z の V3.3 を、Modulo2 の VCC_3V3 ピンに接続してやる必要がありました。

尚、J1-D1, D0 を使用するために UART を無効にしているため
ログは表示されません。

TFTモジュールについて 
aitendoのTFTモジュールはデフォルトでは8bit bus モードになっています。
/media/uploads/Rhyme/img_2364.jpg

半田のジャンパを変えて、SPIの設定にしてください。
/media/uploads/Rhyme/img_2363.jpg

サーミスタについて
POC1.5 では サーミスタは 25℃の時に抵抗値が 50.0kΩになる502AT-11 が
4.95kΩのプルアップ(実際は10kΩx2の並列)で使用されていました。

今回の試作では抵抗値が 10.0kΩの 103AT-11 が
5.1kΩのプルアップで使用されていますので、係数を合わせるために
SMTC502AT-11 のコンストラクタを 
R0 = 10.0
R1 = 5.1
B = 3435
T0 = 298.15
で呼ぶように変更しました。

Committer:
Rhyme
Date:
Tue Apr 24 12:18:10 2018 +0000
Revision:
1:6c54dc8acf96
Parent:
0:0b6732b53bf4
to adjust with 103AT-11 with 5.1k pull-up, the constructor of 502AT-11 is called with R0=10.0, R1=5.1, B=3435, T0=298.15

Who changed what in which revision?

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