[tuxdroid-svn] r527 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-18 10:07:54
|
Author: jaguarondi Date: 2007-09-18 12:07:49 +0200 (Tue, 18 Sep 2007) New Revision: 527 Modified: firmware/tuxcore/trunk/sensors.c firmware/tuxcore/trunk/sensors.h Log: * Updated the thresholds of the light level measurement to change from one resistance to the other. Now the result is sent each time even if the resistance has to change. * Cleanup and commenting. Modified: firmware/tuxcore/trunk/sensors.c =================================================================== --- firmware/tuxcore/trunk/sensors.c 2007-09-18 09:54:28 UTC (rev 526) +++ firmware/tuxcore/trunk/sensors.c 2007-09-18 10:07:49 UTC (rev 527) @@ -19,45 +19,59 @@ /* $Id$ */ +/** \file sensors.c + \brief Sensors module + \ingroup sensors +*/ + #include <avr/interrupt.h> -#include <avr/io.h> #include "global.h" #include "hardware.h" -/* - * ADC conversion complete. - * TODO add battery level measurement +/** + \brief ADC conversion interrupt handling light and battery level + + The light sensor has 2 different values of pull-up resistors (1M and 10k) to + increase the range. It's necessary to switch from one to the other resistor + depending on the light level. This is done here. + + \todo TODO add battery level measurement */ ISR(SIG_ADC) { - if ((ADCL == 0x00) && (ADCH == 0x00) && !(LIGHT_PU_PORT & LIGHT_PU_MK)) + /* Save light mode before changing it below. */ + gStatus.lightM = LIGHT_PU_PORT & LIGHT_PU_MK; + /* Check if it's necessary to change the light mode. */ + if ((ADCL <= 0x28) && (ADCH == 0x00) && !(LIGHT_PU_PORT & LIGHT_PU_MK)) { LIGHT_PU_PORT |= LIGHT_PU_MK; LIGHT_PU_DDR |= LIGHT_PU_MK; - ADCSRA |= _BV(ADSC); } - else if ((ADCL == 0xFF) && (ADCH == 0x03) && (LIGHT_PU_PORT & LIGHT_PU_MK)) + else if ((ADCL >= 0xE8) && (ADCH == 0x03) && (LIGHT_PU_PORT & LIGHT_PU_MK)) { LIGHT_PU_PORT &= ~LIGHT_PU_MK; LIGHT_PU_DDR &= ~LIGHT_PU_MK; - ADCSRA |= _BV(ADSC); } - else - { - gStatus.lightL = ADCL; - gStatus.lightH = ADCH; - gStatus.lightM = LIGHT_PU_PORT & LIGHT_PU_MK; - light_f = 1; - } + /* ADCH should be read after ADCL otherwise ADCL stays wite protected (c.f. + * datasheet). */ + gStatus.lightL = ADCL; + gStatus.lightH = ADCH; + /* There's a new light value. */ + light_f = 1; } /** - * \brief Get light level - * - * Start one conversion. The result will be saved by the ADC interrupt. + * \name Light level + * @{ */ +/** \ingroup sensors */ +/** + \brief Start a light level measurement. + + Start a light level conversion. The result will be saved by the ADC interrupt. */ void getLight(void) { ADCSRA |= _BV(ADSC); } +/*! @} */ Modified: firmware/tuxcore/trunk/sensors.h =================================================================== --- firmware/tuxcore/trunk/sensors.h 2007-09-18 09:54:28 UTC (rev 526) +++ firmware/tuxcore/trunk/sensors.h 2007-09-18 10:07:49 UTC (rev 527) @@ -19,14 +19,21 @@ /* $Id$ */ -#ifndef SENSORS_H -#define SENSORS_H +/** \file sensors.h + \brief Sensors module interface + \ingroup sensors +*/ +/** \defgroup sensors Sensors + + The sensor module handles light and battery level measurement. As both + measurements are done with the same ADC (and same interrupt), it was + difficult to separate them as different modules. +*/ + +#ifndef _SENSORS_H_ +#define _SENSORS_H_ + void getLight(void); -#define isLeftWing (gStatus.sw & GSTATUS_LEFTWINGBTN_MK) -#define isRightWing (gStatus.sw & GSTATUS_RIGHTWINGBTN_MK) -#define isPlugged (gStatus.sw & GSTATUS_POWERPLUGSW_MK) -#define isHead (gStatus.sw & GSTATUS_HEADBTN_MK) - -#endif +#endif /* _SENSORS_H_ */ |