Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)

Dependencies:   UniGraphic mbed vt100

18-Jun-2018 外部センサの電源オン・オフ機能は下位互換の為に無効になっていました。 この版で再度有効にしました。

Committer:
Rhyme
Date:
Fri Apr 13 04:19:23 2018 +0000
Revision:
0:846e2321c637
power to color sensor on/off test OK. Currently the function is disabled.

Who changed what in which revision?

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