diff --git a/master/master/config.h b/master/master/config.h --- a/master/master/config.h +++ b/master/master/config.h @@ -29,6 +29,13 @@ #define HEATER_THRESHOLD 60 +// Touchdown buzzer settings +#define BUZZER_RATE 3000 +#define BUZZER_DURATION 1 + +#define BUZZER_FAILSAFE_DURATION 600000 +#define BUZZER_TRIGGER_MINDURATION 1 +#define BUZZER_TRIGGER_MAXALTITUDE 1 // -------------------------------------------------------------------------- // Error Codes config (led.c, used throughout code) diff --git a/master/master/lib/led.c b/master/master/lib/led.c --- a/master/master/lib/led.c +++ b/master/master/lib/led.c @@ -43,7 +43,7 @@ void led_power_toggle() // Turn the specified LED on void led_on(uint8_t led) { - if(blackout && led != LED_ERROR) + if(blackout && led != LED_ERROR && led != LED_BUZZ) { return; } @@ -58,7 +58,7 @@ void led_off(uint8_t led) void led_toggle(uint8_t led) { - if(blackout && led != LED_ERROR) + if(blackout && led != LED_ERROR && led != LED_BUZZ) { return; } diff --git a/master/master/lib/sensordata.c b/master/master/lib/sensordata.c --- a/master/master/lib/sensordata.c +++ b/master/master/lib/sensordata.c @@ -204,4 +204,45 @@ void sensordata_logvalues() snprintf(logbuf + strlen(logbuf),CSV_LOGLINE_SIZE-strlen(logbuf),"\r\n"); logger_log(logbuf); } +} + +bool isTouchdown = false; +bool sensordata_isTouchdown() +{ + return isTouchdown; +} + +int32_t sensordata_getSensorValue(uint8_t sensorID) +{ + // Loop through all slaves + for(int i=0; i BUZZER_FAILSAFE_DURATION) + { + isTouchdown = true; + } + else + { + int32_t altitude = sensordata_getSensorValue(SENSOR_ALTITUDE); + if(altitude != -2111111111 && altitude < BUZZER_TRIGGER_MAXALTITUDE && time_millis() > BUZZER_TRIGGER_MINDURATION) + { + isTouchdown = true; + } + } } \ No newline at end of file diff --git a/master/master/lib/sensordata.h b/master/master/lib/sensordata.h --- a/master/master/lib/sensordata.h +++ b/master/master/lib/sensordata.h @@ -21,5 +21,7 @@ void sensordata_set(uint8_t nodeID, uint int32_t sensordata_get(uint8_t nodeID, uint8_t type); char* slavesensors_getAPRScomment(); void sensordata_logvalues(); +bool sensordata_isTouchdown(); +void sensordata_checkTouchdown(); #endif /* SENSORDATA_H_ */ \ No newline at end of file diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -64,6 +64,7 @@ int main(void) uint32_t lastLog = 0; uint32_t lastLedCycle = 0; uint32_t lastDataReq = 0; + uint32_t lastBuzz = 0; // Result of last parser run int parseResult = PARSERESULT_NODATA; @@ -73,7 +74,6 @@ int main(void) while(1) { - // Periodic: LED execution indicator if(time_millis() - lastLedCycle > LEDCYCLE_RATE) { @@ -113,11 +113,20 @@ int main(void) lastLog = time_millis(); } + // Periodic: Buzzer + if(time_millis() - lastBuzz > BUZZER_RATE) { + if(sensordata_isTouchdown()) + { + led_on(LED_BUZZ); + _delay_ms(BUZZER_DURATION); + led_off(LED_BUZZ); + } + lastBuzz = time_millis(); + } // Periodic: Data Request if(time_millis() - lastDataReq > DATAREQUEST_RATE) { - // Start getting values for next transmission if(slavesensors_isrequesting()) { @@ -135,6 +144,10 @@ int main(void) // Periodic: APRS transmission if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) { + // Check for touchdown + sensordata_checkTouchdown(); + + // LED blackout #ifdef BLACKOUT_ENABLE led_blackout(); #endif