brickOS Kernel Developer v0.9.0
battery.c
Go to the documentation of this file.
1
6/*
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.0 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License
10 * at http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 * the License for the specific language governing rights and
15 * limitations under the License.
16 *
17 * The Original Code is legOS code, released October 17, 1999.
18 *
19 * The Initial Developer of the Original Code is Markus L. Noga.
20 * Portions created by Markus L. Noga are Copyright (C) 1999
21 * Markus L. Noga. All Rights Reserved.
22 *
23 * Contributor(s): Markus L. Noga <markus@noga.de>
24 * Paolo Masetti <paolo.masetti@itlug.org>
25 */
26
27#include <sys/irq.h>
28#include <dsensor.h>
29#include <dlcd.h>
30
31#include <sys/battery.h>
32
34//
35// Global Variables
36//
38#ifdef CONF_BATTERY_INDICATOR
39unsigned int battery_refresh_counter = 0;
40unsigned int battery_refresh_period = 2000;
41#endif
42
44//
45// Functions
46//
48
50#if defined(CONF_DSENSOR)
52{
53 long b = ds_scale(BATTERY) * 0xABD4L;
54 return (int)(b / 0x618L);
55}
56#endif // CONF_DSENSOR
57
58#ifdef CONF_BATTERY_INDICATOR
59// battery indicator handed by kernel task when CONF_TM
60#ifndef CONF_TM
62#ifdef CONF_RCX_COMPILER
63void battery_refresh(void) {
64#else // CONF_RCX_COMPILER
65HANDLER_WRAPPER("battery_refresh","battery_refresh_core");
66void battery_refresh_core(void) {
67#endif // CONF_RCX_COMPILER
68 int bmv = get_battery_mv();
69
72 else if (bmv > BATTERY_LOW_THRESHOLD_MV)
74}
75#endif // CONF_TM
76#endif // CONF_BATTERY_INDICATOR
Internal Interface: battery handling.
void battery_refresh(void)
cause the battery voltage sensor value to be refreshed
#define BATTERY_NORMAL_THRESHOLD_MV
Definition battery.h:41
#define BATTERY_LOW_THRESHOLD_MV
Definition battery.h:42
int get_battery_mv()
get current battery voltage
Interface: direct control of LCD display.
#define dlcd_hide(a)
clear a segment directly in the LCD buffer
Definition dlcd.h:180
#define LCD_BATTERY_X
Definition dlcd.h:159
#define dlcd_show(a)
set a segment directly in the LCD buffer
Definition dlcd.h:175
#define BATTERY
Battery sensor.
Definition dsensor.h:64
#define ds_scale(x)
mask off bottom 6 bits
Definition dsensor.h:127
Internal LNP Interface: RCX redirected IRQ vectors.
#define HANDLER_WRAPPER(wrapstring, handstring)
Definition irq.h:48