mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Add battery warning beeper. Update MSP_MISC/MSP_SET_MISC.
Note the old beeper was essentially 'battery critical'.
This commit is contained in:
parent
49cf725b41
commit
367eb79bd0
12 changed files with 67 additions and 24 deletions
|
@ -104,7 +104,7 @@ profile_t *currentProfile;
|
||||||
static uint8_t currentControlRateProfileIndex = 0;
|
static uint8_t currentControlRateProfileIndex = 0;
|
||||||
controlRateConfig_t *currentControlRateProfile;
|
controlRateConfig_t *currentControlRateProfile;
|
||||||
|
|
||||||
static const uint8_t EEPROM_CONF_VERSION = 86;
|
static const uint8_t EEPROM_CONF_VERSION = 87;
|
||||||
|
|
||||||
static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims)
|
static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims)
|
||||||
{
|
{
|
||||||
|
@ -216,6 +216,7 @@ void resetBatteryConfig(batteryConfig_t *batteryConfig)
|
||||||
batteryConfig->vbatscale = VBAT_SCALE_DEFAULT;
|
batteryConfig->vbatscale = VBAT_SCALE_DEFAULT;
|
||||||
batteryConfig->vbatmaxcellvoltage = 43;
|
batteryConfig->vbatmaxcellvoltage = 43;
|
||||||
batteryConfig->vbatmincellvoltage = 33;
|
batteryConfig->vbatmincellvoltage = 33;
|
||||||
|
batteryConfig->vbatwarningcellvoltage = 35;
|
||||||
batteryConfig->currentMeterOffset = 0;
|
batteryConfig->currentMeterOffset = 0;
|
||||||
batteryConfig->currentMeterScale = 400; // for Allegro ACS758LCB-100U (40mV/A)
|
batteryConfig->currentMeterScale = 400; // for Allegro ACS758LCB-100U (40mV/A)
|
||||||
batteryConfig->batteryCapacity = 0;
|
batteryConfig->batteryCapacity = 0;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "drivers/sound_beeper.h"
|
#include "drivers/sound_beeper.h"
|
||||||
#include "drivers/system.h"
|
#include "drivers/system.h"
|
||||||
#include "flight/failsafe.h"
|
#include "flight/failsafe.h"
|
||||||
|
#include "sensors/battery.h"
|
||||||
#include "sensors/sensors.h"
|
#include "sensors/sensors.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
|
@ -60,7 +61,7 @@ void beepcodeInit(failsafe_t *initialFailsafe)
|
||||||
failsafe = initialFailsafe;
|
failsafe = initialFailsafe;
|
||||||
}
|
}
|
||||||
|
|
||||||
void beepcodeUpdateState(bool warn_vbat)
|
void beepcodeUpdateState(batteryState_e batteryState)
|
||||||
{
|
{
|
||||||
static uint8_t beeperOnBox;
|
static uint8_t beeperOnBox;
|
||||||
#ifdef GPS
|
#ifdef GPS
|
||||||
|
@ -117,7 +118,9 @@ void beepcodeUpdateState(bool warn_vbat)
|
||||||
#endif
|
#endif
|
||||||
else if (beeperOnBox == 1)
|
else if (beeperOnBox == 1)
|
||||||
beep_code('S','S','S','M'); // beeperon
|
beep_code('S','S','S','M'); // beeperon
|
||||||
else if (warn_vbat)
|
else if (batteryState == BATTERY_CRITICAL)
|
||||||
|
beep_code('S','S','M','D');
|
||||||
|
else if (batteryState == BATTERY_WARNING)
|
||||||
beep_code('S','M','M','D');
|
beep_code('S','M','M','D');
|
||||||
else if (FLIGHT_MODE(AUTOTUNE_MODE))
|
else if (FLIGHT_MODE(AUTOTUNE_MODE))
|
||||||
beep_code('S','M','S','M');
|
beep_code('S','M','S','M');
|
||||||
|
|
|
@ -17,5 +17,5 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void beepcodeUpdateState(bool warn_vbat);
|
void beepcodeUpdateState(batteryState_e batteryState);
|
||||||
void queueConfirmationBeep(uint8_t duration);
|
void queueConfirmationBeep(uint8_t duration);
|
||||||
|
|
|
@ -570,7 +570,7 @@ void applyLedWarningLayer(uint8_t updateNow)
|
||||||
|
|
||||||
if (updateNow && warningFlashCounter == 0) {
|
if (updateNow && warningFlashCounter == 0) {
|
||||||
warningFlags = WARNING_FLAG_NONE;
|
warningFlags = WARNING_FLAG_NONE;
|
||||||
if (feature(FEATURE_VBAT) && shouldSoundBatteryAlarm()) {
|
if (feature(FEATURE_VBAT) && calculateBatteryState() != BATTERY_OK) {
|
||||||
warningFlags |= WARNING_FLAG_LOW_BATTERY;
|
warningFlags |= WARNING_FLAG_LOW_BATTERY;
|
||||||
}
|
}
|
||||||
if (failsafe->vTable->hasTimerElapsed()) {
|
if (failsafe->vTable->hasTimerElapsed()) {
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "drivers/accgyro.h"
|
#include "drivers/accgyro.h"
|
||||||
|
|
||||||
|
#include "sensors/battery.h"
|
||||||
#include "sensors/sensors.h"
|
#include "sensors/sensors.h"
|
||||||
#include "sensors/gyro.h"
|
#include "sensors/gyro.h"
|
||||||
#include "sensors/acceleration.h"
|
#include "sensors/acceleration.h"
|
||||||
|
|
|
@ -286,6 +286,7 @@ const clivalue_t valueTable[] = {
|
||||||
{ "vbat_scale", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatscale, VBAT_SCALE_MIN, VBAT_SCALE_MAX },
|
{ "vbat_scale", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatscale, VBAT_SCALE_MIN, VBAT_SCALE_MAX },
|
||||||
{ "vbat_max_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmaxcellvoltage, 10, 50 },
|
{ "vbat_max_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmaxcellvoltage, 10, 50 },
|
||||||
{ "vbat_min_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmincellvoltage, 10, 50 },
|
{ "vbat_min_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmincellvoltage, 10, 50 },
|
||||||
|
{ "vbat_warning_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatwarningcellvoltage, 10, 50 },
|
||||||
{ "current_meter_scale", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.currentMeterScale, 1, 10000 },
|
{ "current_meter_scale", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.currentMeterScale, 1, 10000 },
|
||||||
{ "current_meter_offset", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.currentMeterOffset, 0, 1650 },
|
{ "current_meter_offset", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.currentMeterOffset, 0, 1650 },
|
||||||
{ "multiwii_current_meter_output", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.multiwiiCurrentMeterOutput, 0, 1 },
|
{ "multiwii_current_meter_output", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.multiwiiCurrentMeterOutput, 0, 1 },
|
||||||
|
|
|
@ -901,18 +901,27 @@ static bool processOutCommand(uint8_t cmdMSP)
|
||||||
break;
|
break;
|
||||||
case MSP_MISC:
|
case MSP_MISC:
|
||||||
headSerialReply(2 * 6 + 4 + 2 + 4);
|
headSerialReply(2 * 6 + 4 + 2 + 4);
|
||||||
serialize16(0); // intPowerTrigger1 (aka useless trash)
|
serialize16(masterConfig.rxConfig.midrc);
|
||||||
|
|
||||||
serialize16(masterConfig.escAndServoConfig.minthrottle);
|
serialize16(masterConfig.escAndServoConfig.minthrottle);
|
||||||
serialize16(masterConfig.escAndServoConfig.maxthrottle);
|
serialize16(masterConfig.escAndServoConfig.maxthrottle);
|
||||||
serialize16(masterConfig.escAndServoConfig.mincommand);
|
serialize16(masterConfig.escAndServoConfig.mincommand);
|
||||||
|
|
||||||
serialize16(currentProfile->failsafeConfig.failsafe_throttle);
|
serialize16(currentProfile->failsafeConfig.failsafe_throttle);
|
||||||
serialize16(0); // plog useless shit
|
|
||||||
serialize32(0); // plog useless shit
|
serialize8(0); // gps_type
|
||||||
serialize16(currentProfile->mag_declination / 10); // TODO check this shit
|
serialize8(0); // gps_baudrate
|
||||||
|
serialize8(0); // gps_ubx_sbas
|
||||||
|
serialize8(masterConfig.batteryConfig.multiwiiCurrentMeterOutput);
|
||||||
|
serialize8(masterConfig.rxConfig.rssi_channel);
|
||||||
|
serialize8(0);
|
||||||
|
|
||||||
|
serialize16(currentProfile->mag_declination / 10);
|
||||||
|
|
||||||
serialize8(masterConfig.batteryConfig.vbatscale);
|
serialize8(masterConfig.batteryConfig.vbatscale);
|
||||||
serialize8(masterConfig.batteryConfig.vbatmincellvoltage);
|
serialize8(masterConfig.batteryConfig.vbatmincellvoltage);
|
||||||
serialize8(masterConfig.batteryConfig.vbatmaxcellvoltage);
|
serialize8(masterConfig.batteryConfig.vbatmaxcellvoltage);
|
||||||
serialize8(0);
|
serialize8(masterConfig.batteryConfig.vbatwarningcellvoltage);
|
||||||
break;
|
break;
|
||||||
case MSP_MOTOR_PINS:
|
case MSP_MOTOR_PINS:
|
||||||
headSerialReply(8);
|
headSerialReply(8);
|
||||||
|
@ -1062,6 +1071,7 @@ static bool processOutCommand(uint8_t cmdMSP)
|
||||||
static bool processInCommand(void)
|
static bool processInCommand(void)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
uint16_t tmp;
|
||||||
#ifdef GPS
|
#ifdef GPS
|
||||||
uint8_t wp_no;
|
uint8_t wp_no;
|
||||||
int32_t lat = 0, lon = 0, alt = 0;
|
int32_t lat = 0, lon = 0, alt = 0;
|
||||||
|
@ -1165,18 +1175,29 @@ static bool processInCommand(void)
|
||||||
currentControlRateProfile->thrExpo8 = read8();
|
currentControlRateProfile->thrExpo8 = read8();
|
||||||
break;
|
break;
|
||||||
case MSP_SET_MISC:
|
case MSP_SET_MISC:
|
||||||
read16(); // powerfailmeter
|
tmp = read16();
|
||||||
|
if (tmp < 1600 && tmp > 1400)
|
||||||
|
masterConfig.rxConfig.midrc = tmp;
|
||||||
|
|
||||||
masterConfig.escAndServoConfig.minthrottle = read16();
|
masterConfig.escAndServoConfig.minthrottle = read16();
|
||||||
masterConfig.escAndServoConfig.maxthrottle = read16();
|
masterConfig.escAndServoConfig.maxthrottle = read16();
|
||||||
masterConfig.escAndServoConfig.mincommand = read16();
|
masterConfig.escAndServoConfig.mincommand = read16();
|
||||||
|
|
||||||
currentProfile->failsafeConfig.failsafe_throttle = read16();
|
currentProfile->failsafeConfig.failsafe_throttle = read16();
|
||||||
read16();
|
|
||||||
read32();
|
read8(); // gps_type
|
||||||
|
read8(); // gps_baudrate
|
||||||
|
read8(); // gps_ubx_sbas
|
||||||
|
masterConfig.batteryConfig.multiwiiCurrentMeterOutput = read8();
|
||||||
|
masterConfig.rxConfig.rssi_channel = read8();
|
||||||
|
read8();
|
||||||
|
|
||||||
currentProfile->mag_declination = read16() * 10;
|
currentProfile->mag_declination = read16() * 10;
|
||||||
|
|
||||||
masterConfig.batteryConfig.vbatscale = read8(); // actual vbatscale as intended
|
masterConfig.batteryConfig.vbatscale = read8(); // actual vbatscale as intended
|
||||||
masterConfig.batteryConfig.vbatmincellvoltage = read8(); // vbatlevel_warn1 in MWC2.3 GUI
|
masterConfig.batteryConfig.vbatmincellvoltage = read8(); // vbatlevel_warn1 in MWC2.3 GUI
|
||||||
masterConfig.batteryConfig.vbatmaxcellvoltage = read8(); // vbatlevel_warn2 in MWC2.3 GUI
|
masterConfig.batteryConfig.vbatmaxcellvoltage = read8(); // vbatlevel_warn2 in MWC2.3 GUI
|
||||||
read8(); // vbatlevel_crit (unused)
|
masterConfig.batteryConfig.vbatwarningcellvoltage = read8(); // vbatlevel when buzzer starts to alert
|
||||||
break;
|
break;
|
||||||
case MSP_SET_MOTOR:
|
case MSP_SET_MOTOR:
|
||||||
for (i = 0; i < 8; i++) // FIXME should this use MAX_MOTORS or MAX_SUPPORTED_MOTORS instead of 8
|
for (i = 0; i < 8; i++) // FIXME should this use MAX_MOTORS or MAX_SUPPORTED_MOTORS instead of 8
|
||||||
|
|
|
@ -161,7 +161,7 @@ void annexCode(void)
|
||||||
int32_t tmp, tmp2;
|
int32_t tmp, tmp2;
|
||||||
int32_t axis, prop1 = 0, prop2;
|
int32_t axis, prop1 = 0, prop2;
|
||||||
|
|
||||||
static uint8_t batteryWarningEnabled = false;
|
static batteryState_e batteryState = BATTERY_OK;
|
||||||
static uint8_t vbatTimer = 0;
|
static uint8_t vbatTimer = 0;
|
||||||
static int32_t vbatCycleTime = 0;
|
static int32_t vbatCycleTime = 0;
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ void annexCode(void)
|
||||||
|
|
||||||
if (feature(FEATURE_VBAT)) {
|
if (feature(FEATURE_VBAT)) {
|
||||||
updateBatteryVoltage();
|
updateBatteryVoltage();
|
||||||
batteryWarningEnabled = shouldSoundBatteryAlarm();
|
batteryState = calculateBatteryState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feature(FEATURE_CURRENT_METER)) {
|
if (feature(FEATURE_CURRENT_METER)) {
|
||||||
|
@ -241,7 +241,7 @@ void annexCode(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
beepcodeUpdateState(batteryWarningEnabled);
|
beepcodeUpdateState(batteryState);
|
||||||
|
|
||||||
if (ARMING_FLAG(ARMED)) {
|
if (ARMING_FLAG(ARMED)) {
|
||||||
LED0_ON;
|
LED0_ON;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "drivers/accgyro.h"
|
#include "drivers/accgyro.h"
|
||||||
#include "flight/flight.h"
|
#include "flight/flight.h"
|
||||||
|
#include "sensors/battery.h"
|
||||||
#include "sensors/sensors.h"
|
#include "sensors/sensors.h"
|
||||||
#include "io/beeper.h"
|
#include "io/beeper.h"
|
||||||
#include "sensors/boardalignment.h"
|
#include "sensors/boardalignment.h"
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
|
|
||||||
// Battery monitoring stuff
|
// Battery monitoring stuff
|
||||||
uint8_t batteryCellCount = 3; // cell count
|
uint8_t batteryCellCount = 3; // cell count
|
||||||
uint16_t batteryWarningVoltage; // annoying beeper after this one, battery ready to be dead
|
uint16_t batteryWarningVoltage;
|
||||||
|
uint16_t batteryCriticalVoltage;
|
||||||
|
|
||||||
uint8_t vbat = 0; // battery voltage in 0.1V steps
|
uint8_t vbat = 0; // battery voltage in 0.1V steps
|
||||||
|
|
||||||
|
@ -62,9 +63,15 @@ void updateBatteryVoltage(void)
|
||||||
vbat = batteryAdcToVoltage(vbatSampleTotal / BATTERY_SAMPLE_COUNT);
|
vbat = batteryAdcToVoltage(vbatSampleTotal / BATTERY_SAMPLE_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldSoundBatteryAlarm(void)
|
batteryState_e calculateBatteryState(void)
|
||||||
{
|
{
|
||||||
return !((vbat > batteryWarningVoltage) || (vbat < batteryConfig->vbatmincellvoltage));
|
if (vbat <= batteryCriticalVoltage) {
|
||||||
|
return BATTERY_CRITICAL;
|
||||||
|
}
|
||||||
|
if (vbat <= batteryWarningVoltage) {
|
||||||
|
return BATTERY_WARNING;
|
||||||
|
}
|
||||||
|
return BATTERY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void batteryInit(batteryConfig_t *initialBatteryConfig)
|
void batteryInit(batteryConfig_t *initialBatteryConfig)
|
||||||
|
@ -85,7 +92,8 @@ void batteryInit(batteryConfig_t *initialBatteryConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
batteryCellCount = i;
|
batteryCellCount = i;
|
||||||
batteryWarningVoltage = batteryCellCount * batteryConfig->vbatmincellvoltage; // 3.3V per cell minimum, configurable in CLI
|
batteryWarningVoltage = batteryCellCount * batteryConfig->vbatwarningcellvoltage;
|
||||||
|
batteryCriticalVoltage = batteryCellCount * batteryConfig->vbatmincellvoltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADCVREF 33L
|
#define ADCVREF 33L
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
typedef struct batteryConfig_s {
|
typedef struct batteryConfig_s {
|
||||||
uint8_t vbatscale; // adjust this to match battery voltage to reported value
|
uint8_t vbatscale; // adjust this to match battery voltage to reported value
|
||||||
uint8_t vbatmaxcellvoltage; // maximum voltage per cell, used for auto-detecting battery voltage in 0.1V units, default is 43 (4.3V)
|
uint8_t vbatmaxcellvoltage; // maximum voltage per cell, used for auto-detecting battery voltage in 0.1V units, default is 43 (4.3V)
|
||||||
uint8_t vbatmincellvoltage; // minimum voltage per cell, this triggers battery out alarms, in 0.1V units, default is 33 (3.3V)
|
uint8_t vbatmincellvoltage; // minimum voltage per cell, this triggers battery critical alarm, in 0.1V units, default is 33 (3.3V)
|
||||||
|
uint8_t vbatwarningcellvoltage; // warning voltage per cell, this triggers battery warning alarm, in 0.1V units, default is 35 (3.5V)
|
||||||
|
|
||||||
uint16_t currentMeterScale; // scale the current sensor output voltage to milliamps. Value in 1/10th mV/A
|
uint16_t currentMeterScale; // scale the current sensor output voltage to milliamps. Value in 1/10th mV/A
|
||||||
uint16_t currentMeterOffset; // offset of the current sensor in millivolt steps
|
uint16_t currentMeterOffset; // offset of the current sensor in millivolt steps
|
||||||
|
@ -34,6 +35,12 @@ typedef struct batteryConfig_s {
|
||||||
uint16_t batteryCapacity; // mAh
|
uint16_t batteryCapacity; // mAh
|
||||||
} batteryConfig_t;
|
} batteryConfig_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BATTERY_OK = 0,
|
||||||
|
BATTERY_WARNING,
|
||||||
|
BATTERY_CRITICAL
|
||||||
|
} batteryState_e;
|
||||||
|
|
||||||
extern uint8_t vbat;
|
extern uint8_t vbat;
|
||||||
extern uint8_t batteryCellCount;
|
extern uint8_t batteryCellCount;
|
||||||
extern uint16_t batteryWarningVoltage;
|
extern uint16_t batteryWarningVoltage;
|
||||||
|
@ -41,7 +48,7 @@ extern int32_t amperage;
|
||||||
extern int32_t mAhDrawn;
|
extern int32_t mAhDrawn;
|
||||||
|
|
||||||
uint16_t batteryAdcToVoltage(uint16_t src);
|
uint16_t batteryAdcToVoltage(uint16_t src);
|
||||||
bool shouldSoundBatteryAlarm(void);
|
batteryState_e calculateBatteryState(void);
|
||||||
void updateBatteryVoltage(void);
|
void updateBatteryVoltage(void);
|
||||||
void batteryInit(batteryConfig_t *initialBatteryConfig);
|
void batteryInit(batteryConfig_t *initialBatteryConfig);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#define FC_VERSION_MINOR 0 // increment when a minor release is made (small new feature, change etc)
|
#define FC_VERSION_MINOR 0 // increment when a minor release is made (small new feature, change etc)
|
||||||
#define FC_VERSION_PATCH_LEVEL 0 // increment when a bug is fixed
|
#define FC_VERSION_PATCH_LEVEL 0 // increment when a bug is fixed
|
||||||
|
|
||||||
#define MW_VERSION 230
|
#define MW_VERSION 231
|
||||||
|
|
||||||
extern char* targetName;
|
extern char* targetName;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue