Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/Controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ The stick positions are combined to activate different functions:
| Profile 1 | LOW | LOW | CENTER | LOW |
| Profile 2 | LOW | LOW | HIGH | CENTER |
| Profile 3 | LOW | LOW | CENTER | HIGH |
| Battery profile 1 | HIGH | LOW | CENTER | LOW |
| Battery profile 2 | HIGH | LOW | HIGH | CENTER |
| Battery profile 3 | HIGH | LOW | CENTER | HIGH |
| Calibrate Gyro | LOW | LOW | LOW | CENTER |
| Calibrate Acc | HIGH | LOW | LOW | CENTER |
| Calibrate Mag/Compass | HIGH | HIGH | LOW | CENTER |
Expand Down
Binary file modified docs/assets/images/StickPositions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
485 changes: 299 additions & 186 deletions docs/assets/images/StickPositions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions make/source.mk
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ COMMON_SRC = \
blackbox/blackbox_encoding.c \
blackbox/blackbox_io.c \
cms/cms.c \
cms/cms_menu_battery.c \
cms/cms_menu_blackbox.c \
cms/cms_menu_builtin.c \
cms/cms_menu_imu.c \
Expand Down
14 changes: 7 additions & 7 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
return feature(FEATURE_VBAT);

case FLIGHT_LOG_FIELD_CONDITION_AMPERAGE_ADC:
return feature(FEATURE_CURRENT_METER) && batteryConfig()->current.type == CURRENT_SENSOR_ADC;
return feature(FEATURE_CURRENT_METER) && batteryMetersConfig()->current.type == CURRENT_SENSOR_ADC;

case FLIGHT_LOG_FIELD_CONDITION_SURFACE:
#ifdef USE_RANGEFINDER
Expand Down Expand Up @@ -1355,21 +1355,21 @@ static bool blackboxWriteSysinfo(void)

BLACKBOX_PRINT_HEADER_LINE_CUSTOM(
if (testBlackboxCondition(FLIGHT_LOG_FIELD_CONDITION_VBAT)) {
blackboxPrintfHeaderLine("vbat_scale", "%u", batteryConfig()->voltage.scale / 10);
blackboxPrintfHeaderLine("vbat_scale", "%u", batteryMetersConfig()->voltage_scale / 10);
} else {
xmitState.headerIndex += 2; // Skip the next two vbat fields too
}
);
BLACKBOX_PRINT_HEADER_LINE("vbatcellvoltage", "%u,%u,%u", batteryConfig()->voltage.cellMin / 10,
batteryConfig()->voltage.cellWarning / 10,
batteryConfig()->voltage.cellMax / 10);
BLACKBOX_PRINT_HEADER_LINE("vbatcellvoltage", "%u,%u,%u", currentBatteryProfile->voltage.cellMin / 10,
currentBatteryProfile->voltage.cellWarning / 10,
currentBatteryProfile->voltage.cellMax / 10);
BLACKBOX_PRINT_HEADER_LINE("vbatref", "%u", vbatReference);

BLACKBOX_PRINT_HEADER_LINE_CUSTOM(
//Note: Log even if this is a virtual current meter, since the virtual meter uses these parameters too:
if (feature(FEATURE_CURRENT_METER)) {
blackboxPrintfHeaderLine("currentMeter", "%d,%d", batteryConfig()->current.offset,
batteryConfig()->current.scale);
blackboxPrintfHeaderLine("currentMeter", "%d,%d", batteryMetersConfig()->current.offset,
batteryMetersConfig()->current.scale);
}
);

Expand Down
141 changes: 141 additions & 0 deletions src/main/cms/cms_menu_battery.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight 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.
*
* Cleanflight 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 Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdbool.h>
#include <stdint.h>

#include "platform.h"

#ifdef USE_CMS

#include "common/utils.h"

#include "cms/cms.h"
#include "cms/cms_types.h"
#include "cms/cms_menu_misc.h"

#include "fc/config.h"
#include "fc/rc_controls.h"

#include "sensors/battery.h"

// Battery menu

