    * A2 - Temperature
    * D3 - Water Leak detector
  
-   Created 05-MAR-2015 by Jon Brule
+   Created 15-MAR-2015 by Jon Brule
 ----------------------------------------------------------------------------- */
 #include <avr/sleep.h>
 #include <avr/power.h>

}

//-----------------------------------------------------------------------------
// generates a sensor report, sending it to the RF gateway
void report() {    
    sensors->report(sensorData);
    
    memset(&outbound, 0, sizeof(outbound));
    outbound.msg.type = MSG_READING;
    outbound.msg.source = NODEID;
    outbound.msg.destination = 0;
    outbound.msg.component = 0;
    outbound.msg.rssi = 0;
    memcpy(&outbound.msg.data, sensorData, sizeof(*sensorData));
    
    #if DEBUG
        Serial.print("Broadcasting report to gateway...");
    #endif
    if (radio.sendWithRetry(GATEWAYID, outbound.raw, MSG_LENGTH)) {
        #if DEBUG
            Serial.println("ACK");
        #endif
    } else {
        #if DEBUG
            Serial.println("No ACK!");
        #endif
    }
}


// Main Loop
//
void loop () {
  if (f_timer == 1) {
    f_timer = 0;
    enterSleep();
  }   
}

//-----------------------------------------------------------------------------
// ISR - Water Leak
void waterLeak() {
  #if DEBUG
    Serial.println("WATER LEAK detcted!!!");
  #endif
  
  noInterrupts();
  digitalWrite(MOTE_LED_PIN, HIGH);        
  sensors->measure();
  report(MSG_ALERT, 1);
  digitalWrite(MOTE_LED_PIN, LOW);
  interrupts();  
}

//-----------------------------------------------------------------------------
// ISR - Sensor Measurement / Report
ISR(TIMER1_OVF_vect) {
  if (f_timer == 0) {
    f_timer = 1;
        
    noInterrupts();
    digitalWrite(MOTE_LED_PIN, HIGH);        
    sensors->measure();
    report(MSG_READING, 0);
    digitalWrite(MOTE_LED_PIN, LOW);
    interrupts();
  }
}

//-----------------------------------------------------------------------------
// Sleeps the microcontroller
void enterSleep(void) {
  set_sleep_mode(SLEEP_MODE_IDLE);
  
