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

Dependencies:   UniGraphic mbed vt100

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

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

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

/media/uploads/Rhyme/good.jpg

/media/uploads/Rhyme/high.jpg

moto

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

Who changed what in which revision?

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