NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
battery.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include "common/filter.h"
21 #include "../config/battery.h"
22 
23 typedef enum {
29 
30 struct battery {
31  uint16_t vbat;
32  uint16_t vbatRaw;
33  uint16_t vbatLatestADC;
38  int32_t amperage;
39  int32_t mAhDrawn;
40 
43 
44  const struct battery_config *config;
45 };
46 
47 void battery_init(struct battery *self, const struct battery_config *config);
49 const char *battery_get_state_str(struct battery *self);
50 void battery_update(struct battery *self);
51 uint8_t battery_get_remaining_percent(struct battery *self);
52 uint8_t battery_get_remaining_capacity(struct battery *self);
53 uint16_t battery_get_voltage(struct battery *self);
54 uint8_t battery_get_cell_count(struct battery *self);
55 uint16_t battery_get_cell_voltage(struct battery *self);
56 int32_t battery_get_current(struct battery *self);
57 int32_t battery_get_spent_capacity(struct battery *self);
58 
59 void battery_update_current_meter(struct battery *self, int32_t lastUpdateAt);
uint16_t battery_get_cell_voltage(struct battery *self)
Definition: battery.c:67
Definition: config.h:81
int32_t battery_get_spent_capacity(struct battery *self)
Definition: battery.c:63
const char * battery_get_state_str(struct battery *self)
Definition: battery.c:128
biquad_t vbatFilterState
Definition: battery.h:42
Definition: battery.h:30
int32_t mAhDrawn
Definition: battery.h:39
uint16_t amperageLatestADC
Definition: battery.h:37
int32_t battery_get_current(struct battery *self)
Definition: battery.c:59
void battery_init(struct battery *self, const struct battery_config *config)
Definition: battery.c:39
const struct battery_config * config
Definition: battery.h:44
uint16_t batteryCriticalVoltage
Definition: battery.h:36
uint16_t battery_get_voltage(struct battery *self)
Definition: battery.c:51
uint16_t vbatLatestADC
Definition: battery.h:33
Definition: battery.h:26
Definition: battery.h:37
uint8_t battery_get_cell_count(struct battery *self)
Definition: battery.c:55
uint16_t batteryWarningVoltage
Definition: battery.h:35
uint8_t battery_get_remaining_capacity(struct battery *self)
Definition: battery.c:182
battery_state_t battery_get_state(struct battery *self)
Definition: battery.c:124
Definition: battery.h:24
uint16_t vbat
Definition: battery.h:31
void battery_update(struct battery *self)
Definition: battery.c:91
int32_t amperage
Definition: battery.h:38
battery_state_t
Definition: battery.h:23
uint8_t batteryCellCount
Definition: battery.h:34
battery_state_t batteryState
Definition: battery.h:41
void battery_update_current_meter(struct battery *self, int32_t lastUpdateAt)
Definition: battery.c:144
uint16_t vbatRaw
Definition: battery.h:32
Definition: filter.h:27
Definition: battery.h:25
Definition: battery.h:27
uint8_t battery_get_remaining_percent(struct battery *self)
Definition: battery.c:177