I2C hang recover function added

Dependencies:   UniGraphic mbed vt100

In this version, check_i2c_pins function was added in edge_mgr.cpp.

プログラムの起動時、I2Cモジュールを初期化する前に、I2Cに使用するピンの電位を確認し
もし一方でも Low に張り付いていた場合、SCL を GPIO 出力に設定して 
所定回数 (I2C_UNLOCK_TRIAL_CYCLE) 反転させることにより、疑似リセットクロックを生成します。

その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。

Committer:
Rhyme
Date:
Tue Apr 03 08:30:29 2018 +0000
Revision:
0:d895cd1cd897
Initial I2C Pin force reset function added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:d895cd1cd897 1 #include "mbed.h"
Rhyme 0:d895cd1cd897 2 #include <ctype.h>
Rhyme 0:d895cd1cd897 3 #include "af_attributes.h"
Rhyme 0:d895cd1cd897 4 #include "edge_time.h"
Rhyme 0:d895cd1cd897 5 #include "edge_sensor.h"
Rhyme 0:d895cd1cd897 6 #include "edge_accel.h"
Rhyme 0:d895cd1cd897 7 #include "edge_color.h"
Rhyme 0:d895cd1cd897 8 #include "edge_temp.h"
Rhyme 0:d895cd1cd897 9 #include "edge_pressure.h"
Rhyme 0:d895cd1cd897 10 #include "edge_mgr.h"
Rhyme 0:d895cd1cd897 11 #include "edge_reset_mgr.h"
Rhyme 0:d895cd1cd897 12 // #include "SO1602A.h"
Rhyme 0:d895cd1cd897 13 #include <ILI9341.h>
Rhyme 0:d895cd1cd897 14 #include "pending.h"
Rhyme 0:d895cd1cd897 15
Rhyme 0:d895cd1cd897 16 // extern SO1602A *display ;
Rhyme 0:d895cd1cd897 17 extern ILI9341 *display ;
Rhyme 0:d895cd1cd897 18 extern pending_class *pending ;
Rhyme 0:d895cd1cd897 19
Rhyme 0:d895cd1cd897 20 static const af_attribute_type af_attr[] = {
Rhyme 0:d895cd1cd897 21 /* ID, Description, Type, Size */
Rhyme 0:d895cd1cd897 22 { ATTR_SENSE_VAL, "Sensor Value", ATTRIBUTE_TYPE_UTF8S, 255 },
Rhyme 0:d895cd1cd897 23 { ATTR_ACCEL_PRESENT, "Accel Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 24 { ATTR_ACCEL_ENABLE, "Accel Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 25 { ATTR_ACCEL_INTERVAL, "Accel Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 26 { ATTR_ACCEL_VALUE, "Accel Value", ATTRIBUTE_TYPE_FIXED_15_16, 4},
Rhyme 0:d895cd1cd897 27 /* first color sensor (VEML6040) and LED set */
Rhyme 0:d895cd1cd897 28 { ATTR_COLOR0_PRESENT, "Color1 Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 29 { ATTR_COLOR0_ENABLE, "Color1 Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 30 { ATTR_COLOR0_INTERVAL, "Color1 Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 31 { ATTR_COLOR0_TRIGMODE, "Color1 Trigger Mode", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 32 { ATTR_COLOR0_ITIME, "Color1 Integration Time", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 33 { ATTR_COLOR0_CALIBRATE, "Color1 Calibrate", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 34 { ATTR_COLOR0_PWM_R, "Color1 PWM R", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:d895cd1cd897 35 { ATTR_COLOR0_PWM_G, "Color1 PWM G", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:d895cd1cd897 36 { ATTR_COLOR0_PWM_B, "Color1 PWM B", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:d895cd1cd897 37 { ATTR_COLOR0_PWM_PERIOD, "Color1 PWM Period", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 38 { ATTR_COLOR0_PWM_TARGET, "Color1 PWM Target", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 39 { ATTR_COLOR0_R_VALUE, "Color1 R", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 40 { ATTR_COLOR0_G_VALUE, "Color1 G", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 41 { ATTR_COLOR0_B_VALUE, "Color1 B", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 42 /* second color sensor (VEML6040) and LED set */
Rhyme 0:d895cd1cd897 43 { ATTR_COLOR1_PRESENT, "Color2 Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 44 { ATTR_COLOR1_ENABLE, "Color2 Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 45 { ATTR_COLOR1_INTERVAL, "Color2 Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 46 { ATTR_COLOR1_TRIGMODE, "Color2 Trigger Mode", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 47 { ATTR_COLOR1_ITIME, "Color2 Integration Time", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 48 { ATTR_COLOR1_CALIBRATE, "Color2 Calibrate", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 49 { ATTR_COLOR1_PWM_R, "Color2 PWM R", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:d895cd1cd897 50 { ATTR_COLOR1_PWM_G, "Color2 PWM G", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:d895cd1cd897 51 { ATTR_COLOR1_PWM_B, "Color2 PWM B", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:d895cd1cd897 52 { ATTR_COLOR1_PWM_PERIOD, "Color2 PWM Period", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 53 { ATTR_COLOR1_PWM_TARGET, "Color2 PWM Target", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 54 { ATTR_COLOR1_R_VALUE, "Color2 R", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 55 { ATTR_COLOR1_G_VALUE, "Color2 G", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 56 { ATTR_COLOR1_B_VALUE, "Color2 B", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 57 /* first temperature sensor (LM75B) */
Rhyme 0:d895cd1cd897 58 { ATTR_TEMP0_PRESENT, "Temp0 Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 59 { ATTR_TEMP0_ENABLE, "Temp0 Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 60 { ATTR_TEMP0_INTERVAL, "Temp0 Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 61 { ATTR_TEMP0_VALUE, "Temp0 Value", ATTRIBUTE_TYPE_FIXED_15_16, 4},
Rhyme 0:d895cd1cd897 62 /* second temperature sensor (SMTC502AT/Before) */
Rhyme 0:d895cd1cd897 63 { ATTR_TEMP1_PRESENT, "Temp1 Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 64 { ATTR_TEMP1_ENABLE, "Temp1 Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 65 { ATTR_TEMP1_INTERVAL, "Temp1 Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 66 { ATTR_TEMP1_VALUE, "Temp1 Value", ATTRIBUTE_TYPE_FIXED_15_16, 4},
Rhyme 0:d895cd1cd897 67 /* third temperature sensor (SMTC502AT/After) */
Rhyme 0:d895cd1cd897 68 { ATTR_TEMP2_PRESENT, "Temp2 Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 69 { ATTR_TEMP2_ENABLE, "Temp2 Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 70 { ATTR_TEMP2_INTERVAL, "Temp2 Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 71 { ATTR_TEMP2_VALUE, "Temp2 Value", ATTRIBUTE_TYPE_FIXED_15_16, 4},
Rhyme 0:d895cd1cd897 72 /* fouth temperateure sensor (LM75B) */
Rhyme 0:d895cd1cd897 73 { ATTR_TEMP3_PRESENT, "Temp3 Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 74 { ATTR_TEMP3_ENABLE, "Temp3 Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 75 { ATTR_TEMP3_INTERVAL, "Temp3 Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 76 { ATTR_TEMP3_VALUE, "Temp3 Value", ATTRIBUTE_TYPE_FIXED_15_16, 4},
Rhyme 0:d895cd1cd897 77 /* Gas Pressure sensor (PSE530) */
Rhyme 0:d895cd1cd897 78 { ATTR_GAS_PRESENT, "Gas Pressure Present", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 79 { ATTR_GAS_ENABLE, "Gas Pressure Enable", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 80 { ATTR_GAS_INTERVAL, "Gas Pressure Interval", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 81 { ATTR_GAS_VALUE, "Gas Pressure Value", ATTRIBUTE_TYPE_FIXED_15_16, 4},
Rhyme 0:d895cd1cd897 82 { ATTR_GAS_THR_MODE, "Gas Press Threshold Mode", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 83 { ATTR_GAS_THR_HIGH, "Gas Press High Thresh", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 84 { ATTR_GAS_THR_LOW, "Gas Press Low Thresh", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 85 /* Software Reset Request */
Rhyme 0:d895cd1cd897 86 { ATTR_SOFTWARE_RESET, "Software Reset", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:d895cd1cd897 87 { ATTR_DISPLAY_MODE, "Display Mode", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 88 { ATTR_MCU_RESET_REASON, "MCU Reset Reason", ATTRIBUTE_TYPE_UTF8S, 64 },
Rhyme 0:d895cd1cd897 89
Rhyme 0:d895cd1cd897 90 { ATTR_LED, "LED", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 91 { ATTR_IO0, "I/O 0", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 92 { ATTR_IO1, "I/O 1", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 93 { ATTR_IO2, "I/O 2", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 94 { ATTR_BUTTON, "BUTTON", ATTRIBUTE_TYPE_BOOLEAN, 2 },
Rhyme 0:d895cd1cd897 95 { ATTR_IO3, "I/O 3", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 96 { ATTR_BOOT_LOADER_VER, "Bootloader Version", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 97 { ATTR_BLE_STACK_VER, "BLE Stack Version", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 98 { ATTR_FW_APP_VER, "FW Application Version", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 99 { ATTR_DEVICE_DESC, "Device Description", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 100 { ATTR_WIFI_VER, "Wi-Fi chip", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:d895cd1cd897 101 { ATTR_OFFLINE_SCHED, "Offline Schedules enable", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:d895cd1cd897 102 { ATTR_SECURITY_ENABLED, "Security Enabled", ATTRIBUTE_TYPE_SINT8, 1 }, /* ? */
Rhyme 0:d895cd1cd897 103 { ATTR_UTC_OFFSET, "UTC offset data", ATTRIBUTE_TYPE_BYTES, 8 },
Rhyme 0:d895cd1cd897 104 { ATTR_CONFIGURES_SSID, "Configured SSID", ATTRIBUTE_TYPE_UTF8S, 10 }, /* ? */
Rhyme 0:d895cd1cd897 105 { ATTR_WIFI_BARS, "Wi-Fi Bars", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 106 { ATTR_WIFI_STDY_STATE, "Wi-Fi Steady State", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 107 { ATTR_COMMAND, "Command", ATTRIBUTE_TYPE_BYTES, 8 }, /* ? */
Rhyme 0:d895cd1cd897 108 { ATTR_ASR_STATE, "ASR State", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 109 { ATTR_LOW_BATTERY, "Low Battery Warning", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 110 { ATTR_LINKED_TIMESTAMP, "Linked Timestamp", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:d895cd1cd897 111 { ATTR_ATTR_ACK, "Attribute ACK", ATTRIBUTE_TYPE_SINT16, 8 },
Rhyme 0:d895cd1cd897 112 { ATTR_REBOOT_REASON, "Reboot Reason", ATTRIBUTE_TYPE_UTF8S, 100 },
Rhyme 0:d895cd1cd897 113 { ATTR_BLE_COMMS, "BLE Comms", ATTRIBUTE_TYPE_BYTES, 12 },
Rhyme 0:d895cd1cd897 114 { ATTR_MCU_INTERFACE, "MCU Interface", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:d895cd1cd897 115 { 0, 0, 0, 0 }
Rhyme 0:d895cd1cd897 116 } ;
Rhyme 0:d895cd1cd897 117
Rhyme 0:d895cd1cd897 118 int get_af_attr(uint16_t id)
Rhyme 0:d895cd1cd897 119 {
Rhyme 0:d895cd1cd897 120 int i ;
Rhyme 0:d895cd1cd897 121 for (i = 0 ; af_attr[i].id != 0 ; i++ ) {
Rhyme 0:d895cd1cd897 122 if (id == af_attr[i].id) {
Rhyme 0:d895cd1cd897 123 break ;
Rhyme 0:d895cd1cd897 124 }
Rhyme 0:d895cd1cd897 125 }
Rhyme 0:d895cd1cd897 126 return (i) ;
Rhyme 0:d895cd1cd897 127 }
Rhyme 0:d895cd1cd897 128
Rhyme 0:d895cd1cd897 129 void print_af_error(int resultCode)
Rhyme 0:d895cd1cd897 130 {
Rhyme 0:d895cd1cd897 131 switch(resultCode) {
Rhyme 0:d895cd1cd897 132 case afSUCCESS:
Rhyme 0:d895cd1cd897 133 printf("Operation completed successfully\n") ;
Rhyme 0:d895cd1cd897 134 break ;
Rhyme 0:d895cd1cd897 135 case afERROR_NO_SUCH_ATTRIBUTE:
Rhyme 0:d895cd1cd897 136 printf("Request was made for unknown attribute id\n") ;
Rhyme 0:d895cd1cd897 137 break ;
Rhyme 0:d895cd1cd897 138 case afERROR_BUSY:
Rhyme 0:d895cd1cd897 139 printf("Request already in progress, try again\n") ;
Rhyme 0:d895cd1cd897 140 break ;
Rhyme 0:d895cd1cd897 141 case afERROR_INVALID_COMMAND:
Rhyme 0:d895cd1cd897 142 printf("Command could not be parsed\n") ;
Rhyme 0:d895cd1cd897 143 break ;
Rhyme 0:d895cd1cd897 144 case afERROR_QUEUE_OVERFLOW:
Rhyme 0:d895cd1cd897 145 printf("Queue is full\n") ;
Rhyme 0:d895cd1cd897 146 break ;
Rhyme 0:d895cd1cd897 147 case afERROR_QUEUE_UNDERFLOW:
Rhyme 0:d895cd1cd897 148 printf("Queue is empty\n") ;
Rhyme 0:d895cd1cd897 149 break ;
Rhyme 0:d895cd1cd897 150 case afERROR_INVALID_PARAM:
Rhyme 0:d895cd1cd897 151 printf("Bad input parameter\n") ;
Rhyme 0:d895cd1cd897 152 break ;
Rhyme 0:d895cd1cd897 153 default:
Rhyme 0:d895cd1cd897 154 printf("Unknown error code %d\n", resultCode) ;
Rhyme 0:d895cd1cd897 155 break ;
Rhyme 0:d895cd1cd897 156 }
Rhyme 0:d895cd1cd897 157 }
Rhyme 0:d895cd1cd897 158
Rhyme 0:d895cd1cd897 159 void af_print_values(
Rhyme 0:d895cd1cd897 160 const uint8_t requestId,
Rhyme 0:d895cd1cd897 161 const uint16_t attributeId,
Rhyme 0:d895cd1cd897 162 const uint16_t valueLen,
Rhyme 0:d895cd1cd897 163 const uint8_t *value
Rhyme 0:d895cd1cd897 164 )
Rhyme 0:d895cd1cd897 165 {
Rhyme 0:d895cd1cd897 166 int i, id ;
Rhyme 0:d895cd1cd897 167
Rhyme 0:d895cd1cd897 168 id = get_af_attr(attributeId) ;
Rhyme 0:d895cd1cd897 169
Rhyme 0:d895cd1cd897 170 if (af_attr[id].id != 0) {
Rhyme 0:d895cd1cd897 171 printf(af_attr[id].description) ;
Rhyme 0:d895cd1cd897 172 printf(" : ") ;
Rhyme 0:d895cd1cd897 173 switch(af_attr[id].attribute_type) {
Rhyme 0:d895cd1cd897 174 case ATTRIBUTE_TYPE_BOOLEAN:
Rhyme 0:d895cd1cd897 175 case ATTRIBUTE_TYPE_SINT8:
Rhyme 0:d895cd1cd897 176 if (valueLen >= 1) {
Rhyme 0:d895cd1cd897 177 printf("%02X\n", value[0]) ;
Rhyme 0:d895cd1cd897 178 }
Rhyme 0:d895cd1cd897 179 break ;
Rhyme 0:d895cd1cd897 180 case ATTRIBUTE_TYPE_SINT16:
Rhyme 0:d895cd1cd897 181 if (valueLen >= 2) {
Rhyme 0:d895cd1cd897 182 printf("%02X%02X\n", value[1], value[0]) ;
Rhyme 0:d895cd1cd897 183 }
Rhyme 0:d895cd1cd897 184 break ;
Rhyme 0:d895cd1cd897 185 case ATTRIBUTE_TYPE_SINT32:
Rhyme 0:d895cd1cd897 186 if (valueLen >= 4) {
Rhyme 0:d895cd1cd897 187 printf("%02X%02X%02X%02X\n",
Rhyme 0:d895cd1cd897 188 value[3],value[2],value[1],value[0]) ;
Rhyme 0:d895cd1cd897 189 }
Rhyme 0:d895cd1cd897 190 break ;
Rhyme 0:d895cd1cd897 191 case ATTRIBUTE_TYPE_SINT64:
Rhyme 0:d895cd1cd897 192 if (valueLen >= 8) {
Rhyme 0:d895cd1cd897 193 printf("%02X%02X %02X%02X %02X%02X %02X%02X\n",
Rhyme 0:d895cd1cd897 194 value[7], value[6], value[5], value[4],
Rhyme 0:d895cd1cd897 195 value[3], value[2], value[1], value[0]) ;
Rhyme 0:d895cd1cd897 196 }
Rhyme 0:d895cd1cd897 197 break ;
Rhyme 0:d895cd1cd897 198 case ATTRIBUTE_TYPE_UTF8S:
Rhyme 0:d895cd1cd897 199 if (valueLen > 0) {
Rhyme 0:d895cd1cd897 200 for (i = 0 ; i < valueLen ; i++) {
Rhyme 0:d895cd1cd897 201 if (isprint(value[i])) {
Rhyme 0:d895cd1cd897 202 printf("%c", value[i]) ;
Rhyme 0:d895cd1cd897 203 } else if (value[i] == 0) { /* string terminator NULL */
Rhyme 0:d895cd1cd897 204 break ;
Rhyme 0:d895cd1cd897 205 } else {
Rhyme 0:d895cd1cd897 206 printf("\'%02X\'",value[i]) ;
Rhyme 0:d895cd1cd897 207 }
Rhyme 0:d895cd1cd897 208 }
Rhyme 0:d895cd1cd897 209 printf("\n") ;
Rhyme 0:d895cd1cd897 210 }
Rhyme 0:d895cd1cd897 211 break ;
Rhyme 0:d895cd1cd897 212 case ATTRIBUTE_TYPE_BYTES:
Rhyme 0:d895cd1cd897 213 default:
Rhyme 0:d895cd1cd897 214 if (valueLen > 0) {
Rhyme 0:d895cd1cd897 215 for (i = 0 ; i < valueLen ; i++ ) {
Rhyme 0:d895cd1cd897 216 printf("%02X ", value[i]) ;
Rhyme 0:d895cd1cd897 217 }
Rhyme 0:d895cd1cd897 218 printf("\n") ;
Rhyme 0:d895cd1cd897 219 }
Rhyme 0:d895cd1cd897 220 break ;
Rhyme 0:d895cd1cd897 221 }
Rhyme 0:d895cd1cd897 222 } else {
Rhyme 0:d895cd1cd897 223 if (valueLen > 0) {
Rhyme 0:d895cd1cd897 224 for (i = 0 ; i < valueLen ; i++ ) {
Rhyme 0:d895cd1cd897 225 printf("%02X ", value[i]) ;
Rhyme 0:d895cd1cd897 226 }
Rhyme 0:d895cd1cd897 227 printf("\n") ;
Rhyme 0:d895cd1cd897 228 }
Rhyme 0:d895cd1cd897 229 }
Rhyme 0:d895cd1cd897 230 // printf("\n") ;
Rhyme 0:d895cd1cd897 231 }
Rhyme 0:d895cd1cd897 232
Rhyme 0:d895cd1cd897 233 void assignAttribute(
Rhyme 0:d895cd1cd897 234 const uint8_t requestId,
Rhyme 0:d895cd1cd897 235 const uint16_t attributeId,
Rhyme 0:d895cd1cd897 236 const uint16_t valueLen,
Rhyme 0:d895cd1cd897 237 const uint8_t *value,
Rhyme 0:d895cd1cd897 238 bool fromRequest
Rhyme 0:d895cd1cd897 239 )
Rhyme 0:d895cd1cd897 240 {
Rhyme 0:d895cd1cd897 241 switch(attributeId) {
Rhyme 0:d895cd1cd897 242 case ATTR_LINKED_TIMESTAMP: /* timestamp */
Rhyme 0:d895cd1cd897 243 set_time(valueLen, value) ; /* 68 us */
Rhyme 0:d895cd1cd897 244 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 245 printf("timestampe = ") ;
Rhyme 0:d895cd1cd897 246 print_date_wd(&current_time) ;
Rhyme 0:d895cd1cd897 247 // print_time(&current_time) ;
Rhyme 0:d895cd1cd897 248 printf("\n") ;
Rhyme 0:d895cd1cd897 249 break ;
Rhyme 0:d895cd1cd897 250 case ATTR_SOFTWARE_RESET: /* software reset requested! */
Rhyme 0:d895cd1cd897 251 if (value[0]) {
Rhyme 0:d895cd1cd897 252 reset_watch_dog() ;
Rhyme 0:d895cd1cd897 253 printf("Software Reset Requested!\n") ;
Rhyme 0:d895cd1cd897 254 if (display != 0) {
Rhyme 0:d895cd1cd897 255 display->cls() ;
Rhyme 0:d895cd1cd897 256 display->locate(0,0) ;
Rhyme 0:d895cd1cd897 257 display->printf("System Rebooting!") ;
Rhyme 0:d895cd1cd897 258 }
Rhyme 0:d895cd1cd897 259 reset_watch_dog() ;
Rhyme 0:d895cd1cd897 260 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 261 wait(0.5) ;
Rhyme 0:d895cd1cd897 262 reset_watch_dog() ;
Rhyme 0:d895cd1cd897 263 reboot_edge() ;
Rhyme 0:d895cd1cd897 264 }
Rhyme 0:d895cd1cd897 265 break ;
Rhyme 0:d895cd1cd897 266 case ATTR_DISPLAY_MODE:
Rhyme 0:d895cd1cd897 267 if (display_mode != value[0]) {
Rhyme 0:d895cd1cd897 268 display_mode = value[0] ;
Rhyme 0:d895cd1cd897 269 if (display) {
Rhyme 0:d895cd1cd897 270 display->BusEnable(true) ;
Rhyme 0:d895cd1cd897 271 display->cls() ;
Rhyme 0:d895cd1cd897 272 display->BusEnable(false) ;
Rhyme 0:d895cd1cd897 273 }
Rhyme 0:d895cd1cd897 274 }
Rhyme 0:d895cd1cd897 275 reset_watch_dog() ;
Rhyme 0:d895cd1cd897 276 switch(value[0]) {
Rhyme 0:d895cd1cd897 277 case DISPLAY_MODE_GAS: /* gas pressure monitor only */
Rhyme 0:d895cd1cd897 278 break ;
Rhyme 0:d895cd1cd897 279 case DISPLAY_MODE_SUMMARY: /* summary */
Rhyme 0:d895cd1cd897 280 break ;
Rhyme 0:d895cd1cd897 281 case DISPLAY_MODE_CHART: /* chart mode */
Rhyme 0:d895cd1cd897 282 if (display) {
Rhyme 0:d895cd1cd897 283 draw_all_chart_frame() ;
Rhyme 0:d895cd1cd897 284 }
Rhyme 0:d895cd1cd897 285 break ;
Rhyme 0:d895cd1cd897 286 case DISPLAY_MODE_OFF: /* display off */
Rhyme 0:d895cd1cd897 287 default:
Rhyme 0:d895cd1cd897 288 display_mode = DISPLAY_MODE_OFF ;
Rhyme 0:d895cd1cd897 289 break ;
Rhyme 0:d895cd1cd897 290 }
Rhyme 0:d895cd1cd897 291 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 292 break ;
Rhyme 0:d895cd1cd897 293 case ATTR_ACCEL_ENABLE: /* accel enable */
Rhyme 0:d895cd1cd897 294 if (sensor[SENSOR_ID_ACCEL]) {
Rhyme 0:d895cd1cd897 295 if (value[0]) {
Rhyme 0:d895cd1cd897 296 sensor[SENSOR_ID_ACCEL]->reset() ;
Rhyme 0:d895cd1cd897 297 sensor[SENSOR_ID_ACCEL]->enable() ;
Rhyme 0:d895cd1cd897 298 } else if (sensor[SENSOR_ID_ACCEL]){
Rhyme 0:d895cd1cd897 299 sensor[SENSOR_ID_ACCEL]->disable() ;
Rhyme 0:d895cd1cd897 300 }
Rhyme 0:d895cd1cd897 301 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 302 }
Rhyme 0:d895cd1cd897 303 break ;
Rhyme 0:d895cd1cd897 304 case ATTR_ACCEL_INTERVAL:
Rhyme 0:d895cd1cd897 305 if (sensor[SENSOR_ID_ACCEL]) {
Rhyme 0:d895cd1cd897 306 sensor[SENSOR_ID_ACCEL]->setInterval((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 307 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 308 }
Rhyme 0:d895cd1cd897 309 break ;
Rhyme 0:d895cd1cd897 310 case ATTR_COLOR0_ENABLE: /* color0 enable */
Rhyme 0:d895cd1cd897 311 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 312 if (value[0]) {
Rhyme 0:d895cd1cd897 313 sensor[SENSOR_ID_COLOR1]->reset() ;
Rhyme 0:d895cd1cd897 314 sensor[SENSOR_ID_COLOR1]->enable() ;
Rhyme 0:d895cd1cd897 315 } else {
Rhyme 0:d895cd1cd897 316 sensor[SENSOR_ID_COLOR1]->disable() ;
Rhyme 0:d895cd1cd897 317 }
Rhyme 0:d895cd1cd897 318 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 319 }
Rhyme 0:d895cd1cd897 320 break ;
Rhyme 0:d895cd1cd897 321 case ATTR_COLOR0_INTERVAL:
Rhyme 0:d895cd1cd897 322 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 323 sensor[SENSOR_ID_COLOR1]->setInterval((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 324 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 325 }
Rhyme 0:d895cd1cd897 326 break ;
Rhyme 0:d895cd1cd897 327 case ATTR_COLOR0_TRIGMODE: /* color0 config */
Rhyme 0:d895cd1cd897 328 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 329 uint8_t config = ((edge_color*)sensor[SENSOR_ID_COLOR1])->getConfig() & 0x70 ;
Rhyme 0:d895cd1cd897 330 if (value[0]) {
Rhyme 0:d895cd1cd897 331 config = config | 0x06 ;
Rhyme 0:d895cd1cd897 332 }
Rhyme 0:d895cd1cd897 333 ((edge_color*)sensor[SENSOR_ID_COLOR1])->setConfig(config) ;
Rhyme 0:d895cd1cd897 334 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 335 }
Rhyme 0:d895cd1cd897 336 break ;
Rhyme 0:d895cd1cd897 337 case ATTR_COLOR0_ITIME: /* color0 config */
Rhyme 0:d895cd1cd897 338 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 339 uint8_t config = ((edge_color*)sensor[SENSOR_ID_COLOR1])->getConfig() & 0x07 ;
Rhyme 0:d895cd1cd897 340 config = (value[0] << 4) | config ;
Rhyme 0:d895cd1cd897 341 ((edge_color*)sensor[SENSOR_ID_COLOR1])->setConfig(config) ;
Rhyme 0:d895cd1cd897 342 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 343 }
Rhyme 0:d895cd1cd897 344 break ;
Rhyme 0:d895cd1cd897 345 case ATTR_COLOR0_PWM_PERIOD: /* color0 pwm period */
Rhyme 0:d895cd1cd897 346 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 347 ((edge_color*)sensor[SENSOR_ID_COLOR1])->set_pwm_period((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 348 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 349 }
Rhyme 0:d895cd1cd897 350 break ;
Rhyme 0:d895cd1cd897 351 case ATTR_COLOR0_PWM_TARGET: /* color0 pwm calibration target */
Rhyme 0:d895cd1cd897 352 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 353 color0_target[0] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 354 color0_target[1] = color0_target[0] ;
Rhyme 0:d895cd1cd897 355 color0_target[2] = color0_target[1] ;
Rhyme 0:d895cd1cd897 356 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 357 }
Rhyme 0:d895cd1cd897 358 break ;
Rhyme 0:d895cd1cd897 359 #if 1 /* do not handle calibration twice */
Rhyme 0:d895cd1cd897 360 case ATTR_COLOR0_CALIBRATE: /* calibrate color0 */
Rhyme 0:d895cd1cd897 361 if (sensor[SENSOR_ID_COLOR1] && value[0] && fromRequest) { /* do calibration */
Rhyme 0:d895cd1cd897 362 ((edge_color*)sensor[SENSOR_ID_COLOR1])->request_calibration() ;
Rhyme 0:d895cd1cd897 363 }
Rhyme 0:d895cd1cd897 364 break ;
Rhyme 0:d895cd1cd897 365 #endif
Rhyme 0:d895cd1cd897 366 case ATTR_COLOR0_PWM_R:
Rhyme 0:d895cd1cd897 367 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 368 ((edge_color*)sensor[SENSOR_ID_COLOR1])->setPwmR( (value[1] << 8) | value[0] ) ;
Rhyme 0:d895cd1cd897 369 // color0_pwm[0] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 370 }
Rhyme 0:d895cd1cd897 371 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 372 break ;
Rhyme 0:d895cd1cd897 373 case ATTR_COLOR0_PWM_G:
Rhyme 0:d895cd1cd897 374 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 375 ((edge_color*)sensor[SENSOR_ID_COLOR1])->setPwmG( (value[1] << 8) | value[0] ) ;
Rhyme 0:d895cd1cd897 376 // color0_pwm[1] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 377 }
Rhyme 0:d895cd1cd897 378 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 379 break ;
Rhyme 0:d895cd1cd897 380 case ATTR_COLOR0_PWM_B:
Rhyme 0:d895cd1cd897 381 if (sensor[SENSOR_ID_COLOR1]) {
Rhyme 0:d895cd1cd897 382 ((edge_color*)sensor[SENSOR_ID_COLOR1])->setPwmB( (value[1] << 8) | value[0] ) ;
Rhyme 0:d895cd1cd897 383 // color0_pwm[2] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 384 }
Rhyme 0:d895cd1cd897 385 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 386 break ;
Rhyme 0:d895cd1cd897 387 case ATTR_COLOR1_ENABLE: /* color1 enable */
Rhyme 0:d895cd1cd897 388 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 389 if (value[0]) {
Rhyme 0:d895cd1cd897 390 sensor[SENSOR_ID_COLOR2]->reset() ;
Rhyme 0:d895cd1cd897 391 sensor[SENSOR_ID_COLOR2]->enable() ;
Rhyme 0:d895cd1cd897 392 } else {
Rhyme 0:d895cd1cd897 393 sensor[SENSOR_ID_COLOR2]->disable() ;
Rhyme 0:d895cd1cd897 394 }
Rhyme 0:d895cd1cd897 395 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 396 }
Rhyme 0:d895cd1cd897 397 break ;
Rhyme 0:d895cd1cd897 398 case ATTR_COLOR1_INTERVAL:
Rhyme 0:d895cd1cd897 399 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 400 sensor[SENSOR_ID_COLOR2]->setInterval((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 401 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 402 }
Rhyme 0:d895cd1cd897 403 break ;
Rhyme 0:d895cd1cd897 404 case ATTR_COLOR1_TRIGMODE: /* color0 config */
Rhyme 0:d895cd1cd897 405 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 406 uint8_t config = ((edge_color*)sensor[SENSOR_ID_COLOR2])->getConfig() & 0x70 ;
Rhyme 0:d895cd1cd897 407 if (value[0]) {
Rhyme 0:d895cd1cd897 408 config = config | 0x06 ;
Rhyme 0:d895cd1cd897 409 }
Rhyme 0:d895cd1cd897 410 ((edge_color*)sensor[SENSOR_ID_COLOR2])->setConfig(config) ;
Rhyme 0:d895cd1cd897 411 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 412 }
Rhyme 0:d895cd1cd897 413 break ;
Rhyme 0:d895cd1cd897 414 case ATTR_COLOR1_ITIME: /* color0 config */
Rhyme 0:d895cd1cd897 415 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 416 uint8_t config = ((edge_color*)sensor[SENSOR_ID_COLOR2])->getConfig() & 0x07 ;
Rhyme 0:d895cd1cd897 417 config = (value[0] << 4) | config ;
Rhyme 0:d895cd1cd897 418 ((edge_color*)sensor[SENSOR_ID_COLOR2])->setConfig(config) ;
Rhyme 0:d895cd1cd897 419 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 420 }
Rhyme 0:d895cd1cd897 421 break ;
Rhyme 0:d895cd1cd897 422 case ATTR_COLOR1_PWM_PERIOD: /* color0 pwm period */
Rhyme 0:d895cd1cd897 423 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 424 ((edge_color*)sensor[SENSOR_ID_COLOR2])->set_pwm_period((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 425 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 426 }
Rhyme 0:d895cd1cd897 427 break ;
Rhyme 0:d895cd1cd897 428 case ATTR_COLOR1_PWM_TARGET: /* color0 pwm calibration target */
Rhyme 0:d895cd1cd897 429 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 430 color1_target[0] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 431 color1_target[1] = color1_target[0] ;
Rhyme 0:d895cd1cd897 432 color1_target[2] = color1_target[1] ;
Rhyme 0:d895cd1cd897 433 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 434 }
Rhyme 0:d895cd1cd897 435 break ;
Rhyme 0:d895cd1cd897 436 #if 1 /* do not handle calibration twice */
Rhyme 0:d895cd1cd897 437 case ATTR_COLOR1_CALIBRATE: /* calibrate color1 */
Rhyme 0:d895cd1cd897 438 if (sensor[SENSOR_ID_COLOR2] && value[0] && fromRequest) { /* do calibration! */
Rhyme 0:d895cd1cd897 439 ((edge_color*)sensor[SENSOR_ID_COLOR2])->request_calibration() ;
Rhyme 0:d895cd1cd897 440 }
Rhyme 0:d895cd1cd897 441 break ;
Rhyme 0:d895cd1cd897 442 #endif
Rhyme 0:d895cd1cd897 443 case ATTR_COLOR1_PWM_R:
Rhyme 0:d895cd1cd897 444 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 445 ((edge_color*)sensor[SENSOR_ID_COLOR2])->setPwmR( (value[1] << 8) | value[0] ) ;
Rhyme 0:d895cd1cd897 446 // color1_pwm[0] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 447 }
Rhyme 0:d895cd1cd897 448 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 449 break ;
Rhyme 0:d895cd1cd897 450 case ATTR_COLOR1_PWM_G:
Rhyme 0:d895cd1cd897 451 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 452 ((edge_color*)sensor[SENSOR_ID_COLOR2])->setPwmG( (value[1] << 8) | value[0] ) ;
Rhyme 0:d895cd1cd897 453 // color1_pwm[1] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 454 }
Rhyme 0:d895cd1cd897 455 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 456 break ;
Rhyme 0:d895cd1cd897 457 case ATTR_COLOR1_PWM_B:
Rhyme 0:d895cd1cd897 458 if (sensor[SENSOR_ID_COLOR2]) {
Rhyme 0:d895cd1cd897 459 ((edge_color*)sensor[SENSOR_ID_COLOR2])->setPwmB( (value[1] << 8) | value[0] ) ;
Rhyme 0:d895cd1cd897 460 // color1_pwm[2] = (value[1] << 8) | value[0] ;
Rhyme 0:d895cd1cd897 461 }
Rhyme 0:d895cd1cd897 462 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 463 break ;
Rhyme 0:d895cd1cd897 464 case ATTR_TEMP0_ENABLE: /* temp0 is used to control temp-sensors */
Rhyme 0:d895cd1cd897 465 if (sensor[SENSOR_ID_TEMP]) {
Rhyme 0:d895cd1cd897 466 if (value[0]) {
Rhyme 0:d895cd1cd897 467 sensor[SENSOR_ID_TEMP]->reset() ;
Rhyme 0:d895cd1cd897 468 sensor[SENSOR_ID_TEMP]->enable() ;
Rhyme 0:d895cd1cd897 469 } else {
Rhyme 0:d895cd1cd897 470 sensor[SENSOR_ID_TEMP]->disable() ;
Rhyme 0:d895cd1cd897 471 }
Rhyme 0:d895cd1cd897 472 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 473 }
Rhyme 0:d895cd1cd897 474 break ;
Rhyme 0:d895cd1cd897 475 case ATTR_TEMP0_INTERVAL:
Rhyme 0:d895cd1cd897 476 if (sensor[SENSOR_ID_TEMP]) {
Rhyme 0:d895cd1cd897 477 sensor[SENSOR_ID_TEMP]->setInterval((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 478 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 479 }
Rhyme 0:d895cd1cd897 480 break ;
Rhyme 0:d895cd1cd897 481 case ATTR_TEMP3_ENABLE: /* temp3 enable */
Rhyme 0:d895cd1cd897 482 break ;
Rhyme 0:d895cd1cd897 483 case ATTR_GAS_ENABLE: /* pressure enable */
Rhyme 0:d895cd1cd897 484 if (sensor[SENSOR_ID_PRESS]) {
Rhyme 0:d895cd1cd897 485 if (value[0]) {
Rhyme 0:d895cd1cd897 486 sensor[SENSOR_ID_PRESS]->reset() ;
Rhyme 0:d895cd1cd897 487 sensor[SENSOR_ID_PRESS]->enable() ;
Rhyme 0:d895cd1cd897 488 } else {
Rhyme 0:d895cd1cd897 489 sensor[SENSOR_ID_PRESS]->disable() ;
Rhyme 0:d895cd1cd897 490 }
Rhyme 0:d895cd1cd897 491 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 492 }
Rhyme 0:d895cd1cd897 493 break ;
Rhyme 0:d895cd1cd897 494 case ATTR_GAS_INTERVAL:
Rhyme 0:d895cd1cd897 495 if (sensor[SENSOR_ID_PRESS]) {
Rhyme 0:d895cd1cd897 496 sensor[SENSOR_ID_PRESS]->setInterval((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 497 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 498 }
Rhyme 0:d895cd1cd897 499 break ;
Rhyme 0:d895cd1cd897 500 case ATTR_GAS_THR_MODE:
Rhyme 0:d895cd1cd897 501 if (sensor[SENSOR_ID_PRESS]) {
Rhyme 0:d895cd1cd897 502 ((edge_pressure*)sensor[SENSOR_ID_PRESS])->set_thr_mode(value[0]) ;
Rhyme 0:d895cd1cd897 503 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 504 }
Rhyme 0:d895cd1cd897 505 break ;
Rhyme 0:d895cd1cd897 506 case ATTR_GAS_THR_HIGH:
Rhyme 0:d895cd1cd897 507 if (sensor[SENSOR_ID_PRESS]) {
Rhyme 0:d895cd1cd897 508 ((edge_pressure*)sensor[SENSOR_ID_PRESS])->set_thr_high((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 509 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 510 }
Rhyme 0:d895cd1cd897 511 break ;
Rhyme 0:d895cd1cd897 512 case ATTR_GAS_THR_LOW:
Rhyme 0:d895cd1cd897 513 if (sensor[SENSOR_ID_PRESS]) {
Rhyme 0:d895cd1cd897 514 ((edge_pressure*)sensor[SENSOR_ID_PRESS])->set_thr_low((value[1] << 8) | value[0]) ;
Rhyme 0:d895cd1cd897 515 if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 516 }
Rhyme 0:d895cd1cd897 517 break ;
Rhyme 0:d895cd1cd897 518 default:
Rhyme 0:d895cd1cd897 519 break ;
Rhyme 0:d895cd1cd897 520 }
Rhyme 0:d895cd1cd897 521 }
Rhyme 0:d895cd1cd897 522
Rhyme 0:d895cd1cd897 523 /*
Rhyme 0:d895cd1cd897 524 * Callback that allows ASR to request an MCU attribute be changed.
Rhyme 0:d895cd1cd897 525 * You should define this function in your MCU firmware to perform application-specific actions
Rhyme 0:d895cd1cd897 526 * your code must take (e.g., updating the state of the hardware),
Rhyme 0:d895cd1cd897 527 * in light of the attribute value change.
Rhyme 0:d895cd1cd897 528 */
Rhyme 0:d895cd1cd897 529 void attributeChangeRequest(
Rhyme 0:d895cd1cd897 530 const uint8_t requestId,
Rhyme 0:d895cd1cd897 531 const uint16_t attributeId,
Rhyme 0:d895cd1cd897 532 const uint16_t valueLen,
Rhyme 0:d895cd1cd897 533 const uint8_t *value
Rhyme 0:d895cd1cd897 534 )
Rhyme 0:d895cd1cd897 535 {
Rhyme 0:d895cd1cd897 536 uint32_t timestamp = edge_time ;
Rhyme 0:d895cd1cd897 537 if ((pending != 0)&&(pending->request->requestId == requestId)) {
Rhyme 0:d895cd1cd897 538 pending->replied_time = timestamp ;
Rhyme 0:d895cd1cd897 539
Rhyme 0:d895cd1cd897 540 }
Rhyme 0:d895cd1cd897 541 ts2time(timestamp, &current_time) ; /* 12 us */
Rhyme 0:d895cd1cd897 542 if (verbos) {
Rhyme 0:d895cd1cd897 543 print_time(&current_time) ;
Rhyme 0:d895cd1cd897 544 printf(" %5d ASR requested [%d] : ", attributeId, requestId) ;
Rhyme 0:d895cd1cd897 545 af_print_values(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 546 }
Rhyme 0:d895cd1cd897 547
Rhyme 0:d895cd1cd897 548 assignAttribute(requestId, attributeId, valueLen, value, true) ;
Rhyme 0:d895cd1cd897 549
Rhyme 0:d895cd1cd897 550 // af_print_values(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 551 if ((pending != 0)&&(pending->request->requestId == requestId)) {
Rhyme 0:d895cd1cd897 552 printf("Request [%d] replied in %d sec!\n", requestId, pending->replied_time - pending->submit_time) ;
Rhyme 0:d895cd1cd897 553 delete pending ;
Rhyme 0:d895cd1cd897 554 pending = 0 ;
Rhyme 0:d895cd1cd897 555 }
Rhyme 0:d895cd1cd897 556 }
Rhyme 0:d895cd1cd897 557
Rhyme 0:d895cd1cd897 558 /*
Rhyme 0:d895cd1cd897 559 * Application callback that allows afLib to notify that an attribute has changed.
Rhyme 0:d895cd1cd897 560 * This method will be called in response to a getAttribute call from the application
Rhyme 0:d895cd1cd897 561 * and whenever a ASR module attribute changes.
Rhyme 0:d895cd1cd897 562 */
Rhyme 0:d895cd1cd897 563 void attributeUpdatedReport(
Rhyme 0:d895cd1cd897 564 const uint8_t requestId,
Rhyme 0:d895cd1cd897 565 const uint16_t attributeId,
Rhyme 0:d895cd1cd897 566 const uint16_t valueLen,
Rhyme 0:d895cd1cd897 567 const uint8_t *value
Rhyme 0:d895cd1cd897 568 )
Rhyme 0:d895cd1cd897 569 {
Rhyme 0:d895cd1cd897 570 uint32_t timestamp = edge_time ;
Rhyme 0:d895cd1cd897 571 int result ;
Rhyme 0:d895cd1cd897 572 if ((pending != 0)&&(pending->request->requestId == requestId)) {
Rhyme 0:d895cd1cd897 573 pending->replied_time = timestamp ;
Rhyme 0:d895cd1cd897 574 }
Rhyme 0:d895cd1cd897 575 ts2time(timestamp, &current_time) ; /* 12us */
Rhyme 0:d895cd1cd897 576 if (verbos) {
Rhyme 0:d895cd1cd897 577 print_time(&current_time) ;
Rhyme 0:d895cd1cd897 578 printf(" %5d ASR reported [%d]: ", attributeId, requestId) ;
Rhyme 0:d895cd1cd897 579 af_print_values(requestId, attributeId, valueLen, value) ;
Rhyme 0:d895cd1cd897 580 }
Rhyme 0:d895cd1cd897 581
Rhyme 0:d895cd1cd897 582 switch(attributeId) {
Rhyme 0:d895cd1cd897 583 case ATTR_LINKED_TIMESTAMP:
Rhyme 0:d895cd1cd897 584 set_time(valueLen, value) ; /* 68 us */
Rhyme 0:d895cd1cd897 585 printf("timestampe = ") ;
Rhyme 0:d895cd1cd897 586 print_date_wd(&current_time) ;
Rhyme 0:d895cd1cd897 587 // print_time(&current_time) ;
Rhyme 0:d895cd1cd897 588 printf("\n") ;
Rhyme 0:d895cd1cd897 589 break ;
Rhyme 0:d895cd1cd897 590 case ATTR_WIFI_STDY_STATE:
Rhyme 0:d895cd1cd897 591 gConnected = false ;
Rhyme 0:d895cd1cd897 592 printf("WiFi Steady State: ") ;
Rhyme 0:d895cd1cd897 593 switch(value[0]) {
Rhyme 0:d895cd1cd897 594 case 0: printf("Not Connected\n") ; break ;
Rhyme 0:d895cd1cd897 595 case 1: printf("Pending\n") ; break ;
Rhyme 0:d895cd1cd897 596 case 2:
Rhyme 0:d895cd1cd897 597 printf("Connected\n") ;
Rhyme 0:d895cd1cd897 598 gConnected = true ; // the only case Connected state is OK
Rhyme 0:d895cd1cd897 599 break ;
Rhyme 0:d895cd1cd897 600 case 3: printf("Unknown Failure\n") ; break ;
Rhyme 0:d895cd1cd897 601 case 4: printf("Association Failed\n") ; break ;
Rhyme 0:d895cd1cd897 602 case 5: printf("Handshake Failed\n") ; break ;
Rhyme 0:d895cd1cd897 603 case 6: printf("Echo Failed\n") ; break ;
Rhyme 0:d895cd1cd897 604 case 7: printf("SSID Not Found\n") ; break ;
Rhyme 0:d895cd1cd897 605 case 8: printf("NTP Failed\n") ; break ;
Rhyme 0:d895cd1cd897 606 default: printf("Unknown [%d]\n", value[0]) ; break ;
Rhyme 0:d895cd1cd897 607 }
Rhyme 0:d895cd1cd897 608 break ;
Rhyme 0:d895cd1cd897 609 case ATTR_REBOOT_REASON:
Rhyme 0:d895cd1cd897 610 printf("Reboot Reason: ") ;
Rhyme 0:d895cd1cd897 611 switch(value[0]) {
Rhyme 0:d895cd1cd897 612 case 1: printf("Reset pin asserted\n") ; break ;
Rhyme 0:d895cd1cd897 613 case 2: printf("Watchdog reset\n") ; break ;
Rhyme 0:d895cd1cd897 614 case 4: printf("Software reset\n") ; break ;
Rhyme 0:d895cd1cd897 615 case 8: printf("CPU Lock up\n") ; break ;
Rhyme 0:d895cd1cd897 616 default: printf("Unknown [%d]\n", value[0]) ; break ;
Rhyme 0:d895cd1cd897 617 }
Rhyme 0:d895cd1cd897 618 if (reboot_requested) {
Rhyme 0:d895cd1cd897 619 printf("Unexpected ASR Reboot. Rebooting MCU.\n") ;
Rhyme 0:d895cd1cd897 620 wait_ms(100) ;
Rhyme 0:d895cd1cd897 621 reboot_edge() ;
Rhyme 0:d895cd1cd897 622 }
Rhyme 0:d895cd1cd897 623 break ;
Rhyme 0:d895cd1cd897 624 case ATTR_MCU_INTERFACE:
Rhyme 0:d895cd1cd897 625 printf("MCU Interface: ") ;
Rhyme 0:d895cd1cd897 626 switch(value[0]) {
Rhyme 0:d895cd1cd897 627 case 0: printf("No MCU\n") ; break ;
Rhyme 0:d895cd1cd897 628 case 1: printf("SPI Slave\n") ; break ;
Rhyme 0:d895cd1cd897 629 case 2: printf("UART\n") ; break ;
Rhyme 0:d895cd1cd897 630 default: printf("Unknown\n") ; break ;
Rhyme 0:d895cd1cd897 631 }
Rhyme 0:d895cd1cd897 632 break ;
Rhyme 0:d895cd1cd897 633 case AF_SYSTEM_ASR_STATE:
Rhyme 0:d895cd1cd897 634 printf("ASR state: ") ;
Rhyme 0:d895cd1cd897 635 switch(value[0]) {
Rhyme 0:d895cd1cd897 636 case MODULE_STATE_REBOOTED:
Rhyme 0:d895cd1cd897 637 gLinked = false ;
Rhyme 0:d895cd1cd897 638 printf("Rebooted\n") ;
Rhyme 0:d895cd1cd897 639 // wait_ms(100) ; /* */
Rhyme 0:d895cd1cd897 640 if (edge_mgr_status == EDGE_MGR_RUNNING) {
Rhyme 0:d895cd1cd897 641 result = afero->getAttribute(ATTR_REBOOT_REASON) ;
Rhyme 0:d895cd1cd897 642 reboot_requested = true ;
Rhyme 0:d895cd1cd897 643 // reboot_edge() ;
Rhyme 0:d895cd1cd897 644 }
Rhyme 0:d895cd1cd897 645 break ;
Rhyme 0:d895cd1cd897 646 case MODULE_STATE_LINKED:
Rhyme 0:d895cd1cd897 647 if (gLinked == false) { /* new link established */
Rhyme 0:d895cd1cd897 648 result = afero->getAttribute(ATTR_LINKED_TIMESTAMP) ;
Rhyme 0:d895cd1cd897 649 if (result != afSUCCESS) {
Rhyme 0:d895cd1cd897 650 printf("getAttriute for ATTR_LINKED_TIMESTAMP failed\n") ;
Rhyme 0:d895cd1cd897 651 }
Rhyme 0:d895cd1cd897 652 }
Rhyme 0:d895cd1cd897 653 gLinked = true ;
Rhyme 0:d895cd1cd897 654 printf("Linked\n") ;
Rhyme 0:d895cd1cd897 655 break ;
Rhyme 0:d895cd1cd897 656 case MODULE_STATE_UPDATING:
Rhyme 0:d895cd1cd897 657 gLinked = true ;
Rhyme 0:d895cd1cd897 658 printf("Updating\n") ;
Rhyme 0:d895cd1cd897 659 if (display) {
Rhyme 0:d895cd1cd897 660 display->cls() ;
Rhyme 0:d895cd1cd897 661 display->locate(5, 5) ;
Rhyme 0:d895cd1cd897 662 display->printf("FW Updating...") ;
Rhyme 0:d895cd1cd897 663 }
Rhyme 0:d895cd1cd897 664 break ;
Rhyme 0:d895cd1cd897 665 case MOUDLE_STATE_UPDATE_READY:
Rhyme 0:d895cd1cd897 666 gLinked = false ;
Rhyme 0:d895cd1cd897 667 printf("Update ready - rebooting\n") ;
Rhyme 0:d895cd1cd897 668 if (display) {
Rhyme 0:d895cd1cd897 669 display->cls() ;
Rhyme 0:d895cd1cd897 670 display->locate(5, 5) ;
Rhyme 0:d895cd1cd897 671 display->printf("Rebooting...") ;
Rhyme 0:d895cd1cd897 672 }
Rhyme 0:d895cd1cd897 673 while(afero->setAttribute32(AF_SYSTEM_COMMAND, MODULE_COMMAND_REBOOT) != afSUCCESS) {
Rhyme 0:d895cd1cd897 674 afero->loop() ;
Rhyme 0:d895cd1cd897 675 wait_us(100) ;
Rhyme 0:d895cd1cd897 676 }
Rhyme 0:d895cd1cd897 677 reboot_edge() ;
Rhyme 0:d895cd1cd897 678 break ;
Rhyme 0:d895cd1cd897 679 default:
Rhyme 0:d895cd1cd897 680 break ;
Rhyme 0:d895cd1cd897 681 }
Rhyme 0:d895cd1cd897 682 break ;
Rhyme 0:d895cd1cd897 683 default:
Rhyme 0:d895cd1cd897 684 assignAttribute(requestId, attributeId, valueLen, value, false) ;
Rhyme 0:d895cd1cd897 685 break ;
Rhyme 0:d895cd1cd897 686 }
Rhyme 0:d895cd1cd897 687 if ((pending != 0)&&(pending->request->requestId == requestId)) {
Rhyme 0:d895cd1cd897 688 printf("Request [%d] replied in %d sec!\n", requestId, pending->replied_time - pending->submit_time) ;
Rhyme 0:d895cd1cd897 689 delete pending ;
Rhyme 0:d895cd1cd897 690 pending = 0 ;
Rhyme 0:d895cd1cd897 691 }
Rhyme 0:d895cd1cd897 692 }