1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-24 00:35:34 +03:00

Merge pull request #9327 from RomanLut/hitl-hd-osd

HITL: hd osd support
This commit is contained in:
Paweł Spychalski 2023-10-25 15:38:48 +02:00 committed by GitHub
commit 05a93edb6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 16 deletions

View file

@ -3397,7 +3397,7 @@ bool isOSDTypeSupportedBySimulator(void)
{ {
#ifdef USE_OSD #ifdef USE_OSD
displayPort_t *osdDisplayPort = osdGetDisplayPort(); displayPort_t *osdDisplayPort = osdGetDisplayPort();
return (osdDisplayPort && osdDisplayPort->cols == 30 && (osdDisplayPort->rows == 13 || osdDisplayPort->rows == 16)); return (!!osdDisplayPort && !!osdDisplayPort->vTable->readChar);
#else #else
return false; return false;
#endif #endif
@ -3409,18 +3409,25 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
//scan displayBuffer iteratively //scan displayBuffer iteratively
//no more than 80+3+2 bytes output in single run //no more than 80+3+2 bytes output in single run
//0 and 255 are special symbols //0 and 255 are special symbols
//255 - font bank switch //255 [char] - font bank switch
//0 - font bank switch, blink switch and character repeat //0 [flags,count] [char] - font bank switch, blink switch and character repeat
//original 0 is sent as 32
//original 0xff, 0x100 and 0x1ff are forcibly sent inside command 0
static uint8_t osdPos_y = 0; static uint8_t osdPos_y = 0;
static uint8_t osdPos_x = 0; static uint8_t osdPos_x = 0;
//indicate new format hitl 1.4.0
sbufWriteU8(dst, 255);
if (isOSDTypeSupportedBySimulator()) if (isOSDTypeSupportedBySimulator())
{ {
displayPort_t *osdDisplayPort = osdGetDisplayPort(); displayPort_t *osdDisplayPort = osdGetDisplayPort();
sbufWriteU8(dst, osdPos_y | (osdDisplayPort->rows == 16 ? 128: 0)); sbufWriteU8(dst, osdDisplayPort->rows);
sbufWriteU8(dst, osdDisplayPort->cols);
sbufWriteU8(dst, osdPos_y);
sbufWriteU8(dst, osdPos_x); sbufWriteU8(dst, osdPos_x);
int bytesCount = 0; int bytesCount = 0;
@ -3431,7 +3438,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
bool blink = false; bool blink = false;
int count = 0; int count = 0;
int processedRows = 16; int processedRows = osdDisplayPort->rows;
while (bytesCount < 80) //whole response should be less 155 bytes at worst. while (bytesCount < 80) //whole response should be less 155 bytes at worst.
{ {
@ -3442,7 +3449,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
while ( true ) while ( true )
{ {
displayReadCharWithAttr(osdDisplayPort, osdPos_x, osdPos_y, &c, &attr); displayReadCharWithAttr(osdDisplayPort, osdPos_x, osdPos_y, &c, &attr);
if (c == 0 || c == 255) c = 32; if (c == 0) c = 32;
//REVIEW: displayReadCharWithAttr() should return mode with _TEXT_ATTRIBUTES_BLINK_BIT ! //REVIEW: displayReadCharWithAttr() should return mode with _TEXT_ATTRIBUTES_BLINK_BIT !
//for max7456 it returns mode with MAX7456_MODE_BLINK instead (wrong) //for max7456 it returns mode with MAX7456_MODE_BLINK instead (wrong)
@ -3457,7 +3464,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
lastChar = c; lastChar = c;
blink1 = blink2; blink1 = blink2;
} }
else if (lastChar != c || blink2 != blink1 || count == 63) else if ((lastChar != c) || (blink2 != blink1) || (count == 63))
{ {
break; break;
} }
@ -3465,12 +3472,12 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
count++; count++;
osdPos_x++; osdPos_x++;
if (osdPos_x == 30) if (osdPos_x == osdDisplayPort->cols)
{ {
osdPos_x = 0; osdPos_x = 0;
osdPos_y++; osdPos_y++;
processedRows--; processedRows--;
if (osdPos_y == 16) if (osdPos_y == osdDisplayPort->rows)
{ {
osdPos_y = 0; osdPos_y = 0;
} }
@ -3478,6 +3485,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
} }
uint8_t cmd = 0; uint8_t cmd = 0;
uint8_t lastCharLow = (uint8_t)(lastChar & 0xff);
if (blink1 != blink) if (blink1 != blink)
{ {
cmd |= 128;//switch blink attr cmd |= 128;//switch blink attr
@ -3493,27 +3501,27 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
if (count == 1 && cmd == 64) if (count == 1 && cmd == 64)
{ {
sbufWriteU8(dst, 255); //short command for bank switch sbufWriteU8(dst, 255); //short command for bank switch with char following
sbufWriteU8(dst, lastChar & 0xff); sbufWriteU8(dst, lastChar & 0xff);
bytesCount += 2; bytesCount += 2;
} }
else if (count > 2 || cmd !=0 ) else if ((count > 2) || (cmd !=0) || (lastChar == 255) || (lastChar == 0x100) || (lastChar == 0x1ff))
{ {
cmd |= count; //long command for blink/bank switch and symbol repeat cmd |= count; //long command for blink/bank switch and symbol repeat
sbufWriteU8(dst, 0); sbufWriteU8(dst, 0);
sbufWriteU8(dst, cmd); sbufWriteU8(dst, cmd);
sbufWriteU8(dst, lastChar & 0xff); sbufWriteU8(dst, lastCharLow);
bytesCount += 3; bytesCount += 3;
} }
else if (count == 2) //cmd == 0 here else if (count == 2) //cmd == 0 here
{ {
sbufWriteU8(dst, lastChar & 0xff); sbufWriteU8(dst, lastCharLow);
sbufWriteU8(dst, lastChar & 0xff); sbufWriteU8(dst, lastCharLow);
bytesCount+=2; bytesCount+=2;
} }
else else
{ {
sbufWriteU8(dst, lastChar & 0xff); sbufWriteU8(dst, lastCharLow);
bytesCount++; bytesCount++;
} }
@ -3527,7 +3535,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
} }
else else
{ {
sbufWriteU8(dst, 255); sbufWriteU8(dst, 0);
} }
} }
#endif #endif

View file

@ -42,6 +42,7 @@
#include "drivers/osd_symbols.h" #include "drivers/osd_symbols.h"
#include "fc/rc_modes.h" #include "fc/rc_modes.h"
#include "fc/runtime_config.h"
#include "io/osd.h" #include "io/osd.h"
#include "io/displayport_msp.h" #include "io/displayport_msp.h"
@ -113,6 +114,10 @@ static void checkVtxPresent(void)
if (vtxActive && (millis()-vtxHeartbeat) > VTX_TIMEOUT) { if (vtxActive && (millis()-vtxHeartbeat) > VTX_TIMEOUT) {
vtxActive = false; vtxActive = false;
} }
if (ARMING_FLAG(SIMULATOR_MODE_HITL)) {
vtxActive = true;
}
} }
static int output(displayPort_t *displayPort, uint8_t cmd, uint8_t *subcmd, int len) static int output(displayPort_t *displayPort, uint8_t cmd, uint8_t *subcmd, int len)