Merge branch '2.0.x-maintenance' into master-merge-commit
[ExpressLRS.git] / src / python / bind.py
blob3ac69b896bc3820191a120e07d9a569441e1957c
1 import serial, time, sys, re
2 import argparse
3 import serials_find
4 import SerialHelper
5 import bootloader
6 from BFinitPassthrough import *
8 SCRIPT_DEBUG = 0
10 def send_bind_command(args):
11 dbg_print("======== SEND BIND COMMAND ========")
12 s = serial.Serial(port=args.port, baudrate=args.baud,
13 bytesize=8, parity='N', stopbits=1,
14 timeout=1, xonxoff=0, rtscts=0)
15 if args.half_duplex:
16 BindInitSeq = bootloader.get_bind_seq('GHST', args.type)
17 dbg_print(" * Using half duplex (GHST)")
18 else:
19 BindInitSeq = bootloader.get_bind_seq('CRSF', args.type)
20 dbg_print(" * Using full duplex (CRSF)")
21 s.write(BindInitSeq)
22 s.flush()
23 time.sleep(.5)
24 s.close()
27 if __name__ == '__main__':
28 parser = argparse.ArgumentParser(
29 description="Initialize BetaFlight passthrough and send the 'enter bind mode' command")
30 parser.add_argument("-b", "--baud", type=int, default=420000,
31 help="Baud rate for passthrough communication")
32 parser.add_argument("-p", "--port", type=str,
33 help="Override serial port autodetection and use PORT")
34 parser.add_argument("-hd", "--half-duplex", action="store_true",
35 dest="half_duplex", help="Use half duplex mode")
36 parser.add_argument("-t", "--type", type=str, default="ESP82",
37 help="Defines flash target type which is sent to target in reboot command")
38 args = parser.parse_args()
40 if (args.port == None):
41 args.port = serials_find.get_serial_port()
43 try:
44 bf_passthrough_init(args.port, args.baud)
45 except PassthroughEnabled as err:
46 dbg_print(str(err))
48 send_bind_command(args)