1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

Add PID and Rate Profile names

This commit is contained in:
Pieter Kruger 2019-05-01 22:42:45 +10:00
parent 3651bbc03a
commit de5a54a19a
9 changed files with 156 additions and 0 deletions

View file

@ -659,8 +659,56 @@ static void dumpPgValue(const clivalue_t *value, dumpFlags_t dumpMask)
} }
} }
#ifdef USE_PROFILE_NAMES
static void printRateProfileName(uint8_t dumpMask, const profileName_t *rateProfileNameConfig)
{
const bool equalsDefault = strlen(rateProfileNameConfig->name) == 0;
cliDumpPrintLinef(dumpMask, equalsDefault, "rateprofile_name %s", equalsDefault ? emptyName : rateProfileNameConfig->name);
}
static void cliRateProfileName(char *cmdline)
{
const unsigned int len = strlen(cmdline);
uint8_t profileIndex = getCurrentControlRateProfileIndex();
if (len > 0) {
memset(rateProfileNameMutable()->profile[profileIndex].name, 0, ARRAYLEN(rateProfileNameMutable()->profile[profileIndex].name));
if (strncmp(cmdline, emptyName, len)) {
strncpy(rateProfileNameMutable()->profile[profileIndex].name, cmdline, MIN(len, MAX_PROFILE_NAME_LENGTH));
}
}
printRateProfileName(DUMP_MASTER, &rateProfileName()->profile[profileIndex]);
}
static void printPidProfileName(uint8_t dumpMask, const profileName_t *pidProfileNameConfig)
{
const bool equalsDefault = strlen(pidProfileNameConfig->name) == 0;
cliDumpPrintLinef(dumpMask, equalsDefault, "profile_name %s", equalsDefault ? emptyName : pidProfileNameConfig->name);
}
static void cliPidProfileName(char *cmdline)
{
const unsigned int len = strlen(cmdline);
uint8_t profileIndex = getCurrentPidProfileIndex();
if (len > 0) {
memset(pidProfileNameMutable()->profile[profileIndex].name, 0, ARRAYLEN(pidProfileNameMutable()->profile[profileIndex].name));
if (strncmp(cmdline, emptyName, len)) {
strncpy(pidProfileNameMutable()->profile[profileIndex].name, cmdline, MIN(len, MAX_PROFILE_NAME_LENGTH));
}
}
printPidProfileName(DUMP_MASTER, &pidProfileName()->profile[profileIndex]);
}
#endif
static void dumpAllValues(uint16_t valueSection, dumpFlags_t dumpMask) static void dumpAllValues(uint16_t valueSection, dumpFlags_t dumpMask)
{ {
#ifdef USE_PROFILE_NAMES
if (valueSection == PROFILE_VALUE) {
printPidProfileName(DUMP_MASTER, &pidProfileName()->profile[getPidProfileIndexToUse()]);
}
if (valueSection == PROFILE_RATE_VALUE) {
printRateProfileName(DUMP_MASTER, &rateProfileName()->profile[getRateProfileIndexToUse()]);
}
#endif
for (uint32_t i = 0; i < valueTableEntryCount; i++) { for (uint32_t i = 0; i < valueTableEntryCount; i++) {
const clivalue_t *value = &valueTable[i]; const clivalue_t *value = &valueTable[i];
bufWriterFlush(cliWriter); bufWriterFlush(cliWriter);
@ -5767,7 +5815,13 @@ const clicmd_t cmdTable[] = {
CLI_COMMAND_DEF("play_sound", NULL, "[<index>]", cliPlaySound), CLI_COMMAND_DEF("play_sound", NULL, "[<index>]", cliPlaySound),
#endif #endif
CLI_COMMAND_DEF("profile", "change profile", "[<index>]", cliProfile), CLI_COMMAND_DEF("profile", "change profile", "[<index>]", cliProfile),
#ifdef USE_PROFILE_NAMES
CLI_COMMAND_DEF("profile_name", "name of pid profile", NULL, cliPidProfileName),
#endif
CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile), CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile),
#ifdef USE_PROFILE_NAMES
CLI_COMMAND_DEF("rateprofile_name", "name of rate profile", NULL, cliRateProfileName),
#endif
#ifdef USE_RC_SMOOTHING_FILTER #ifdef USE_RC_SMOOTHING_FILTER
CLI_COMMAND_DEF("rc_smoothing_info", "show rc_smoothing operational settings", NULL, cliRcSmoothing), CLI_COMMAND_DEF("rc_smoothing_info", "show rc_smoothing operational settings", NULL, cliRcSmoothing),
#endif // USE_RC_SMOOTHING_FILTER #endif // USE_RC_SMOOTHING_FILTER

View file

@ -1228,6 +1228,11 @@ const clivalue_t valueTable[] = {
{ "osd_stick_overlay_radio_mode", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 4 }, PG_OSD_CONFIG, offsetof(osdConfig_t, overlay_radio_mode) }, { "osd_stick_overlay_radio_mode", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 4 }, PG_OSD_CONFIG, offsetof(osdConfig_t, overlay_radio_mode) },
#endif #endif
#ifdef USE_PROFILE_NAMES
{ "osd_rate_profile_name_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_RATE_PROFILE_NAME]) },
{ "osd_pid_profile_name_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_PID_PROFILE_NAME]) },
#endif
// OSD stats enabled flags are stored as bitmapped values inside a 32bit parameter // OSD stats enabled flags are stored as bitmapped values inside a 32bit parameter
// It is recommended to keep the settings order the same as the enumeration. This way the settings are displayed in the cli in the same order making it easier on the users // It is recommended to keep the settings order the same as the enumeration. This way the settings are displayed in the cli in the same order making it easier on the users
{ "osd_stat_rtc_date_time", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_RTC_DATE_TIME, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)}, { "osd_stat_rtc_date_time", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_RTC_DATE_TIME, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)},

View file

@ -114,6 +114,10 @@ const OSD_Entry menuOsdActiveElemsEntries[] =
{"PITCH PID", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PITCH_PIDS], DYNAMIC}, {"PITCH PID", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PITCH_PIDS], DYNAMIC},
{"YAW PID", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_YAW_PIDS], DYNAMIC}, {"YAW PID", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_YAW_PIDS], DYNAMIC},
{"PROFILES", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PIDRATE_PROFILE], DYNAMIC}, {"PROFILES", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PIDRATE_PROFILE], DYNAMIC},
#ifdef USE_PROFILE_NAMES
{"PID PROFILE NAME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PID_PROFILE_NAME], DYNAMIC},
{"RATE PROFILE NAME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_RATE_PROFILE_NAME], DYNAMIC},
#endif
{"DEBUG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DEBUG], DYNAMIC}, {"DEBUG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DEBUG], DYNAMIC},
{"WARNINGS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_WARNINGS], DYNAMIC}, {"WARNINGS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_WARNINGS], DYNAMIC},
{"DISARMED", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DISARMED], DYNAMIC}, {"DISARMED", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DISARMED], DYNAMIC},

