39 #define SKETCH_VERSION "0.2"
52 #define MY_RF24_PA_LEVEL RF24_PA_HIGH
55 #define MY_GATEWAY_SERIAL
59 #define MY_BAUD_RATE 38400
63 #define MY_INCLUSION_MODE_FEATURE
65 #define MY_INCLUSION_BUTTON_FEATURE
71 #define MY_INCLUSION_MODE_DURATION 60
76 #define MY_DEFAULT_LED_BLINK_PERIOD 300
89 #include <drivers/ATSHA204/ATSHA204.cpp>
93 #define EEPROM_VERIFICATION_ADDRESS 0x01
95 static uint8_t num_of_leds = 5;
96 static uint8_t leds[] = {LED_BLUE, LED_RED, LED_GREEN, LED_YELLOW, LED_ORANGE};
117 pinMode(MY_SWC1, INPUT_PULLUP);
118 pinMode(MY_SWC2, INPUT_PULLUP);
119 if (digitalRead(MY_SWC1) && digitalRead(MY_SWC2)) {
125 for (
int i=0; i< num_of_leds; i++) {
126 pinMode(leds[i], OUTPUT);
128 if (digitalRead(MY_SWC1)) {
129 uint8_t led_state = 0;
131 digitalWrite(LED_BLUE, led_state);
136 digitalWrite(LED_BLUE,
LOW);
138 Serial.println(
"Sensebender GateWay test routine");
139 Serial.print(
"MySensors core version : ");
141 Serial.print(
"GateWay sketch version : ");
142 Serial.println(SKETCH_VERSION);
143 Serial.println(
"----------------------------------");
147 digitalWrite(LED_GREEN,
HIGH);
151 digitalWrite(LED_YELLOW,
HIGH);
156 digitalWrite(LED_ORANGE,
HIGH);
160 digitalWrite(LED_BLUE,
HIGH);
165 for (
int i=0; i<num_of_leds; i++) {
166 digitalWrite(leds[i],
HIGH);
168 digitalWrite(leds[i],
LOW);
173 digitalWrite(LED_RED,
HIGH);
175 digitalWrite(LED_RED,
LOW);
184 uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
187 Serial.print(
"- > SHA204 ");
190 ret_code = atsha204_wakeup(rx_buffer);
193 ret_code = atsha204_getSerialNumber(rx_buffer);
196 Serial.println(F(
"Failed to obtain device serial number. Response: "));
198 Serial.println(ret_code, HEX);
201 Serial.print(F(
"Ok (serial : "));
202 for (
int i=0; i<9; i++) {
203 if (rx_buffer[i] < 0x10) {
206 Serial.print(rx_buffer[i], HEX);
214 Serial.println(F(
"Failed to wakeup SHA204"));
223 Serial.print(
"- > SD CARD ");
225 if (!card.init(SPI_HALF_SPEED, MY_SDCARD_CS)) {
227 Serial.println(
"SD CARD did not initialize!");
231 Serial.print(
"SD Card initialized correct! - ");
232 Serial.print(
"type detected : ");
233 switch(card.type()) {
234 case SD_CARD_TYPE_SD1:
235 Serial.println(
"SD1");
237 case SD_CARD_TYPE_SD2:
238 Serial.println(
"SD2");
240 case SD_CARD_TYPE_SDHC:
241 Serial.println(
"SDHC");
244 Serial.println(
"Unknown");
254 uint8_t eeprom_d1, eeprom_d2;
255 SerialUSB.print(
" -> EEPROM ");
256 eeprom_d1 = hwReadConfig(EEPROM_VERIFICATION_ADDRESS);
258 eeprom_d1 = ~eeprom_d1;
259 hwWriteConfig(EEPROM_VERIFICATION_ADDRESS, eeprom_d1);
261 eeprom_d2 = hwReadConfig(EEPROM_VERIFICATION_ADDRESS);
262 if (eeprom_d1 == eeprom_d2) {
263 SerialUSB.println(
"PASSED");
264 hwWriteConfig(EEPROM_VERIFICATION_ADDRESS, ~eeprom_d1);
267 SerialUSB.println(
"FAILED!");
273 int bat_detect = analogRead(MY_BAT_DETECT);
274 Serial.print(
"-> analog : ");
275 Serial.print(bat_detect);
276 if (bat_detect < 400 || bat_detect > 650) {
277 Serial.println(
" Failed");
280 Serial.println(
" Passed");