From af1573ad3023e515e240229b41ed30a314cca1ef Mon Sep 17 00:00:00 2001
From: Andrew Tridgell <tridge@samba.org>
Date: Tue, 5 Jun 2012 11:31:40 +1000
Subject: [PATCH] ACM: prevent link flood with "Low Battery" warnings

thanks to Marco for noticing this
---
 ArduCopter/events.pde | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/ArduCopter/events.pde b/ArduCopter/events.pde
index bb090ef97..a235b0ef1 100644
--- a/ArduCopter/events.pde
+++ b/ArduCopter/events.pde
@@ -59,7 +59,15 @@ static void failsafe_off_event()
 
 static void low_battery_event(void)
 {
-	gcs_send_text_P(SEVERITY_HIGH,PSTR("Low Battery!"));
+    static uint32_t last_low_battery_message;
+    uint32_t tnow = millis();
+    if (((uint32_t)(tnow - last_low_battery_message)) > 5000) {
+        // only send this message at 5s intervals at most or we may
+        // flood the link
+        gcs_send_text_P(SEVERITY_LOW,PSTR("Low Battery!"));
+        last_low_battery_message = tnow;
+    }
+
 	low_batt = true;
 
 	// if we are in Auto mode, come home
-- 
GitLab