From 78af52083b589aa3754a9645cf6173fc15e4aaf7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 Nov 2011 15:48:52 +1100 Subject: [PATCH] desktop: fixed ADC value for airspeed --- libraries/Desktop/support/sitl_adc.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/Desktop/support/sitl_adc.h b/libraries/Desktop/support/sitl_adc.h index 68a26fe5c9..ac18dd1e34 100644 --- a/libraries/Desktop/support/sitl_adc.h +++ b/libraries/Desktop/support/sitl_adc.h @@ -36,6 +36,9 @@ struct ADC_UDR2 { case 0xB7: next_value = channels[6]; break; case 0xF7: next_value = channels[7]; break; } + if (cmd != 0) { + idx = 1; + } return *this; } @@ -43,13 +46,15 @@ struct ADC_UDR2 { read from UDR2 fetches a byte from the channel */ operator int() { - switch (idx) { - case 0: idx++; return(value>>8); - case 1: idx++; return(value&0xFF); + uint8_t ret; + if (idx & 1) { + ret = (value&0xFF); + value = next_value; + } else { + ret = (value>>8); } - value = next_value; - idx=0; - return(value>>8); + idx ^= 1; + return ret; } /*