static uint8_t battDispProfileIndex;
static uint8_t battProfileIndex;
static char battProfileIndexString[] = " p";


static long cmsx_menuBattery_onEnter(const OSD_Entry *from)
{
UNUSED(from);

battProfileIndex = getConfigBatteryProfile();
battDispProfileIndex = battProfileIndex + 1;
battProfileIndexString[1] = '0' + battDispProfileIndex;

return 0;
}

static long cmsx_menuBattery_onExit(const OSD_Entry *self)
{
UNUSED(self);

setConfigBatteryProfile(battProfileIndex);
activateBatteryProfile();

return 0;
}

static long cmsx_onBatteryProfileIndexChange(displayPort_t *displayPort, const void *ptr)
{
UNUSED(displayPort);
UNUSED(ptr);

battProfileIndex = battDispProfileIndex - 1;
battProfileIndexString[1] = '0' + battDispProfileIndex;
batteryDisableProfileAutoswitch();

return 0;
}

static long cmsx_menuBattSettings_onEnter(const OSD_Entry *from)
{
UNUSED(from);

setConfigBatteryProfile(battProfileIndex);

return 0;
}

static const OSD_Entry menuBattSettingsEntries[]=
{
OSD_LABEL_DATA_ENTRY("-- BATT SETTINGS --", battProfileIndexString),

#ifdef USE_ADC
OSD_SETTING_ENTRY("CELLS", SETTING_BAT_CELLS),
OSD_SETTING_ENTRY("CELL DET.", SETTING_VBAT_CELL_DETECT_VOLTAGE),
OSD_SETTING_ENTRY("CELL MAX", SETTING_VBAT_MAX_CELL_VOLTAGE),
OSD_SETTING_ENTRY("CELL WARN", SETTING_VBAT_WARNING_CELL_VOLTAGE),
OSD_SETTING_ENTRY("CELL MIN", SETTING_VBAT_MIN_CELL_VOLTAGE),
#endif /* USE_ADC */
OSD_SETTING_ENTRY("CAP UNIT", SETTING_BATTERY_CAPACITY_UNIT),
OSD_SETTING_ENTRY("CAPACITY", SETTING_BATTERY_CAPACITY),
OSD_SETTING_ENTRY("CAP WARN", SETTING_BATTERY_CAPACITY_WARNING),
OSD_SETTING_ENTRY("CAP CRIT", SETTING_BATTERY_CAPACITY_CRITICAL),

OSD_BACK_ENTRY,
OSD_END_ENTRY
};

static CMS_Menu cmsx_menuBattSettings = {
#ifdef CMS_MENU_DEBUG
.GUARD_text = "XBATT",
.GUARD_type = OME_MENU,
#endif
.onEnter = cmsx_menuBattSettings_onEnter,
.onExit = NULL,
.onGlobalExit = NULL,
.entries = menuBattSettingsEntries
};

static OSD_Entry menuBatteryEntries[]=
{
OSD_LABEL_ENTRY("-- BATTERY --"),

#ifdef USE_ADC
OSD_SETTING_ENTRY("PROF AUTOSWITCH", SETTING_BAT_PROFILE_AUTOSWITCH),
#endif
OSD_UINT8_CALLBACK_ENTRY("PROF", cmsx_onBatteryProfileIndexChange, (&(const OSD_UINT8_t){ &battDispProfileIndex, 1, MAX_BATTERY_PROFILE_COUNT, 1})),
OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuBattSettings),

OSD_BACK_ENTRY,
OSD_END_ENTRY
};

CMS_Menu cmsx_menuBattery = {
#ifdef CMS_MENU_DEBUG
.GUARD_text = "XBATT",
.GUARD_type = OME_MENU,
#endif
.onEnter = cmsx_menuBattery_onEnter,
.onExit = cmsx_menuBattery_onExit,
.onGlobalExit = NULL,
.entries = menuBatteryEntries
};

#endif // CMS
20 changes: 20 additions & 0 deletions src/main/cms/cms_menu_battery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight 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.
*
* Cleanflight 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 Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

