Skip to content

Commit a643384

Browse files
authoredMay 22, 2023
Merge pull request #84 from pkendall64/hdzero-osd
Add OSD support for HDZero goggles
2 parents 0a10cb4 + f929048 commit a643384

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed
 

‎python/osd_test.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import time
2+
import serial
3+
import argparse
4+
import serials_find
5+
6+
def crc8_dvb_s2(crc, a):
7+
crc = crc ^ a
8+
for ii in range(8):
9+
if crc & 0x80:
10+
crc = (crc << 1) ^ 0xD5
11+
else:
12+
crc = crc << 1
13+
return crc & 0xFF
14+
15+
def send_msp(port, baud, body):
16+
s = serial.Serial(port=port, baudrate=baud,
17+
bytesize=8, parity='N', stopbits=1,
18+
timeout=1, xonxoff=0, rtscts=0)
19+
crc = 0
20+
for x in body:
21+
crc = crc8_dvb_s2(crc, x)
22+
msp = [ord('$'),ord('X'),ord('<')]
23+
msp = msp + body
24+
msp.append(crc)
25+
s.write(msp)
26+
print(msp)
27+
time.sleep(2.0)
28+
print(s.read_all())
29+
30+
def send_clear(port, baud):
31+
msp = [0,0xb6,0x00,1,0,0x02]
32+
send_msp(port, baud, msp)
33+
34+
def send_display(port, baud):
35+
msp = [0,0xb6,0x00,1,0,0x04]
36+
send_msp(port, baud, msp)
37+
38+
def send_msg(port, baud, row, col, str):
39+
l = 4+len(str)
40+
msp = [0,0xb6,0x00,l%256,int(l/256),0x03,row,col,0]
41+
for x in [*str]:
42+
msp.append(ord(x))
43+
send_msp(port, baud, msp)
44+
45+
if __name__ == '__main__':
46+
parser = argparse.ArgumentParser(
47+
description="Initialize EdgeTX passthrough to internal module")
48+
parser.add_argument("-b", "--baud", type=int, default=460800,
49+
help="Baud rate for passthrough communication")
50+
parser.add_argument("-p", "--port", type=str,
51+
help="Override serial port autodetection and use PORT")
52+
parser.add_argument("-c", "--clear", action='store_true',
53+
help="Clear the OSD")
54+
parser.add_argument("-d", "--display", action='store_true',
55+
help="Draw the currently set OSD")
56+
parser.add_argument("row", type=int, nargs='?', default=0,
57+
help="Row where message is to be displayed")
58+
parser.add_argument("col", type=int, nargs='?', default=0,
59+
help="Column where message is to be displayed")
60+
parser.add_argument("message", type=str, nargs='?', default='',
61+
help="Message to be displayed")
62+
args = parser.parse_args()
63+
64+
if (args.port == None):
65+
args.port = serials_find.get_serial_port()
66+
67+
if args.clear:
68+
send_clear(args.port, args.baud)
69+
elif args.display:
70+
send_display(args.port, args.baud)
71+
else:
72+
send_msg(args.port, args.baud, args.row, args.col, args.message)

‎src/hdzero.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ HDZero::SendHeadTrackingEnableCmd(bool enable)
110110
msp.sendPacket(&packet, m_port);
111111
}
112112

113+
void
114+
HDZero::SetOSD(mspPacket_t *packet)
115+
{
116+
MSP msp;
117+
msp.sendPacket(packet, m_port);
118+
}
119+
113120
void
114121
HDZero::SetRTC()
115122
{
@@ -131,4 +138,4 @@ HDZero::SetRTC()
131138
packet.addByte(timeData.tm_sec);
132139

133140
msp.sendPacket(&packet, m_port);
134-
}
141+
}

‎src/hdzero.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ class HDZero : public MSPModuleBase
2424
uint8_t GetRecordingState();
2525
void SetRecordingState(uint8_t recordingState, uint16_t delay);
2626
void SendHeadTrackingEnableCmd(bool enable);
27+
void SetOSD(mspPacket_t *packet);
2728
void SetRTC();
2829
};

0 commit comments

Comments
 (0)
Please sign in to comment.