From de5a54a19ab7583abef0feb3f8b7f79c6f04c10b Mon Sep 17 00:00:00 2001 From: Pieter Kruger Date: Wed, 1 May 2019 22:42:45 +1000 Subject: [PATCH] Add PID and Rate Profile names --- src/main/cli/cli.c | 54 ++++++++++++++++++++++++++++++++++++ src/main/cli/settings.c | 5 ++++ src/main/cms/cms_menu_osd.c | 4 +++ src/main/fc/config.c | 21 ++++++++++++++ src/main/fc/config.h | 18 ++++++++++++ src/main/osd/osd.h | 2 ++ src/main/osd/osd_elements.c | 49 ++++++++++++++++++++++++++++++++ src/main/pg/pg_ids.h | 2 ++ src/main/target/common_pre.h | 1 + 9 files changed, 156 insertions(+) diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index bed23bdbd4..c6d6ec367c 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -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) { +#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++) { const clivalue_t *value = &valueTable[i]; bufWriterFlush(cliWriter); @@ -5767,7 +5815,13 @@ const clicmd_t cmdTable[] = { CLI_COMMAND_DEF("play_sound", NULL, "[]", cliPlaySound), #endif CLI_COMMAND_DEF("profile", "change profile", "[]", cliProfile), +#ifdef USE_PROFILE_NAMES + CLI_COMMAND_DEF("profile_name", "name of pid profile", NULL, cliPidProfileName), +#endif CLI_COMMAND_DEF("rateprofile", "change rate profile", "[]", cliRateProfile), +#ifdef USE_PROFILE_NAMES + CLI_COMMAND_DEF("rateprofile_name", "name of rate profile", NULL, cliRateProfileName), +#endif #ifdef USE_RC_SMOOTHING_FILTER CLI_COMMAND_DEF("rc_smoothing_info", "show rc_smoothing operational settings", NULL, cliRcSmoothing), #endif // USE_RC_SMOOTHING_FILTER diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index 33660bb171..a00674b945 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -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) }, #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 // 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)}, diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index 800336a1e4..d5145ba2eb 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -114,6 +114,10 @@ const OSD_Entry menuOsdActiveElemsEntries[] = {"PITCH PID", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PITCH_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}, +#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}, {"WARNINGS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_WARNINGS], DYNAMIC}, {"DISARMED", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DISARMED], DYNAMIC}, diff --git a/src/main/fc/config.c b/src/main/fc/config.c index a6f726e50f..d582cfd58c 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "platform.h" @@ -86,6 +87,10 @@ PG_RESET_TEMPLATE(pilotConfig_t, pilotConfig, .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_RESET_TEMPLATE(systemConfig_t, systemConfig, @@ -121,6 +126,22 @@ uint16_t getCurrentMinthrottle(void) 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) { pgResetAll(); diff --git a/src/main/fc/config.h b/src/main/fc/config.h index 44c265566f..21bd8090c3 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -27,6 +27,8 @@ #define MAX_NAME_LENGTH 16u +#define MAX_PROFILE_NAME_LENGTH 8u + typedef struct pilotConfig_s { char name[MAX_NAME_LENGTH + 1]; char displayName[MAX_NAME_LENGTH + 1]; @@ -34,6 +36,22 @@ typedef struct pilotConfig_s { 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 { uint8_t pidProfileIndex; uint8_t activeRateProfile; diff --git a/src/main/osd/osd.h b/src/main/osd/osd.h index f86ccdc41d..603bfed972 100644 --- a/src/main/osd/osd.h +++ b/src/main/osd/osd.h @@ -126,6 +126,8 @@ typedef enum { OSD_STICK_OVERLAY_RIGHT, OSD_DISPLAY_NAME, OSD_ESC_RPM_FREQ, + OSD_RATE_PROFILE_NAME, + OSD_PID_PROFILE_NAME, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; diff --git a/src/main/osd/osd_elements.c b/src/main/osd/osd_elements.c index 136ae34723..a523ea463c 100644 --- a/src/main/osd/osd_elements.c +++ b/src/main/osd/osd_elements.c @@ -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 static void osdElementEscTemperature(osdElementParms_t *element) { @@ -1333,6 +1373,10 @@ static const uint8_t osdElementDisplayOrder[] = { OSD_STICK_OVERLAY_LEFT, OSD_STICK_OVERLAY_RIGHT, #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 @@ -1428,6 +1472,11 @@ const osdElementDrawFn osdElementDrawFunction[OSD_ITEM_COUNT] = { #if defined(USE_RPM_FILTER) || defined(USE_ESC_SENSOR) [OSD_ESC_RPM_FREQ] = osdElementEscRpmFreq, #endif +#ifdef USE_PROFILE_NAMES + [OSD_RATE_PROFILE_NAME] = osdElementRateProfileName, + [OSD_PID_PROFILE_NAME] = osdElementPidProfileName, +#endif + }; static void osdAddActiveElement(osd_items_e element) diff --git a/src/main/pg/pg_ids.h b/src/main/pg/pg_ids.h index 2347d554e1..99990d9fbe 100644 --- a/src/main/pg/pg_ids.h +++ b/src/main/pg/pg_ids.h @@ -81,6 +81,8 @@ #define PG_GPS_RESCUE 55 // struct OK #define PG_POSITION 56 #define PG_VTX_IO_CONFIG 57 +#define PG_RATE_PROFILE_NAMES_CONFIG 58 +#define PG_PID_PROFILE_NAMES_CONFIG 59 // Driver configuration #define PG_DRIVER_PWM_RX_CONFIG 100 // does not exist in betaflight diff --git a/src/main/target/common_pre.h b/src/main/target/common_pre.h index 17785b20d0..bbd63b5387 100644 --- a/src/main/target/common_pre.h +++ b/src/main/target/common_pre.h @@ -307,5 +307,6 @@ #define USE_TELEMETRY_SENSORS_DISABLED_DETAILS #define USE_VTX_TABLE #define USE_PERSISTENT_STATS +#define USE_PROFILE_NAMES #endif