extern CMS_Menu cmsx_menuBattery;
2 changes: 2 additions & 0 deletions src/main/cms/cms_menu_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "cms/cms_menu_vtx.h"
#include "cms/cms_menu_osd.h"
#include "cms/cms_menu_ledstrip.h"
#include "cms/cms_menu_battery.h"
#include "cms/cms_menu_misc.h"

// VTX supplied menus
Expand Down Expand Up @@ -150,6 +151,7 @@ static const OSD_Entry menuMainEntries[] =
OSD_SUBMENU_ENTRY("OSD LAYOUTS", &cmsx_menuOsdLayout),
OSD_SUBMENU_ENTRY("ALARMS", &cmsx_menuAlarms),
#endif
OSD_SUBMENU_ENTRY("BATTERY", &cmsx_menuBattery),
OSD_SUBMENU_ENTRY("FC&FW INFO", &menuInfo),
OSD_SUBMENU_ENTRY("MISC", &cmsx_menuMisc),

Expand Down
3 changes: 2 additions & 1 deletion src/main/config/parameter_group_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//#define PG_SENSOR_ALIGNMENT_CONFIG 8 -- NOT USED in iNav
//#define PG_SENSOR_TRIMS 9 -- NOT USED in iNav
#define PG_GYRO_CONFIG 10
#define PG_BATTERY_CONFIG 11
#define PG_BATTERY_PROFILES 11
#define PG_CONTROL_RATE_PROFILES 12
#define PG_SERIAL_CONFIG 13
#define PG_PID_PROFILE 14
Expand Down Expand Up @@ -63,6 +63,7 @@
#define PG_SERVO_PARAMS 42
//#define PG_RX_FAILSAFE_CHANNEL_CONFIG 43
#define PG_RX_CHANNEL_RANGE_CONFIG 44
#define PG_BATTERY_METERS_CONFIG 45
//#define PG_MODE_COLOR_CONFIG 45
//#define PG_SPECIAL_COLOR_CONFIG 46
//#define PG_PILOT_CONFIG 47
Expand Down
62 changes: 54 additions & 8 deletions src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ static void cliPutp(void *p, char ch)
typedef enum {
DUMP_MASTER = (1 << 0),
DUMP_PROFILE = (1 << 1),
DUMP_RATES = (1 << 2),
DUMP_ALL = (1 << 3),
DO_DIFF = (1 << 4),
SHOW_DEFAULTS = (1 << 5),
HIDE_UNUSED = (1 << 6)
DUMP_BATTERY_PROFILE = (1 << 2),
DUMP_RATES = (1 << 3),
DUMP_ALL = (1 << 4),
DO_DIFF = (1 << 5),
SHOW_DEFAULTS = (1 << 6),
HIDE_UNUSED = (1 << 7)
} dumpFlags_e;

static void cliPrintfva(const char *format, va_list va)
Expand Down Expand Up @@ -2203,6 +2204,33 @@ static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask)
dumpAllValues(CONTROL_RATE_VALUE, dumpMask);
}

static void cliBatteryProfile(char *cmdline)
{
// CLI profile index is 1-based
if (isEmpty(cmdline)) {
cliPrintLinef("battery_profile %d", getConfigBatteryProfile() + 1);
return;
} else {
const int i = fastA2I(cmdline) - 1;
if (i >= 0 && i < MAX_PROFILE_COUNT) {
setConfigBatteryProfileAndWriteEEPROM(i);
cliBatteryProfile("");
}
}
}

static void cliDumpBatteryProfile(uint8_t profileIndex, uint8_t dumpMask)
{
if (profileIndex >= MAX_BATTERY_PROFILE_COUNT) {
// Faulty values
return;
}
setConfigBatteryProfile(profileIndex);
cliPrintHashLine("battery_profile");
cliPrintLinef("battery_profile %d\r\n", getConfigBatteryProfile() + 1);
dumpAllValues(BATTERY_CONFIG_VALUE, dumpMask);
}

