39 #define SKETCH_VERSION "0.2"
51 #define MY_RF24_PA_LEVEL RF24_PA_HIGH
54 #define MY_GATEWAY_SERIAL
58 #define MY_BAUD_RATE 38400
62 #define MY_INCLUSION_MODE_FEATURE
64 #define MY_INCLUSION_BUTTON_FEATURE
70 #define MY_INCLUSION_MODE_DURATION 60
75 #define MY_DEFAULT_LED_BLINK_PERIOD 300
88 #include <drivers/ATSHA204/ATSHA204.cpp>
92 #define EEPROM_VERIFICATION_ADDRESS 0x01
94 static uint8_t num_of_leds = 5;
95 static uint8_t leds[] = {LED_BLUE, LED_RED, LED_GREEN, LED_YELLOW, LED_ORANGE};
116 pinMode(MY_SWC1, INPUT_PULLUP);
117 pinMode(MY_SWC2, INPUT_PULLUP);
118 if (digitalRead(MY_SWC1) && digitalRead(MY_SWC2)) {
124 for (
int i=0; i< num_of_leds; i++) {
125 pinMode(leds[i], OUTPUT);
127 if (digitalRead(MY_SWC1)) {
128 uint8_t led_state = 0;
130 digitalWrite(LED_BLUE, led_state);
135 digitalWrite(LED_BLUE,
LOW);
137 Serial.println(
"Sensebender GateWay test routine");
138 Serial.print(
"MySensors core version : ");
140 Serial.print(
"GateWay sketch version : ");
141 Serial.println(SKETCH_VERSION);
142 Serial.println(
"----------------------------------");
146 digitalWrite(LED_GREEN,
HIGH);
150 digitalWrite(LED_YELLOW,
HIGH);
155 digitalWrite(LED_ORANGE,
HIGH);
159 digitalWrite(LED_BLUE,
HIGH);
164 for (
int i=0; i<num_of_leds; i++) {
165 digitalWrite(leds[i],
HIGH);
167 digitalWrite(leds[i],
LOW);
172 digitalWrite(LED_RED,
HIGH);
174 digitalWrite(LED_RED,
LOW);
183 uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
186 Serial.print(
"- > SHA204 ");
189 ret_code = atsha204_wakeup(rx_buffer);
192 ret_code = atsha204_getSerialNumber(rx_buffer);
195 Serial.println(F(
"Failed to obtain device serial number. Response: "));
197 Serial.println(ret_code, HEX);
200 Serial.print(F(
"Ok (serial : "));
201 for (
int i=0; i<9; i++) {
202 if (rx_buffer[i] < 0x10) {
205 Serial.print(rx_buffer[i], HEX);
213 Serial.println(F(
"Failed to wakeup SHA204"));
222 Serial.print(
"- > SD CARD ");
224 if (!card.init(SPI_HALF_SPEED, MY_SDCARD_CS)) {
226 Serial.println(
"SD CARD did not initialize!");
230 Serial.print(
"SD Card initialized correct! - ");
231 Serial.print(
"type detected : ");
232 switch(card.type()) {
233 case SD_CARD_TYPE_SD1:
234 Serial.println(
"SD1");
236 case SD_CARD_TYPE_SD2:
237 Serial.println(
"SD2");
239 case SD_CARD_TYPE_SDHC:
240 Serial.println(
"SDHC");
243 Serial.println(
"Unknown");
253 uint8_t eeprom_d1, eeprom_d2;
254 SerialUSB.print(
" -> EEPROM ");
255 eeprom_d1 = hwReadConfig(EEPROM_VERIFICATION_ADDRESS);
257 eeprom_d1 = ~eeprom_d1;
258 hwWriteConfig(EEPROM_VERIFICATION_ADDRESS, eeprom_d1);
260 eeprom_d2 = hwReadConfig(EEPROM_VERIFICATION_ADDRESS);
261 if (eeprom_d1 == eeprom_d2) {
262 SerialUSB.println(
"PASSED");
263 hwWriteConfig(EEPROM_VERIFICATION_ADDRESS, ~eeprom_d1);
266 SerialUSB.println(
"FAILED!");
272 int bat_detect = analogRead(MY_BAT_DETECT);
273 Serial.print(
"-> analog : ");
274 Serial.print(bat_detect);
275 if (bat_detect < 400 || bat_detect > 650) {
276 Serial.println(
" Failed");
279 Serial.println(
" Passed");