mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-22 16:25:45 +08:00
added device name and model type options for CLI
This commit is contained in:
@@ -22,10 +22,8 @@ import sys
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
e = "\xff\xff\xff"
|
e = "\xff\xff\xff"
|
||||||
deviceName = '/dev/ttyUSB0' #MAKE SURE THIS IS THE CORRECT DEVICE
|
|
||||||
CHECK_MODEL = 'NX3224T024'
|
|
||||||
|
|
||||||
def getBaudrate(ser, fSize=None):
|
def getBaudrate(ser, fSize=None, checkModel=None):
|
||||||
for baudrate in (2400, 4800, 9600, 19200, 38400, 57600, 115200):
|
for baudrate in (2400, 4800, 9600, 19200, 38400, 57600, 115200):
|
||||||
ser.baudrate = baudrate
|
ser.baudrate = baudrate
|
||||||
ser.timeout = 3000 / baudrate + .2
|
ser.timeout = 3000 / baudrate + .2
|
||||||
@@ -46,7 +44,7 @@ def getBaudrate(ser, fSize=None):
|
|||||||
if fSize and fSize > flashSize:
|
if fSize and fSize > flashSize:
|
||||||
print 'File too big!'
|
print 'File too big!'
|
||||||
return False
|
return False
|
||||||
if not CHECK_MODEL in model:
|
if checkModel and not checkModel in model:
|
||||||
print 'Wrong Display!'
|
print 'Wrong Display!'
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -85,8 +83,8 @@ def transferFile(ser, filename, fSize):
|
|||||||
print
|
print
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def upload(ser, filename):
|
def upload(ser, filename, checkModel=None):
|
||||||
if not getBaudrate(ser, os.path.getsize(filename)):
|
if not getBaudrate(ser, os.path.getsize(filename), checkModel):
|
||||||
print 'could not find baudrate'
|
print 'could not find baudrate'
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
@@ -101,15 +99,20 @@ def upload(ser, filename):
|
|||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 4 and len(sys.argv) != 3:
|
||||||
print 'usage:\npython nextion.py file_to_upload.tft'
|
print 'usage:\npython nextion.py file_to_upload.tft /path/to/dev/ttyDevice [nextion_model_name]\
|
||||||
|
\nexample: nextion.py newUI.tft /dev/ttyUSB0 NX3224T024\
|
||||||
|
\nnote: model name is optional'
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
ser = serial.Serial(deviceName, 9600, timeout=5)
|
ser = serial.Serial(sys.argv[2], 9600, timeout=5)
|
||||||
if not ser:
|
if not ser:
|
||||||
print 'could not open device'
|
print 'could not open device'
|
||||||
exit(1)
|
exit(1)
|
||||||
if not ser.is_open:
|
if not ser.is_open:
|
||||||
ser.open()
|
ser.open()
|
||||||
|
|
||||||
upload(ser, sys.argv[1])
|
checkModel = None
|
||||||
|
if len(sys.argv) == 4:
|
||||||
|
checkModel = sys.argv[3]
|
||||||
|
upload(ser, sys.argv[1], checkModel)
|
||||||
|
|||||||
Reference in New Issue
Block a user