static void cliSave(char *cmdline)
{
UNUSED(cmdline);
Expand Down Expand Up @@ -2583,6 +2611,8 @@ static void printConfig(const char *cmdline, bool doDiff)
dumpMask = DUMP_MASTER; // only
} else if ((options = checkCommand(cmdline, "profile"))) {
dumpMask = DUMP_PROFILE; // only
} else if ((options = checkCommand(cmdline, "battery_profile"))) {
dumpMask = DUMP_BATTERY_PROFILE; // only
} else if ((options = checkCommand(cmdline, "all"))) {
dumpMask = DUMP_ALL; // all profiles and rates
} else {
Expand All @@ -2594,11 +2624,13 @@ static void printConfig(const char *cmdline, bool doDiff)
}

const int currentProfileIndexSave = getConfigProfile();
const int currentBatteryProfileIndexSave = getConfigBatteryProfile();
backupConfigs();
// reset all configs to defaults to do differencing
resetConfigs();
// restore the profile indices, since they should not be reset for proper comparison
setConfigProfile(currentProfileIndexSave);
setConfigBatteryProfile(currentBatteryProfileIndexSave);

if (checkCommand(options, "showdefaults")) {
dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values
Expand Down Expand Up @@ -2681,23 +2713,35 @@ static void printConfig(const char *cmdline, bool doDiff)
if (dumpMask & DUMP_ALL) {
// dump all profiles
const int currentProfileIndexSave = getConfigProfile();
const int currentBatteryProfileIndexSave = getConfigBatteryProfile();
for (int ii = 0; ii < MAX_PROFILE_COUNT; ++ii) {
cliDumpProfile(ii, dumpMask);
}
for (int ii = 0; ii < MAX_BATTERY_PROFILE_COUNT; ++ii) {
cliDumpBatteryProfile(ii, dumpMask);
}
setConfigProfile(currentProfileIndexSave);
setConfigBatteryProfile(currentBatteryProfileIndexSave);

cliPrintHashLine("restore original profile selection");
cliPrintLinef("profile %d", currentProfileIndexSave + 1);
cliPrintLinef("battery_profile %d", currentBatteryProfileIndexSave + 1);

cliPrintHashLine("save configuration\r\nsave");
} else {
// dump just the current profile
// dump just the current profiles
cliDumpProfile(getConfigProfile(), dumpMask);
cliDumpBatteryProfile(getConfigBatteryProfile(), dumpMask);
}
}

if (dumpMask & DUMP_PROFILE) {
cliDumpProfile(getConfigProfile(), dumpMask);
}

if (dumpMask & DUMP_BATTERY_PROFILE) {
cliDumpBatteryProfile(getConfigBatteryProfile(), dumpMask);
}
// restore configs from copies
restoreConfigs();
}
Expand Down Expand Up @@ -2760,9 +2804,9 @@ const clicmd_t cmdTable[] = {
CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", NULL, cliDefaults),
CLI_COMMAND_DEF("dfu", "DFU mode on reboot", NULL, cliDfu),
CLI_COMMAND_DEF("diff", "list configuration changes from default",
"[master|profile|rates|all] {showdefaults}", cliDiff),
"[master|battery_profile|profile|rates|all] {showdefaults}", cliDiff),
CLI_COMMAND_DEF("dump", "dump configuration",
"[master|profile|rates|all] {showdefaults}", cliDump),
"[master|battery_profile|profile|rates|all] {showdefaults}", cliDump),
#ifdef USE_RX_ELERES
CLI_COMMAND_DEF("eleres_bind", NULL, NULL, cliEleresBind),
#endif // USE_RX_ELERES
Expand Down Expand Up @@ -2796,6 +2840,8 @@ const clicmd_t cmdTable[] = {
#endif
CLI_COMMAND_DEF("profile", "change profile",
"[<index>]", cliProfile),
CLI_COMMAND_DEF("battery_profile", "change battery profile",
"[<index>]", cliBatteryProfile),
#if !defined(SKIP_TASK_STATISTICS) && !defined(SKIP_CLI_RESOURCES)
CLI_COMMAND_DEF("resource", "view currently used resources", NULL, cliResource),
#endif
Expand Down
Loading