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

Refactoring of PR 13050 - support for custom OSD messages from external device (#14097)

This commit is contained in:
Petr Ledvina 2024-12-22 05:44:08 +01:00 committed by GitHub
parent cab60b6594
commit ac82d8b998
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 135 additions and 35 deletions

View file

@ -124,6 +124,7 @@
#include "pg/gps_rescue.h"
#include "pg/gyrodev.h"
#include "pg/motor.h"
#include "pg/pilot.h"
#include "pg/pos_hold.h"
#include "pg/rx.h"
#include "pg/rx_spi.h"
@ -1158,12 +1159,7 @@ static bool mspProcessOutCommand(mspDescriptor_t srcDesc, int16_t cmdMSP, sbuf_t
break;
case MSP_NAME:
{
const int nameLen = strlen(pilotConfig()->craftName);
for (int i = 0; i < nameLen; i++) {
sbufWriteU8(dst, pilotConfig()->craftName[i]);
}
}
sbufWriteString(dst, pilotConfig()->craftName);
break;
#ifdef USE_SERVOS
@ -2610,9 +2606,7 @@ static mspResult_e mspFcProcessOutCommandWithArg(mspDescriptor_t srcDesc, int16_
// 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]);
}
sbufWriteData(dst, textVar, textLength);
}
break;
#ifdef USE_LED_STRIP
@ -3985,10 +3979,8 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
#endif
case MSP_SET_NAME:
memset(pilotConfigMutable()->craftName, 0, ARRAYLEN(pilotConfig()->craftName));
for (unsigned int i = 0; i < MIN(MAX_NAME_LENGTH, dataSize); i++) {
pilotConfigMutable()->craftName[i] = sbufReadU8(src);
}
memset(pilotConfigMutable()->craftName, 0, sizeof(pilotConfigMutable()->craftName));
sbufReadData(src, pilotConfigMutable()->craftName, MIN(ARRAYLEN(pilotConfigMutable()->craftName) - 1, dataSize));
#ifdef USE_OSD
osdAnalyzeActiveElements();
#endif
@ -4068,35 +4060,51 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
case MSP2_SET_TEXT:
{
// type byte, then length byte followed by the actual characters
const uint8_t textType = sbufReadU8(src);
const unsigned textType = sbufReadU8(src);
char* textVar;
const uint8_t textLength = MIN(MAX_NAME_LENGTH, sbufReadU8(src));
unsigned textSpace;
switch (textType) {
case MSP2TEXT_PILOT_NAME:
textVar = pilotConfigMutable()->pilotName;
textSpace = sizeof(pilotConfigMutable()->pilotName) - 1;
break;
case MSP2TEXT_CRAFT_NAME:
textVar = pilotConfigMutable()->craftName;
textSpace = sizeof(pilotConfigMutable()->craftName) - 1;
break;
case MSP2TEXT_PID_PROFILE_NAME:
textVar = currentPidProfile->profileName;
textSpace = sizeof(currentPidProfile->profileName) - 1;
break;
case MSP2TEXT_RATE_PROFILE_NAME:
textVar = currentControlRateProfile->profileName;
textSpace = sizeof(currentControlRateProfile->profileName) - 1;
break;
case MSP2TEXT_CUSTOM_MSG_0:
case MSP2TEXT_CUSTOM_MSG_0 + 1:
case MSP2TEXT_CUSTOM_MSG_0 + 2:
case MSP2TEXT_CUSTOM_MSG_0 + 3: {
unsigned msgIdx = textType - MSP2TEXT_CUSTOM_MSG_0;
if (msgIdx < OSD_CUSTOM_MSG_COUNT) {
textVar = pilotConfigMutable()->message[msgIdx];
textSpace = sizeof(pilotConfigMutable()->message[msgIdx]) - 1;
} else {
return MSP_RESULT_ERROR;
}
break;
}
default:
return MSP_RESULT_ERROR;
}
const unsigned textLength = MIN(textSpace, sbufReadU8(src));
memset(textVar, 0, strlen(textVar));
for (unsigned int i = 0; i < textLength; i++) {
textVar[i] = sbufReadU8(src);
}
sbufReadData(src, textVar, textLength);
#ifdef USE_OSD
if (textType == MSP2TEXT_PILOT_NAME || textType == MSP2TEXT_CRAFT_NAME) {