From ec70e87495249c5a51a89f235e50ba145a89b468 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jul 2012 19:56:12 +1000 Subject: [PATCH] AnalogSource: prevent a division by zero on zero ADC data --- libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp b/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp index 66a16c904e..8c426684c6 100644 --- a/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp +++ b/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp @@ -94,7 +94,11 @@ uint16_t AP_AnalogSource_Arduino::read_raw(void) // scaled read for board Vcc uint16_t AP_AnalogSource_Arduino::read_vcc(void) { - return 1126400UL / read_raw(); + uint16_t v = read_raw(); + if (v == 0) { + return 0; + } + return 1126400UL / v; } // read the average 16 bit value since the last