mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 05:05:20 -05:00
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:
parent
e1949696d9
commit
62f5027650
2 changed files with 20 additions and 5 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue