Color sensor reset at the end of calibration added. sensor id auto assignment was changed to be a fixed value assignment to avoid sensor id shift when some sensor is absent.

Dependencies:   UniGraphic mbed vt100

Committer:
Rhyme
Date:
Fri Feb 23 05:40:22 2018 +0000
Revision:
0:ce97f6d34336
color sensor reset was added at the end of calibration

Who changed what in which revision?

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