mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Copy profile to another profile (CLI, MSP and CMS)
This commit is contained in:
parent
c750918e8b
commit
d32abc69f8
8 changed files with 142 additions and 0 deletions
|
@ -391,6 +391,73 @@ static CMS_Menu cmsx_menuFilterPerProfile = {
|
|||
.entries = cmsx_menuFilterPerProfileEntries,
|
||||
};
|
||||
|
||||
static uint8_t cmsx_dstPidProfile;
|
||||
static uint8_t cmsx_dstControlRateProfile;
|
||||
|
||||
static const char * const cmsx_ProfileNames[] = {
|
||||
"-",
|
||||
"1",
|
||||
"2",
|
||||
"3"
|
||||
};
|
||||
|
||||
static OSD_TAB_t cmsx_PidProfileTable = { &cmsx_dstPidProfile, 3, cmsx_ProfileNames };
|
||||
static OSD_TAB_t cmsx_ControlRateProfileTable = { &cmsx_dstControlRateProfile, 3, cmsx_ProfileNames };
|
||||
|
||||
static long cmsx_menuCopyProfile_onEnter(void)
|
||||
{
|
||||
cmsx_dstPidProfile = 0;
|
||||
cmsx_dstControlRateProfile = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long cmsx_CopyPidProfile(displayPort_t *pDisplay, const void *ptr)
|
||||
{
|
||||
UNUSED(pDisplay);
|
||||
UNUSED(ptr);
|
||||
|
||||
if (cmsx_dstPidProfile > 0) {
|
||||
copyPidProfile(cmsx_dstPidProfile - 1, getCurrentPidProfileIndex());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long cmsx_CopyControlRateProfile(displayPort_t *pDisplay, const void *ptr)
|
||||
{
|
||||
UNUSED(pDisplay);
|
||||
UNUSED(ptr);
|
||||
|
||||
if (cmsx_dstControlRateProfile > 0) {
|
||||
copyControlRateProfile(cmsx_dstControlRateProfile - 1, getCurrentControlRateProfileIndex());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static OSD_Entry cmsx_menuCopyProfileEntries[] =
|
||||
{
|
||||
{ "-- COPY PROFILE --", OME_Label, NULL, NULL, 0},
|
||||
|
||||
{ "CPY PID PROF TO", OME_TAB, NULL, &cmsx_PidProfileTable, 0 },
|
||||
{ "COPY PP", OME_Funcall, cmsx_CopyPidProfile, NULL, 0 },
|
||||
{ "CPY RATE PROF TO", OME_TAB, NULL, &cmsx_ControlRateProfileTable, 0 },
|
||||
{ "COPY RP", OME_Funcall, cmsx_CopyControlRateProfile, NULL, 0 },
|
||||
|
||||
{ "BACK", OME_Back, NULL, NULL, 0 },
|
||||
{ NULL, OME_END, NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
CMS_Menu cmsx_menuCopyProfile = {
|
||||
.GUARD_text = "XCPY",
|
||||
.GUARD_type = OME_MENU,
|
||||
.onEnter = cmsx_menuCopyProfile_onEnter,
|
||||
.onExit = NULL,
|
||||
.onGlobalExit = NULL,
|
||||
.entries = cmsx_menuCopyProfileEntries,
|
||||
};
|
||||
|
||||
static OSD_Entry cmsx_menuImuEntries[] =
|
||||
{
|
||||
{ "-- IMU --", OME_Label, NULL, NULL, 0},
|
||||
|
@ -404,6 +471,7 @@ static OSD_Entry cmsx_menuImuEntries[] =
|
|||
{"RATE", OME_Submenu, cmsMenuChange, &cmsx_menuRateProfile, 0},
|
||||
|
||||
{"FILT GLB", OME_Submenu, cmsMenuChange, &cmsx_menuFilterGlobal, 0},
|
||||
{"COPY PROF", OME_Submenu, cmsMenuChange, &cmsx_menuCopyProfile, 0},
|
||||
|
||||
{"BACK", OME_Back, NULL, NULL, 0},
|
||||
{NULL, OME_END, NULL, NULL, 0}
|
||||
|
@ -417,4 +485,5 @@ CMS_Menu cmsx_menuImu = {
|
|||
.onGlobalExit = NULL,
|
||||
.entries = cmsx_menuImuEntries,
|
||||
};
|
||||
|
||||
#endif // CMS
|
||||
|
|
|
@ -3266,6 +3266,44 @@ static void cliResource(char *cmdline)
|
|||
}
|
||||
#endif /* USE_RESOURCE_MGMT */
|
||||
|
||||
static void cliCopyProfile(char *cmdline)
|
||||
{
|
||||
if (isEmpty(cmdline)) {
|
||||
cliShowParseError();
|
||||
} else {
|
||||
const int id = atoi(cmdline); // id = target profile id
|
||||
if (id < 0 || id > MAX_PROFILE_COUNT-1) {
|
||||
cliPrintLinef("Invalid profile id, choose [0-%d]", MAX_PROFILE_COUNT-1);
|
||||
} else {
|
||||
if (id == getCurrentPidProfileIndex()) {
|
||||
cliPrintLine("Can not overwrite current selected profile");
|
||||
} else {
|
||||
copyPidProfile(id, getCurrentPidProfileIndex());
|
||||
cliPrintLinef("Copied profile settings from %d to %d", getCurrentPidProfileIndex(), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cliCopyRateProfile(char *cmdline)
|
||||
{
|
||||
if (isEmpty(cmdline)) {
|
||||
cliShowParseError();
|
||||
} else {
|
||||
const int id = atoi(cmdline); // id = target rateprofile id
|
||||
if (id < 0 || id > CONTROL_RATE_PROFILE_COUNT-1) {
|
||||
cliPrintLinef("Invalid rateprofile id, choose [0-%d]", CONTROL_RATE_PROFILE_COUNT-1);
|
||||
} else {
|
||||
if (id == getCurrentControlRateProfileIndex()) {
|
||||
cliPrintLine("Can not overwrite current selected rateprofile");
|
||||
} else {
|
||||
copyControlRateProfile(id, getCurrentControlRateProfileIndex());
|
||||
cliPrintLinef("Copied rateprofile settings from %d to %d", getCurrentControlRateProfileIndex(), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void backupConfigs(void)
|
||||
{
|
||||
// make copies of configs to do differencing
|
||||
|
@ -3564,6 +3602,8 @@ const clicmd_t cmdTable[] = {
|
|||
#ifdef VTX_CONTROL
|
||||
CLI_COMMAND_DEF("vtx", "vtx channels on switch", NULL, cliVtx),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("copyprofile", "copy current profile settings to another profile", "<id> : target profile id", cliCopyProfile),
|
||||
CLI_COMMAND_DEF("copyrateprofile", "copy current rateprofile settings to another rateprofile", "<id> : target rate profile id", cliCopyRateProfile),
|
||||
};
|
||||
static void cliHelp(char *cmdline)
|
||||
{
|
||||
|
|
|
@ -71,3 +71,11 @@ void changeControlRateProfile(uint8_t controlRateProfileIndex)
|
|||
setControlRateProfile(controlRateProfileIndex);
|
||||
generateThrottleCurve();
|
||||
}
|
||||
|
||||
void copyControlRateProfile(const uint8_t dstControlRateProfileIndex, const uint8_t srcControlRateProfileIndex) {
|
||||
if ((dstControlRateProfileIndex < CONTROL_RATE_PROFILE_COUNT-1 && srcControlRateProfileIndex < CONTROL_RATE_PROFILE_COUNT-1)
|
||||
&& dstControlRateProfileIndex != srcControlRateProfileIndex
|
||||
) {
|
||||
memcpy(controlRateProfilesMutable(dstControlRateProfileIndex), controlRateProfilesMutable(srcControlRateProfileIndex), sizeof(controlRateConfig_t));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,3 +41,5 @@ extern controlRateConfig_t *currentControlRateProfile;
|
|||
|
||||
void setControlRateProfile(uint8_t controlRateProfileIndex);
|
||||
void changeControlRateProfile(uint8_t controlRateProfileIndex);
|
||||
|
||||
void copyControlRateProfile(const uint8_t dstControlRateProfileIndex, const uint8_t srcControlRateProfileIndex);
|
||||
|
|
|
@ -1299,6 +1299,18 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
|||
}
|
||||
break;
|
||||
|
||||
case MSP_COPY_PROFILE:
|
||||
value = sbufReadU8(src); // 0 = pid profile, 1 = control rate profile
|
||||
uint8_t dstProfileIndex = sbufReadU8(src);
|
||||
uint8_t srcProfileIndex = sbufReadU8(src);
|
||||
if (value == 0) {
|
||||
copyPidProfile(dstProfileIndex, srcProfileIndex);
|
||||
}
|
||||
else if (value == 1) {
|
||||
copyControlRateProfile(dstProfileIndex, srcProfileIndex);
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(GPS) || defined(MAG)
|
||||
case MSP_SET_HEADING:
|
||||
magHold = sbufReadU16(src);
|
||||
|
|
|
@ -482,3 +482,11 @@ void pidController(const pidProfile_t *pidProfile, const rollAndPitchTrims_t *an
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void copyPidProfile(const uint8_t dstPidProfileIndex, const uint8_t srcPidProfileIndex) {
|
||||
if ((dstPidProfileIndex < MAX_PROFILE_COUNT-1 && srcPidProfileIndex < MAX_PROFILE_COUNT-1)
|
||||
&& dstPidProfileIndex != srcPidProfileIndex
|
||||
) {
|
||||
memcpy(pidProfilesMutable(dstPidProfileIndex), pidProfilesMutable(srcPidProfileIndex), sizeof(pidProfile_t));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,5 +133,6 @@ void pidSetItermAccelerator(float newItermAccelerator);
|
|||
void pidInitFilters(const pidProfile_t *pidProfile);
|
||||
void pidInitConfig(const pidProfile_t *pidProfile);
|
||||
void pidInit(const pidProfile_t *pidProfile);
|
||||
void copyPidProfile(const uint8_t dstPidProfileIndex, const uint8_t srcPidProfileIndex);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -223,6 +223,8 @@
|
|||
// External OSD displayport mode messages
|
||||
#define MSP_DISPLAYPORT 182
|
||||
|
||||
#define MSP_COPY_PROFILE 183
|
||||
|
||||
#define MSP_BEEPER_CONFIG 184
|
||||
#define MSP_SET_BEEPER_CONFIG 185
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue