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

Add support for custom OSD message via MSP #56

Closed
Closed
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
8 changes: 8 additions & 0 deletions src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ PG_RESET_TEMPLATE(pilotConfig_t, pilotConfig,
.displayName = { 0 },
);

PG_REGISTER_WITH_RESET_TEMPLATE(customMsgConfig_t, customMsgConfig, PG_PILOT_CONFIG, 1);

PG_RESET_TEMPLATE(customMsgConfig_t, customMsgConfig,
.customMessage[0] = { 0 },
.customMessage[1] = { 0 },
.customMessage[2] = { 0 },
);

PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 3);

PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
Expand Down
9 changes: 9 additions & 0 deletions src/main/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "pg/pg.h"

#define MAX_NAME_LENGTH 16u
#define MAX_CUSTOM_MSG_LENGTH 30u
#define CUSTOM_MSG_SPLITER 0x23 //'#'作为分隔符

typedef enum {
CONFIGURATION_STATE_DEFAULTS_BARE = 0,
Expand Down Expand Up @@ -56,6 +58,13 @@ typedef struct systemConfig_s {

PG_DECLARE(systemConfig_t, systemConfig);

//Custom message configure
typedef struct customMsgConfig_s {
char customMessage[3][MAX_CUSTOM_MSG_LENGTH + 1];
} customMsgConfig_t;

PG_DECLARE(customMsgConfig_t, customMsgConfig);

struct pidProfile_s;
extern struct pidProfile_s *currentPidProfile;

Expand Down
26 changes: 26 additions & 0 deletions src/main/msp/msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4019,6 +4019,32 @@ static mspResult_e mspCommonProcessInCommand(mspDescriptor_t srcDesc, int16_t cm
}
break;
#endif // OSD
case MSP2_SET_CUSTOM_OSD_INFO:
{ //handle custom msg from msp
char customRawMessage[MAX_CUSTOM_MSG_LENGTH*3];
const uint8_t textLength = MIN(MAX_CUSTOM_MSG_LENGTH*3, sbufReadU8(src));
memset(customRawMessage, 0, textLength);

for (unsigned int i = 0; i < textLength; i++) {
customRawMessage[i] = sbufReadU8(src);
}

uint8_t spliter_pos = 0;
uint8_t msg_cnt = 0;
uint8_t i = 0;
for(msg_cnt = 0;msg_cnt < 3;msg_cnt++)
{
for(i = spliter_pos;i < 20;i++)
{
if(customRawMessage[i] != CUSTOM_MSG_SPLITER)
customMsgConfigMutable()->customMessage[msg_cnt][i-spliter_pos] = customRawMessage[i];
else
break;
}
spliter_pos = i + 1;
}
}
break;

default:
return mspProcessInCommand(srcDesc, cmdMSP, src);
Expand Down
2 changes: 2 additions & 0 deletions src/main/msp/msp_protocol_v2_betaflight.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
#define MSP2_SEND_DSHOT_COMMAND 0x3003
#define MSP2_GET_VTX_DEVICE_STATUS 0x3004
#define MSP2_GET_OSD_WARNINGS 0x3005 // returns active OSD warning message text

#define MSP2_SET_CUSTOM_OSD_INFO 0x4000 // for set self defined OSD message text
3 changes: 3 additions & 0 deletions src/main/osd/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ typedef enum {
OSD_TOTAL_FLIGHTS,
OSD_UP_DOWN_REFERENCE,
OSD_TX_UPLINK_POWER,
OSD_CUSTOM_MESSAGE1,
OSD_CUSTOM_MESSAGE2,
OSD_CUSTOM_MESSAGE3,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down
57 changes: 57 additions & 0 deletions src/main/osd/osd_elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,57 @@ static void osdElementWarnings(osdElementParms_t *element)
}
}

static void osdElementCustomMessage1(osdElementParms_t *element)
{
//display string from msp, without handle
if (strlen(customMsgConfig()->customMessage[0]) == 0) {
strcpy(element->buff, "READY_GO");
} else {
unsigned i;
for (i = 0; i < MAX_CUSTOM_MSG_LENGTH; i++) {
if (customMsgConfig()->customMessage[0][i]) {
element->buff[i] = customMsgConfig()->customMessage[0][i];
} else {
break;
}
}
element->buff[i] = '\0';
}
}
static void osdElementCustomMessage2(osdElementParms_t *element)
{
//display string from msp, without handle
if (strlen(customMsgConfig()->customMessage[1]) == 0) {
strcpy(element->buff, "LAPTIMER");
} else {
unsigned i;
for (i = 0; i < MAX_CUSTOM_MSG_LENGTH; i++) {
if (customMsgConfig()->customMessage[1][i]) {
element->buff[i] = customMsgConfig()->customMessage[1][i];
} else {
break;
}
}
element->buff[i] = '\0';
}
}
static void osdElementCustomMessage3(osdElementParms_t *element)
{
//display string from msp, without handle
if (strlen(customMsgConfig()->customMessage[2]) == 0) {
strcpy(element->buff, "VER_1.0");
} else {
unsigned i;
for (i = 0; i < MAX_CUSTOM_MSG_LENGTH; i++) {
if (customMsgConfig()->customMessage[2][i]) {
element->buff[i] = customMsgConfig()->customMessage[2][i];
} else {
break;
}
}
element->buff[i] = '\0';
}
}
// Define the order in which the elements are drawn.
// Elements positioned later in the list will overlay the earlier
// ones if their character positions overlap
Expand Down Expand Up @@ -1558,6 +1609,9 @@ static const uint8_t osdElementDisplayOrder[] = {
#ifdef USE_PERSISTENT_STATS
OSD_TOTAL_FLIGHTS,
#endif
OSD_CUSTOM_MESSAGE1,
OSD_CUSTOM_MESSAGE2,
OSD_CUSTOM_MESSAGE3,
};

// Define the mapping between the OSD element id and the function to draw it
Expand Down Expand Up @@ -1675,6 +1729,9 @@ const osdElementDrawFn osdElementDrawFunction[OSD_ITEM_COUNT] = {
#ifdef USE_PERSISTENT_STATS
[OSD_TOTAL_FLIGHTS] = osdElementTotalFlights,
#endif
[OSD_CUSTOM_MESSAGE1] = osdElementCustomMessage1,
[OSD_CUSTOM_MESSAGE2] = osdElementCustomMessage2,
[OSD_CUSTOM_MESSAGE3] = osdElementCustomMessage3,
};

// Define the mapping between the OSD element id and the function to draw its background (static part)
Expand Down