Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added MSP_PILOT_CONFIG with user definable parameters #156

Merged
merged 8 commits into from
Sep 11, 2024
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
11 changes: 11 additions & 0 deletions src/main/cli/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ const char * const lookupTableEdgeMode[] = {
"FALLING", "RISING"
};

const char * const lookupTableParamType[] = {
"NONE", "TIMER1", "TIMER2", "TIMER3", "GV1", "GV2", "GV3", "GV4", "GV5", "GV6", "GV7", "GV8", "GV9"
};

#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }

const lookupTableEntry_t lookupTables[] = {
Expand Down Expand Up @@ -614,6 +618,7 @@ const lookupTableEntry_t lookupTables[] = {
LOOKUP_TABLE_ENTRY(lookupTableTelemMode),
LOOKUP_TABLE_ENTRY(lookupTablePullMode),
LOOKUP_TABLE_ENTRY(lookupTableEdgeMode),
LOOKUP_TABLE_ENTRY(lookupTableParamType),
};

#undef LOOKUP_TABLE_ENTRY
Expand Down Expand Up @@ -1701,6 +1706,12 @@ const clivalue_t valueTable[] = {
{ "display_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, MAX_NAME_LENGTH, STRING_FLAGS_NONE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, displayName) },
#endif
{ "model_id", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 99 }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, modelId) },
{ "model_param1_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_PARAM_TYPE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, modelParam1Type) },
{ "model_param1_value", VAR_INT16 | MASTER_VALUE, .config.minmax = { INT16_MIN, INT16_MAX }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, modelParam1Value) },
{ "model_param2_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_PARAM_TYPE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, modelParam2Type) },
{ "model_param2_value", VAR_INT16 | MASTER_VALUE, .config.minmax = { INT16_MIN, INT16_MAX }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, modelParam2Value) },
{ "model_param3_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_PARAM_TYPE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, modelParam3Type) },
{ "model_param3_value", VAR_INT16 | MASTER_VALUE, .config.minmax = { INT16_MIN, INT16_MAX }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, modelParam3Value) },

// PG_POSITION
{ "position_alt_source", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_POSITION_ALT_SOURCE }, PG_POSITION, offsetof(positionConfig_t, alt_source) },
Expand Down
2 changes: 1 addition & 1 deletion src/main/cli/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ typedef enum {
TABLE_SWASH_TYPE,
TABLE_DTERM_MODE,
TABLE_TELEM_MODE,

TABLE_INPUT_PULL_MODE,
TABLE_INPUT_EDGE_MODE,
TABLE_PARAM_TYPE,

LOOKUP_TABLE_COUNT
} lookupTableIndex_e;
Expand Down
26 changes: 22 additions & 4 deletions src/main/msp/msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,10 +1103,20 @@ static bool mspProcessOutCommand(int16_t cmdMSP, sbuf_t *dst)
for (int i = 0; i < nameLen; i++) {
sbufWriteU8(dst, pilotConfig()->name[i]);
}
sbufWriteU8(dst, pilotConfig()->modelId);
}
break;

case MSP_PILOT_CONFIG:
// Introduced in MSP API 12.7
sbufWriteU8(dst, pilotConfig()->modelId);
sbufWriteU8(dst, pilotConfig()->modelParam1Type);
sbufWriteU16(dst, pilotConfig()->modelParam1Value);
sbufWriteU8(dst, pilotConfig()->modelParam2Type);
sbufWriteU16(dst, pilotConfig()->modelParam2Value);
sbufWriteU8(dst, pilotConfig()->modelParam3Type);
sbufWriteU16(dst, pilotConfig()->modelParam3Value);
break;

#ifdef USE_SERVOS
case MSP_SERVO:
for (int i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
Expand Down Expand Up @@ -3202,14 +3212,22 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
for (unsigned int i = 0; i < MIN(MAX_NAME_LENGTH, dataSize); i++) {
pilotConfigMutable()->name[i] = sbufReadU8(src);
}
if (sbufBytesRemaining(src) >= 1) {
pilotConfigMutable()->modelId = sbufReadU8(src);
}
#ifdef USE_OSD
osdAnalyzeActiveElements();
#endif
break;

case MSP_SET_PILOT_CONFIG:
// Introduced in MSP API 12.7
pilotConfigMutable()->modelId = sbufReadU8(src);
pilotConfigMutable()->modelParam1Type = sbufReadU8(src);
pilotConfigMutable()->modelParam1Value = sbufReadU16(src);
pilotConfigMutable()->modelParam2Type = sbufReadU8(src);
pilotConfigMutable()->modelParam2Value = sbufReadU16(src);
pilotConfigMutable()->modelParam3Type = sbufReadU8(src);
pilotConfigMutable()->modelParam3Value = sbufReadU16(src);
break;

#ifdef USE_RTC_TIME
case MSP_SET_RTC:
{
Expand Down
2 changes: 2 additions & 0 deletions src/main/msp/msp_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

#define MSP_NAME 10
#define MSP_SET_NAME 11
#define MSP_PILOT_CONFIG 12
#define MSP_SET_PILOT_CONFIG 13

#define MSP_BATTERY_CONFIG 32
#define MSP_SET_BATTERY_CONFIG 33
Expand Down
6 changes: 6 additions & 0 deletions src/main/pg/pilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ typedef struct {
char name[MAX_NAME_LENGTH + 1];
char displayName[MAX_NAME_LENGTH + 1];
uint8_t modelId;
uint8_t modelParam1Type;
int16_t modelParam1Value;
uint8_t modelParam2Type;
int16_t modelParam2Value;
uint8_t modelParam3Type;
int16_t modelParam3Value;
} pilotConfig_t;

PG_DECLARE(pilotConfig_t, pilotConfig);