Fix battery meter on Sansa Connect.

Use the battery capacity percents reported by AVR. Internally fake linear voltage scale is used (1 mV = 1%).


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31049 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Tomasz Moń 2011-11-24 18:55:11 +00:00
parent e1949696d9
commit 62f5027650
2 changed files with 20 additions and 5 deletions

View file

@ -297,6 +297,8 @@ void avr_hid_init(void)
avr_hid_sync();
}
/* defined in powermgmt-sansaconnect.c */
void set_battery_level(unsigned int level);
static void avr_hid_get_state(void)
{
@ -309,6 +311,12 @@ static void avr_hid_get_state(void)
spi_txrx(cmd, buf, sizeof(cmd));
/*
* buf[8] contains some battery/charger related information (unknown)
* buf[9] contains battery level in percents (0-100)
*/
set_battery_level((unsigned int)buf[9]);
spi_txrx(cmd_empty, NULL, 1); /* request interrupt on button press */
parse_button_state(buf);

View file

@ -24,9 +24,10 @@
#include "powermgmt.h"
#include "kernel.h"
/* THIS CONTAINS CURRENTLY DUMMY CODE! */
/* Use fake linear scale as AVR does the voltage to percentage conversion */
static unsigned int current_battery_level = 100;
static const unsigned short current_voltage = 3910;
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
{
0
@ -40,17 +41,23 @@ const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{
{ 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320 },
{ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 },
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
const unsigned short percent_to_volt_charge[11] =
{
100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320,
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
};
/* Returns battery voltage from ADC [millivolts] */
unsigned int battery_adc_voltage(void)
{
return current_voltage;
return current_battery_level;
}
void set_battery_level(unsigned int level)
{
current_battery_level = level;
}