From ff022fce0561bf4393799e4bb89a7ce4028cc78c Mon Sep 17 00:00:00 2001 From: harald42 Date: Wed, 23 Jan 2013 09:20:11 +0100 Subject: [PATCH] add battery sensor --- .../er-rest-example-dht11/er-example-server.c | 2 +- .../osd/er-rest-example-dht11/project-conf.h | 2 +- platform/osd-er-lp24/Makefile.osd-er-lp24 | 3 ++- platform/osd-er-lp24/dev/battery-sensor.c | 22 +++++++------------ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/examples/osd/er-rest-example-dht11/er-example-server.c b/examples/osd/er-rest-example-dht11/er-example-server.c index 051bc28ac..3eac87b8a 100644 --- a/examples/osd/er-rest-example-dht11/er-example-server.c +++ b/examples/osd/er-rest-example-dht11/er-example-server.c @@ -58,7 +58,7 @@ #define REST_RES_LEDS 0 #define REST_RES_TOGGLE 0 #define REST_RES_LIGHT 0 -#define REST_RES_BATTERY 0 +#define REST_RES_BATTERY 1 #define REST_RES_RADIO 0 diff --git a/examples/osd/er-rest-example-dht11/project-conf.h b/examples/osd/er-rest-example-dht11/project-conf.h index 76558fdd5..dcbd00805 100644 --- a/examples/osd/er-rest-example-dht11/project-conf.h +++ b/examples/osd/er-rest-example-dht11/project-conf.h @@ -36,7 +36,7 @@ //#define PLATFORM_HAS_BUTTON 1 //#define PLATFORM_HAS_LIGHT 1 #define PLATFORM_HAS_TEMPERATURE 1 -//#define PLATFORM_HAS_BATTERY 1 +#define PLATFORM_HAS_BATTERY 1 //#define PLATFORM_HAS_SHT11 1 #define SICSLOWPAN_CONF_FRAG 1 diff --git a/platform/osd-er-lp24/Makefile.osd-er-lp24 b/platform/osd-er-lp24/Makefile.osd-er-lp24 index 5f5f5fed6..dc7bdce5d 100644 --- a/platform/osd-er-lp24/Makefile.osd-er-lp24 +++ b/platform/osd-er-lp24/Makefile.osd-er-lp24 @@ -9,7 +9,8 @@ CONTIKI_TARGET_SOURCEFILES += temperature-sensor.c adc.c button-sensor.c sensors CONTIKI_TARGET_SOURCEFILES += dht11.c #Needed for DS18S20 temperature sensor CONTIKI_TARGET_SOURCEFILES += ds1820.c - +#Needed for Battery test +CONTIKI_TARGET_SOURCEFILES += battery-sensor.c CONTIKIAVR=$(CONTIKI)/cpu/avr CONTIKIBOARD=. BOOTLOADER_START = 0x1F000 diff --git a/platform/osd-er-lp24/dev/battery-sensor.c b/platform/osd-er-lp24/dev/battery-sensor.c index 495d39a1e..56837baa8 100644 --- a/platform/osd-er-lp24/dev/battery-sensor.c +++ b/platform/osd-er-lp24/dev/battery-sensor.c @@ -31,30 +31,23 @@ /** * \file -* Battery sensor header file for Atmega128rfa1. +* Battery sensor file for Atmega128rfa1. * \author * Paulo Louro * Harald Pichler */ -#include "dev/battery-sensor.h" -#include "adc.h" - -/* Connect Battery(+) to pin A1, via a 1000/470 voltage divider. -* This will case a battery voltage of 5.0V to read as the max analog -* voltage of 1.6V. -* -* Connect Battery(+) to pin A1, via a 1000/(470+470) voltage divider. -* This will case a battery voltage of 3.3V to read as the max analog -* voltage of 1.6V. +/** +*The atmel rf23x radios have a low voltage detector that can be configured in units of 75 millivolts. Here is example *code for the ATmega128rfa1, where the BATMON register is in extended io space [dak664] */ -#define INPUT_CHANNEL 1 + +#include "dev/battery-sensor.h" const struct sensors_sensor battery_sensor; /*---------------------------------------------------------------------------*/ /** -* \return Voltage on battery measurement pin, 4096 is 5V. +* \return Voltage on battery measurement with BATMON register. */ static int value(int type) @@ -67,11 +60,12 @@ value(int type) /* Use BATMON register instead */ for ( p1=16; p1<31; p1++) { BATMON = p1; - // delay_us(100); //delay needed? + clock_delay_usec(100); // delay needed !! if ((BATMON&(1<