Gas Pressure Display Updated Power control for Pressure sensor added

Dependencies:   UniGraphic mbed vt100

Committer:
Rhyme
Date:
Fri Feb 16 08:27:50 2018 +0000
Revision:
0:37c8ecde13c2
control PSE530 power via PTC5 (pse530_en)

Who changed what in which revision?

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