View file

@ -22,6 +22,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <common/printf.h>
#include "platform.h" #include "platform.h"
@ -86,6 +87,10 @@ PG_RESET_TEMPLATE(pilotConfig_t, pilotConfig,
.displayName = { 0 }, .displayName = { 0 },
); );
PG_REGISTER_WITH_RESET_FN(rateProfileNameConfig_t, rateProfileName, PG_RATE_PROFILE_NAMES_CONFIG, 1);
PG_REGISTER_WITH_RESET_FN(pidProfileNameConfig_t, pidProfileName, PG_PID_PROFILE_NAMES_CONFIG, 1);
PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 2); PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 2);
PG_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
@ -121,6 +126,22 @@ uint16_t getCurrentMinthrottle(void)
return motorConfig()->minthrottle; return motorConfig()->minthrottle;
} }
void pgResetFn_rateProfileName(rateProfileNameConfig_t *rateProfileName)
{
for (int i = 0; i < CONTROL_RATE_PROFILE_COUNT; i++) {
tfp_sprintf(rateProfileName->profile[i].name, "RATE %u", i+1, MAX_PROFILE_NAME_LENGTH);
}
}
void pgResetFn_pidProfileName(pidProfileNameConfig_t *pidProfileName)
{
for (int i = 0; i < PID_PROFILE_COUNT; i++) {
tfp_sprintf(pidProfileName->profile[i].name, "PID %u", i+1, MAX_PROFILE_NAME_LENGTH);
}
}
void resetConfigs(void) void resetConfigs(void)
{ {
pgResetAll(); pgResetAll();

View file

@ -27,6 +27,8 @@
#define MAX_NAME_LENGTH 16u #define MAX_NAME_LENGTH 16u
#define MAX_PROFILE_NAME_LENGTH 8u
typedef struct pilotConfig_s { typedef struct pilotConfig_s {
char name[MAX_NAME_LENGTH + 1]; char name[MAX_NAME_LENGTH + 1];
char displayName[MAX_NAME_LENGTH + 1]; char displayName[MAX_NAME_LENGTH + 1];
@ -34,6 +36,22 @@ typedef struct pilotConfig_s {
PG_DECLARE(pilotConfig_t, pilotConfig); PG_DECLARE(pilotConfig_t, pilotConfig);
typedef struct profileName_s {
char name[MAX_PROFILE_NAME_LENGTH + 1];
} profileName_t;
typedef struct rateProfileNameConfig_s {
profileName_t profile[CONTROL_RATE_PROFILE_COUNT];
} rateProfileNameConfig_t;
PG_DECLARE(rateProfileNameConfig_t, rateProfileName);
typedef struct pidProfileNameConfig_s {
profileName_t profile[PID_PROFILE_COUNT];
} pidProfileNameConfig_t;
PG_DECLARE(pidProfileNameConfig_t, pidProfileName);
typedef struct systemConfig_s { typedef struct systemConfig_s {
uint8_t pidProfileIndex; uint8_t pidProfileIndex;
uint8_t activeRateProfile; uint8_t activeRateProfile;

View file

@ -126,6 +126,8 @@ typedef enum {
OSD_STICK_OVERLAY_RIGHT, OSD_STICK_OVERLAY_RIGHT,
OSD_DISPLAY_NAME, OSD_DISPLAY_NAME,
OSD_ESC_RPM_FREQ, OSD_ESC_RPM_FREQ,
OSD_RATE_PROFILE_NAME,
OSD_PID_PROFILE_NAME,
OSD_ITEM_COUNT // MUST BE LAST OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e; } osd_items_e;

View file

@ -647,6 +647,46 @@ static void osdElementDisplayName(osdElementParms_t *element)
} }
} }
#ifdef USE_PROFILE_NAMES
static void osdElementRateProfileName(osdElementParms_t *element)
{
uint8_t rateProfileIndex = getCurrentControlRateProfileIndex();
if (strlen(rateProfileName()->profile[rateProfileIndex].name) == 0) {
tfp_sprintf(element->buff, "RATE_%u", rateProfileIndex);
} else {
unsigned i;
for (i = 0; i < MAX_PROFILE_NAME_LENGTH; i++) {
if (rateProfileName()->profile[rateProfileIndex].name[i]) {
element->buff[i] = toupper((unsigned char)rateProfileName()->profile[rateProfileIndex].name[i]);
} else {
break;
}
}
element->buff[i] = '\0';
}
}
static void osdElementPidProfileName(osdElementParms_t *element)
{
uint8_t pidProfileIndex = getCurrentPidProfileIndex();
if (strlen(pidProfileName()->profile[pidProfileIndex].name) == 0) {
tfp_sprintf(element->buff, "PID_%u", pidProfileIndex);
} else {
unsigned i;
for (i = 0; i < MAX_PROFILE_NAME_LENGTH; i++) {
if (pidProfileName()->profile[pidProfileIndex].name[i]) {
element->buff[i] = toupper((unsigned char)pidProfileName()->profile[pidProfileIndex].name[i]);
} else {
break;
}
}
element->buff[i] = '\0';
}
}
#endif
#ifdef USE_ESC_SENSOR #ifdef USE_ESC_SENSOR
static void osdElementEscTemperature(osdElementParms_t *element) static void osdElementEscTemperature(osdElementParms_t *element)
{ {
@ -1333,6 +1373,10 @@ static const uint8_t osdElementDisplayOrder[] = {
OSD_STICK_OVERLAY_LEFT, OSD_STICK_OVERLAY_LEFT,
OSD_STICK_OVERLAY_RIGHT, OSD_STICK_OVERLAY_RIGHT,
#endif #endif
#ifdef USE_PROFILE_NAMES
OSD_RATE_PROFILE_NAME,
OSD_PID_PROFILE_NAME,
#endif
}; };
// Define the mapping between the OSD element id and the function to draw it // Define the mapping between the OSD element id and the function to draw it
@ -1428,6 +1472,11 @@ const osdElementDrawFn osdElementDrawFunction[OSD_ITEM_COUNT] = {
#if defined(USE_RPM_FILTER) || defined(USE_ESC_SENSOR) #if defined(USE_RPM_FILTER) || defined(USE_ESC_SENSOR)
[OSD_ESC_RPM_FREQ] = osdElementEscRpmFreq, [OSD_ESC_RPM_FREQ] = osdElementEscRpmFreq,
#endif #endif
#ifdef USE_PROFILE_NAMES
[OSD_RATE_PROFILE_NAME] = osdElementRateProfileName,
[OSD_PID_PROFILE_NAME] = osdElementPidProfileName,
#endif
}; };
static void osdAddActiveElement(osd_items_e element) static void osdAddActiveElement(osd_items_e element)

View file

@ -81,6 +81,8 @@
#define PG_GPS_RESCUE 55 // struct OK #define PG_GPS_RESCUE 55 // struct OK
#define PG_POSITION 56 #define PG_POSITION 56
#define PG_VTX_IO_CONFIG 57 #define PG_VTX_IO_CONFIG 57
#define PG_RATE_PROFILE_NAMES_CONFIG 58
#define PG_PID_PROFILE_NAMES_CONFIG 59
// Driver configuration // Driver configuration
#define PG_DRIVER_PWM_RX_CONFIG 100 // does not exist in betaflight #define PG_DRIVER_PWM_RX_CONFIG 100 // does not exist in betaflight

View file

@ -307,5 +307,6 @@
#define USE_TELEMETRY_SENSORS_DISABLED_DETAILS #define USE_TELEMETRY_SENSORS_DISABLED_DETAILS
#define USE_VTX_TABLE #define USE_VTX_TABLE
#define USE_PERSISTENT_STATS #define USE_PERSISTENT_STATS
#define USE_PROFILE_NAMES
#endif #endif