From cead1c7ce0a452133519dd9c09ecc5aae1314cd4 Mon Sep 17 00:00:00 2001 From: Harald Pichler Date: Tue, 20 Aug 2013 13:34:01 +0200 Subject: [PATCH] use batmon in battery_sensor --- platform/osd-merkur/Makefile.osd-merkur | 2 +- platform/osd-merkur/dev/batmon.c | 10 +++++----- platform/osd-merkur/dev/battery-sensor.c | 14 +++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/platform/osd-merkur/Makefile.osd-merkur b/platform/osd-merkur/Makefile.osd-merkur index e5e47d7f4..cf862b1af 100644 --- a/platform/osd-merkur/Makefile.osd-merkur +++ b/platform/osd-merkur/Makefile.osd-merkur @@ -12,7 +12,7 @@ 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 +CONTIKI_TARGET_SOURCEFILES += battery-sensor.c batmon.c #Needed for PIR CONTIKI_TARGET_SOURCEFILES += pir-sensor.c #Needed for OPTRIAC diff --git a/platform/osd-merkur/dev/batmon.c b/platform/osd-merkur/dev/batmon.c index 6ff0c135b..5c61d125f 100644 --- a/platform/osd-merkur/dev/batmon.c +++ b/platform/osd-merkur/dev/batmon.c @@ -17,10 +17,10 @@ int8_t batmon_get_voltage(uint16_t* voltage) uint16_t offset = 2550; int8_t ctr = 0; - BATMON = 0 | BV(BATMON_HR); + BATMON = 0 | _BV(BATMON_HR); _delay_us(2); - if(BATMON & BV(BATMON_OK)) + if(BATMON & _BV(BATMON_OK)) { // voltage above 2.550 V resolution = 75; @@ -29,7 +29,7 @@ int8_t batmon_get_voltage(uint16_t* voltage) { BATMON = (BATMON & 0xF0) | (ctr); _delay_us(2); - if(BATMON & BV(BATMON_OK)) break; + if(BATMON & _BV(BATMON_OK)) break; } } else @@ -38,13 +38,13 @@ int8_t batmon_get_voltage(uint16_t* voltage) resolution = 50; offset = 1700; - BATMON &= ~BV(BATMON_HR); + BATMON &= ~_BV(BATMON_HR); for(ctr=15; ctr>=0; ctr--) { BATMON = (BATMON & 0xF0) | (ctr); _delay_us(2); - if(BATMON & BV(BATMON_OK)) break; + if(BATMON & _BV(BATMON_OK)) break; } } diff --git a/platform/osd-merkur/dev/battery-sensor.c b/platform/osd-merkur/dev/battery-sensor.c index 56837baa8..1eb7906b4 100644 --- a/platform/osd-merkur/dev/battery-sensor.c +++ b/platform/osd-merkur/dev/battery-sensor.c @@ -42,6 +42,7 @@ */ #include "dev/battery-sensor.h" +#include "dev/batmon.h" const struct sensors_sensor battery_sensor; /*---------------------------------------------------------------------------*/ @@ -52,20 +53,22 @@ const struct sensors_sensor battery_sensor; static int value(int type) { + uint16_t h; +/* uint8_t p1; BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage -/* Bandgap can't be measured against supply voltage in this chip. */ -/* Use BATMON register instead */ +// Bandgap can't be measured against supply voltage in this chip. +// Use BATMON register instead for ( p1=16; p1<31; p1++) { BATMON = p1; clock_delay_usec(100); // delay needed !! if ((BATMON&(1<