mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 17:55:30 +03:00
Merge pull request #11084 from rvdveen/lipo-continue-v2-shortmenu
This commit is contained in:
commit
d01447c025
10 changed files with 97 additions and 1 deletions
|
@ -919,6 +919,9 @@ const clivalue_t valueTable[] = {
|
|||
{ "ibatv_scale", VAR_INT16 | MASTER_VALUE, .config.minmax = { -16000, 16000 }, PG_CURRENT_SENSOR_VIRTUAL_CONFIG, offsetof(currentSensorVirtualConfig_t, scale) },
|
||||
{ "ibatv_offset", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 16000 }, PG_CURRENT_SENSOR_VIRTUAL_CONFIG, offsetof(currentSensorVirtualConfig_t, offset) },
|
||||
#endif
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
{ "battery_continue", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, isBatteryContinueEnabled) },
|
||||
#endif
|
||||
|
||||
#ifdef USE_BEEPER
|
||||
// PG_BEEPER_DEV_CONFIG
|
||||
|
@ -1662,6 +1665,10 @@ const clivalue_t valueTable[] = {
|
|||
|
||||
{ "stats_total_time_s", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_time_s) },
|
||||
{ "stats_total_dist_m", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_dist_m) },
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
{ "stats_mah_used", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_mah_used) },
|
||||
#endif
|
||||
#endif
|
||||
{ "name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, MAX_NAME_LENGTH, STRING_FLAGS_NONE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, name) },
|
||||
#ifdef USE_OSD
|
||||
|
|
|
@ -62,6 +62,11 @@
|
|||
|
||||
#include "cms_menu_main.h"
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
#include "sensors/battery.h"
|
||||
#include "pg/stats.h"
|
||||
#endif
|
||||
|
||||
#define CALIBRATION_STATUS_MAX_LENGTH 9
|
||||
|
||||
#define CALIBRATION_STATUS_REQUIRED "REQUIRED"
|
||||
|
@ -72,6 +77,10 @@
|
|||
static char accCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
|
||||
#endif
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
static char batteryContinueAmount[18];
|
||||
#endif
|
||||
|
||||
// Features
|
||||
|
||||
static const OSD_Entry menuFeaturesEntries[] =
|
||||
|
@ -121,10 +130,28 @@ static const void *cmsx_SaveExitMenu(displayPort_t *pDisplay, const void *ptr)
|
|||
}
|
||||
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
#define SETUP_POPUP_MAX_ENTRIES 2 // Increase as new entries are added
|
||||
#else
|
||||
#define SETUP_POPUP_MAX_ENTRIES 1 // Increase as new entries are added
|
||||
#endif
|
||||
|
||||
static OSD_Entry setupPopupMenuEntries[SETUP_POPUP_MAX_ENTRIES + 3];
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
static const void *cmsRestoreMah(displayPort_t *pDisp, const void *self)
|
||||
{
|
||||
UNUSED(self);
|
||||
|
||||
setMAhDrawn(statsConfig()->stats_mah_used);
|
||||
statsConfigMutable()->stats_mah_used = 0;
|
||||
|
||||
cmsMenuExit(pDisp, (void *)CMS_EXIT);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool setupPopupMenuBuild(void)
|
||||
{
|
||||
uint8_t menuIndex = 0;
|
||||
|
@ -139,6 +166,12 @@ static bool setupPopupMenuBuild(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
if (hasUsedMAh()) {
|
||||
cmsAddMenuEntry(&setupPopupMenuEntries[++menuIndex], batteryContinueAmount, OME_Funcall | DYNAMIC, cmsRestoreMah, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
cmsAddMenuEntry(&setupPopupMenuEntries[++menuIndex], "EXIT", OME_Back | DYNAMIC, NULL, NULL);
|
||||
cmsAddMenuEntry(&setupPopupMenuEntries[++menuIndex], "NULL", OME_END, NULL, NULL);
|
||||
|
||||
|
@ -154,6 +187,11 @@ static const void *setupPopupMenuOnDisplayUpdate(displayPort_t *pDisp, const OSD
|
|||
// Update the ACC calibration status message.
|
||||
tfp_sprintf(accCalibrationStatus, accIsCalibrationComplete() ? accHasBeenCalibrated() ? CALIBRATION_STATUS_COMPLETE : CALIBRATION_STATUS_REQUIRED : CALIBRATION_STATUS_ACTIVE);
|
||||
#endif
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
if (hasUsedMAh()) {
|
||||
tfp_sprintf(batteryContinueAmount, "RESTORE %5d MAH", statsConfig()->stats_mah_used);
|
||||
}
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
|
||||
#include "pg/stats.h"
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
#include "sensors/battery.h"
|
||||
#endif
|
||||
|
||||
#define STATS_SAVE_DELAY_US 500000 // Let disarming complete and save stats after this time
|
||||
|
||||
|
@ -91,6 +94,9 @@ void statsOnDisarm(void)
|
|||
statsConfigMutable()->stats_total_flights += 1; // arm / flight counter
|
||||
statsConfigMutable()->stats_total_time_s += dtS;
|
||||
statsConfigMutable()->stats_total_dist_m += (DISTANCE_FLOWN_CM - arm_distance_cm) / 100;
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
statsConfigMutable()->stats_mah_used = getMAhDrawn();
|
||||
#endif
|
||||
|
||||
saveRequired = true;
|
||||
}
|
||||
|
|
|
@ -386,6 +386,15 @@ void renderOsdWarning(char *warningText, bool *blinking, uint8_t *displayAttr)
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
// Show warning if battery is not fresh and battery continue is active
|
||||
if (hasUsedMAh()) {
|
||||
tfp_sprintf(warningText, "BATTERY CONTINUE");
|
||||
*displayAttr = DISPLAYPORT_ATTR_INFO;
|
||||
return;
|
||||
}
|
||||
#endif // USE_BATTERY_CONTINUE
|
||||
|
||||
// Show warning if battery is not fresh
|
||||
if (osdWarnGetState(OSD_WARNING_BATTERY_NOT_FULL) && !(ARMING_FLAG(ARMED) || ARMING_FLAG(WAS_EVER_ARMED)) && (getBatteryState() == BATTERY_OK)
|
||||
&& getBatteryAverageCellVoltage() < batteryConfig()->vbatfullcellvoltage) {
|
||||
|
|
|
@ -27,12 +27,13 @@
|
|||
|
||||
#include "stats.h"
|
||||
|
||||
PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 2);
|
||||
PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 3);
|
||||
|
||||
PG_RESET_TEMPLATE(statsConfig_t, statsConfig,
|
||||
.stats_min_armed_time_s = STATS_OFF,
|
||||
.stats_total_flights = 0,
|
||||
.stats_total_time_s = 0,
|
||||
.stats_total_dist_m = 0,
|
||||
.stats_mah_used = 0,
|
||||
);
|
||||
#endif
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef struct statsConfig_s {
|
|||
uint32_t stats_total_time_s;
|
||||
uint32_t stats_total_dist_m;
|
||||
int8_t stats_min_armed_time_s;
|
||||
uint32_t stats_mah_used;
|
||||
} statsConfig_t;
|
||||
|
||||
PG_DECLARE(statsConfig_t, statsConfig);
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
#include "pg/pg_ids.h"
|
||||
|
||||
#include "scheduler/scheduler.h"
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
#include "pg/stats.h"
|
||||
#endif
|
||||
|
||||
#include "sensors/battery.h"
|
||||
|
||||
|
@ -541,5 +544,24 @@ int32_t getAmperageLatest(void)
|
|||
|
||||
int32_t getMAhDrawn(void)
|
||||
{
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
return currentMeter.mAhDrawn + currentMeter.mAhDrawnOffset;
|
||||
#else
|
||||
return currentMeter.mAhDrawn;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
bool hasUsedMAh()
|
||||
{
|
||||
return batteryConfig()->isBatteryContinueEnabled
|
||||
&& !(ARMING_FLAG(ARMED) || ARMING_FLAG(WAS_EVER_ARMED)) && (getBatteryState() == BATTERY_OK)
|
||||
&& getBatteryAverageCellVoltage() < batteryConfig()->vbatfullcellvoltage
|
||||
&& statsConfig()->stats_mah_used > 0;
|
||||
}
|
||||
|
||||
void setMAhDrawn(uint32_t mAhDrawn)
|
||||
{
|
||||
currentMeter.mAhDrawnOffset = mAhDrawn;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -71,6 +71,10 @@ typedef struct batteryConfig_s {
|
|||
uint8_t vbatDurationForWarning; // Period voltage has to sustain before the battery state is set to BATTERY_WARNING (in 0.1 s)
|
||||
uint8_t vbatDurationForCritical; // Period voltage has to sustain before the battery state is set to BATTERY_CRIT (in 0.1 s)
|
||||
uint8_t vbatSagLpfPeriod; // Period of the cutoff frequency for the Vbat sag and PID compensation filter (in 0.1 s)
|
||||
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
bool isBatteryContinueEnabled;
|
||||
#endif
|
||||
} batteryConfig_t;
|
||||
|
||||
PG_DECLARE(batteryConfig_t, batteryConfig);
|
||||
|
@ -116,6 +120,10 @@ bool isAmperageConfigured(void);
|
|||
int32_t getAmperage(void);
|
||||
int32_t getAmperageLatest(void);
|
||||
int32_t getMAhDrawn(void);
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
bool hasUsedMAh();
|
||||
void setMAhDrawn(uint32_t mAhDrawn);
|
||||
#endif
|
||||
|
||||
void batteryUpdateCurrentMeter(timeUs_t currentTimeUs);
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ typedef struct currentMeter_s {
|
|||
int32_t amperage; // current read by current sensor in centiampere (1/100th A)
|
||||
int32_t amperageLatest; // current read by current sensor in centiampere (1/100th A) (unfiltered)
|
||||
int32_t mAhDrawn; // milliampere hours drawn from the battery since start
|
||||
#ifdef USE_BATTERY_CONTINUE
|
||||
int32_t mAhDrawnOffset; // mAh offset
|
||||
#endif
|
||||
} currentMeter_t;
|
||||
|
||||
// WARNING - do not mix usage of CURRENT_SENSOR_* and CURRENT_METER_*, they are separate concerns.
|
||||
|
|
|
@ -421,4 +421,5 @@ extern uint8_t _dmaram_end__;
|
|||
#define USE_EMFAT_AUTORUN
|
||||
#define USE_EMFAT_ICON
|
||||
#define USE_GPS_PLUS_CODES
|
||||
#define USE_BATTERY_CONTINUE
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue