1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-22 07:45:29 +03:00

Merge pull request #11391 from krasiyan/add-display-name-msp-commands

This commit is contained in:
J Blackman 2022-10-31 07:57:44 +11:00 committed by GitHub
commit e801548117
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 99 additions and 49 deletions

View file

@ -1143,15 +1143,6 @@ static bool mspProcessOutCommand(mspDescriptor_t srcDesc, int16_t cmdMSP, sbuf_t
}
break;
case MSP_NAME:
{
const int nameLen = strlen(pilotConfig()->name);
for (int i = 0; i < nameLen; i++) {
sbufWriteU8(dst, pilotConfig()->name[i]);
}
}
break;
#ifdef USE_SERVOS
case MSP_SERVO:
sbufWriteData(dst, &servo, MAX_SUPPORTED_SERVOS * 2);
@ -2499,6 +2490,38 @@ static mspResult_e mspFcProcessOutCommandWithArg(mspDescriptor_t srcDesc, int16_
}
break;
case MSP2_GET_TEXT:
{
// type byte, then length byte followed by the actual characters
const uint8_t textType = sbufBytesRemaining(src) ? sbufReadU8(src) : 0;
char* textVar;
switch (textType) {
case MSP2TEXT_PILOT_NAME:
textVar = pilotConfigMutable()->pilotName;
break;
case MSP2TEXT_CRAFT_NAME:
textVar = pilotConfigMutable()->craftName;
break;
default:
return MSP_RESULT_ERROR;
}
const uint8_t textLength = strlen(textVar);
// type byte, then length byte followed by the actual characters
sbufWriteU8(dst, textType);
sbufWriteU8(dst, textLength);
for (unsigned int i = 0; i < textLength; i++) {
sbufWriteU8(dst, textVar[i]);
}
}
break;
default:
return MSP_RESULT_CMD_UNKNOWN;
}
@ -3781,16 +3804,6 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
break;
#endif
case MSP_SET_NAME:
memset(pilotConfigMutable()->name, 0, ARRAYLEN(pilotConfig()->name));
for (unsigned int i = 0; i < MIN(MAX_NAME_LENGTH, dataSize); i++) {
pilotConfigMutable()->name[i] = sbufReadU8(src);
}
#ifdef USE_OSD
osdAnalyzeActiveElements();
#endif
break;
#ifdef USE_RTC_TIME
case MSP_SET_RTC:
{
@ -3861,6 +3874,40 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
break;
#endif
case MSP2_SET_TEXT:
{
// type byte, then length byte followed by the actual characters
const uint8_t textType = sbufReadU8(src);
char* textVar;
const uint8_t textLength = MIN(MAX_NAME_LENGTH, sbufReadU8(src));
switch (textType) {
case MSP2TEXT_PILOT_NAME:
textVar = pilotConfigMutable()->pilotName;
break;
case MSP2TEXT_CRAFT_NAME:
textVar = pilotConfigMutable()->craftName;
break;
default:
return MSP_RESULT_ERROR;
}
memset(textVar, 0, strlen(textVar));
for (unsigned int i = 0; i < textLength; i++) {
textVar[i] = sbufReadU8(src);
}
#ifdef USE_OSD
if (textType == MSP2TEXT_PILOT_NAME || textType == MSP2TEXT_CRAFT_NAME) {
osdAnalyzeActiveElements();
}
#endif
}
break;
default:
// we do not know how to handle the (valid) message, indicate error MSP $M!
return MSP_RESULT_ERROR;