kopia lustrzana https://github.com/OpenRTX/OpenRTX
Implement battery voltage to charge conversion
Voltage to charge nonlinear function is being linearly approximated in the operating range.replace/3f6653143c3de3d583303c4c15a3770aea76d900
rodzic
0e1d9b090f
commit
41ec005680
|
@ -14,7 +14,8 @@ project('OpenRTX', 'c',
|
|||
openrtx_src = ['openrtx/src/bootstrap.c',
|
||||
'openrtx/src/state.c',
|
||||
'openrtx/src/ui.c',
|
||||
'openrtx/src/threads.c']
|
||||
'openrtx/src/threads.c',
|
||||
'openrtx/src/battery.c']
|
||||
|
||||
|
||||
## Replace main executable with platform test
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN, *
|
||||
* Silvano Seva IU2KWO *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef BATTERY_H
|
||||
#define BATTERY_H
|
||||
|
||||
/* This function uses battery charge tables to convert a battery voltage into a
|
||||
* charge percentage.
|
||||
* @param vbat: the voltage read from the battery in volt
|
||||
* @return the charge percentage
|
||||
*/
|
||||
float battery_getCharge(float vbat);
|
||||
|
||||
#endif /* BATTERY_H */
|
|
@ -0,0 +1,45 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN, *
|
||||
* Silvano Seva IU2KWO *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#include <battery.h>
|
||||
#include <hwconfig.h>
|
||||
#include <math.h>
|
||||
|
||||
/* This array acts as a lookup table for converting Li-Po voltage into
|
||||
* charge percentage, elements range from 0% to 100% (included) with 5% steps.
|
||||
* Data is taken from (https://blog.ampow.com/lipo-voltage-chart/).
|
||||
*/
|
||||
#define V_LUT_STEPS 21
|
||||
#if defined BAT_LIPO_1S
|
||||
float bat_v_min = 3.61f;
|
||||
float bat_v_max = 4.20f;
|
||||
#elif defined BAT_LIPO_2S
|
||||
float bat_v_min = 7.22f;
|
||||
float bat_v_max = 8.40f;
|
||||
#elif defined BAT_LIPO_3S
|
||||
float bat_v_min = 10.83;
|
||||
float bat_v_max = 12.60;
|
||||
#else
|
||||
#error Please define a battery type into platform/targets/.../hwconfig.h
|
||||
#endif
|
||||
|
||||
float battery_getCharge(float vbat) {
|
||||
// Perform a linear interpolation between minimum and maximum charge values
|
||||
return (vbat - bat_v_min) / (bat_v_max - bat_v_min);
|
||||
}
|
|
@ -72,6 +72,7 @@
|
|||
#include <platform.h>
|
||||
#include <hwconfig.h>
|
||||
#include <string.h>
|
||||
#include <battery.h>
|
||||
|
||||
const char *menuItems[MENU_NUM] =
|
||||
{
|
||||
|
@ -229,12 +230,12 @@ void _ui_drawTopBar(state_t* last_state)
|
|||
color_white);
|
||||
|
||||
// Print battery icon on top bar, use 4 px padding
|
||||
float percentage = last_state->v_bat / MAX_VBAT;
|
||||
float charge = battery_getCharge(last_state->v_bat);
|
||||
uint16_t bat_width = SCREEN_WIDTH / 9;
|
||||
uint16_t bat_height = layout.top_h - layout.vertical_pad;
|
||||
point_t bat_pos = {SCREEN_WIDTH - bat_width - layout.horizontal_pad,
|
||||
layout.vertical_pad / 2};
|
||||
gfx_drawBattery(bat_pos, bat_width, bat_height, percentage);
|
||||
gfx_drawBattery(bat_pos, bat_width, bat_height, charge);
|
||||
|
||||
// Print radio mode on top bar
|
||||
char mode[4] = "";
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 64
|
||||
|
||||
/* Battery type */
|
||||
#define BAT_LIPO_2S
|
||||
|
||||
/* Display */
|
||||
#define LCD_BKLIGHT GPIOC,4
|
||||
#define LCD_CS GPIOC,8
|
||||
|
@ -56,4 +59,4 @@
|
|||
#define FUNC2_SW GPIOB,1
|
||||
#define MONI_SW GPIOB,9
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
/* Screen needs x-axis mirroring */
|
||||
#define DISPLAY_MIRROR_X
|
||||
|
||||
/* Maximum battery voltage */
|
||||
#define MAX_VBAT 8.4f
|
||||
/* Battery type */
|
||||
#define BAT_LIPO_2S
|
||||
|
||||
/* Display */
|
||||
#define LCD_D0 GPIOD,14
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
#define SCREEN_WIDTH 160
|
||||
#define SCREEN_HEIGHT 128
|
||||
|
||||
/* Maximum battery voltage */
|
||||
#define MAX_VBAT 8.4f
|
||||
/* Battery type */
|
||||
#define BAT_LIPO_2S
|
||||
|
||||
/* Display */
|
||||
#define LCD_D0 GPIOD,14
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#define SCREEN_WIDTH 160
|
||||
#define SCREEN_HEIGHT 128
|
||||
|
||||
/* Battery type */
|
||||
#define BAT_LIPO_2S
|
||||
|
||||
/* Display */
|
||||
#define LCD_D0 GPIOD,14
|
||||
#define LCD_D1 GPIOD,15
|
||||
|
@ -76,9 +79,6 @@
|
|||
#define FLASH_SDO GPIOB,4
|
||||
#define FLASH_SDI GPIOB,5
|
||||
|
||||
/* Maximum battery voltage */
|
||||
#define MAX_VBAT 8.4f
|
||||
|
||||
/*
|
||||
* To enable pwm for display backlight dimming uncomment this directive.
|
||||
*
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
radio_state Radio_State = {12, 7, 3, 4, 1, false};
|
||||
radio_state Radio_State = {12, 8.2f, 3, 4, 1, false};
|
||||
|
||||
void systemBootstrap();
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
#define PLATFORM_LINUX
|
||||
|
||||
/* Battery type */
|
||||
#define BAT_LIPO_2S
|
||||
|
||||
#define GPIOA "PA"
|
||||
#define GPIOB "PB"
|
||||
#define GPIOC "PC"
|
||||
|
@ -48,6 +51,3 @@
|
|||
|
||||
/* Push-to-talk switch */
|
||||
#define PTT_SW "PTT_SW",11
|
||||
|
||||
/* Maximum battery voltage */
|
||||
#define MAX_VBAT 8.4f
|
||||
|
|
Ładowanie…
Reference in New Issue