diff --git a/WeatherStation.ino b/WeatherStation.ino index a314ddf..f098fe5 100644 --- a/WeatherStation.ino +++ b/WeatherStation.ino @@ -19,15 +19,26 @@ #include "hidwh1080rptparser.h" +#define XBEE_SLEEP 2 +#define MAX_RESET 7 //MAX3421E pin 12 +#define MAX_GPX 8 //MAX3421E pin 17 + USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); WH1080ReportParser parser; -void setup() +void startUsb() { - Serial.begin( 9600 ); + // Set up reset and GPX ports -- USB Host library seems to be missing this, + // see https://github.com/watterott/KnowledgeBase/wiki/SparkFun-USB-Host-Shield + pinMode(MAX_GPX, INPUT); + pinMode(MAX_RESET, OUTPUT); + digitalWrite(MAX_RESET, LOW); + delay(20); //wait 20ms + digitalWrite(MAX_RESET, HIGH); + delay(20); //wait 20ms if (Usb.Init() == -1) Serial.println("{\"error\":\"OSC did not start.\"}"); @@ -38,6 +49,15 @@ ErrorMessage(PSTR("SetReportParser"), 1 ); } +void setup() +{ + Serial.begin( 9600 ); + pinMode(XBEE_SLEEP, OUTPUT); // XBee sleep pin (DTR) + digitalWrite(XBEE_SLEEP, LOW); // ensure awake + + startUsb(); +} + void loop() { Usb.Task(); @@ -47,8 +67,14 @@ Serial.print("{\"error\":\"Rcode = "); Serial.print(rcode, HEX); Serial.println("\"}"); + parser.startDelay = millis() + 5000; + } else { + parser.startDelay = 0; } - parser.startDelay = 0; } +/* if ((parser.lastMillis + 60000) < millis()) { + parser.lastMillis = millis(); + startUsb(); + } */ } diff --git a/hidwh1080rptparser.cpp b/hidwh1080rptparser.cpp index 6a35644..77629d8 100644 --- a/hidwh1080rptparser.cpp +++ b/hidwh1080rptparser.cpp @@ -17,7 +17,9 @@ } else { if (memcmp(chunk, lastChunk, WH1080_BUFFER_CHUNK) != 0) { memcpy(lastChunk, chunk, WH1080_BUFFER_CHUNK); - //Serial.print("Time since last change: "); + // wake up XBee +/* digitalWrite(2, LOW); + delay(1000); */ Serial.print("{\"period\":"); Serial.print(millis() - lastMillis); lastMillis = millis(); @@ -44,6 +46,8 @@ Serial.print(",\"status\":"); Serial.print(chunk[WH1080_STATUS], HEX); Serial.println("}"); +/* delay(5000); + digitalWrite(2, HIGH); // put XBee to sleep */ } readingBlockZero = true; report[1] = 0; diff --git a/hidwh1080rptparser.h b/hidwh1080rptparser.h index 4618f65..26c686c 100644 --- a/hidwh1080rptparser.h +++ b/hidwh1080rptparser.h @@ -59,11 +59,11 @@ uint8_t chunkStart; bool readingBlockZero; unsigned short currentPos; - unsigned long lastMillis; public: unsigned long startDelay; + unsigned long lastMillis; uint8_t report[8]; WH1080ReportParser() {