Temporary Connector Reversed Version

Dependencies:   UniGraphic mbed vt100

afero_poc15_180403R , J1 のピン配置を反転させたヴァージョンです。

Color2系を使用するためには以下のピンをジャンパで接続してください。
J1-D7 <-> J1-D0
J1-D6 <-> J1-D1

(調査中) また、こちらでテストした範囲では、
FRDM-KL25Z の V3.3 を、Modulo2 の VCC_3V3 ピンに接続してやる必要がありました。

尚、J1-D1, D0 を使用するために UART を無効にしているため
ログは表示されません。

TFTモジュールについて 
aitendoのTFTモジュールはデフォルトでは8bit bus モードになっています。
/media/uploads/Rhyme/img_2364.jpg

半田のジャンパを変えて、SPIの設定にしてください。
/media/uploads/Rhyme/img_2363.jpg

サーミスタについて
POC1.5 では サーミスタは 25℃の時に抵抗値が 50.0kΩになる502AT-11 が
4.95kΩのプルアップ(実際は10kΩx2の並列)で使用されていました。

今回の試作では抵抗値が 10.0kΩの 103AT-11 が
5.1kΩのプルアップで使用されていますので、係数を合わせるために
SMTC502AT-11 のコンストラクタを 
R0 = 10.0
R1 = 5.1
B = 3435
T0 = 298.15
で呼ぶように変更しました。

Committer:
Rhyme
Date:
Tue Apr 24 12:18:10 2018 +0000
Revision:
1:6c54dc8acf96
Parent:
0:0b6732b53bf4
to adjust with 103AT-11 with 5.1k pull-up, the constructor of 502AT-11 is called with R0=10.0, R1=5.1, B=3435, T0=298.15

Who changed what in which revision?

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