diff --git a/tasmota/autoexec.be b/tasmota/autoexec.be index c3d7e6d8..1ac9b0ef 100644 --- a/tasmota/autoexec.be +++ b/tasmota/autoexec.be @@ -20,6 +20,8 @@ class Nextion : Driver var flash_written var flash_buff var flash_offset + var flash_proto_version + var flash_proto_baud var awaiting_offset var tcp var ser @@ -136,8 +138,7 @@ class Nextion : Driver if (self.flash_written==self.flash_size) log("FLH: Flashing complete - Time elapsed: %d", (tasmota.millis()-self.flash_start_millis)/1000) self.flash_mode = 0 - self.ser = nil - tasmota.gc() + self.ser.deinit() self.ser = serial(17, 16, 115200, serial.SERIAL_8N1) end @@ -155,8 +156,15 @@ class Nextion : Driver log("FLH: Send (High Speed) flash start") self.flash_start_millis = tasmota.millis() #self.sendnx(string.format("whmi-wris %d,115200,res0",self.flash_size)) - self.sendnx(string.format("whmi-wris %d,921600,res0",self.flash_size)) - self.ser = serial(17, 16, 921600, serial.SERIAL_8N1) + if self.flash_proto_version == 0 + self.sendnx(string.format("whmi-wri %d,%d,res0",self.flash_size,self.flash_proto_baud)) + else + self.sendnx(string.format("whmi-wris %d,%d,res0",self.flash_size,self.flash_proto_baud)) + end + if self.flash_proto_baud != 115200 + self.ser.deinit() + self.ser = serial(17, 16, self.flash_proto_baud, serial.SERIAL_8N1) + end elif size(msg)==1 && msg[0]==0x08 log("FLH: Waiting offset...",3) self.awaiting_offset = 1 @@ -299,6 +307,8 @@ class Nextion : Driver log("NXP: Initializing Driver") self.ser = serial(17, 16, 115200, serial.SERIAL_8N1) self.flash_mode = 0 + self.flash_proto_version = 1 + self.flash_proto_baud = 921600 end end @@ -309,7 +319,7 @@ tasmota.add_driver(nextion) def get_current_version(cmd, idx, payload, payload_json) import string - var version_of_this_script = 4 + var version_of_this_script = 6 var jm = string.format("{\"nlui_driver_version\":\"%s\"}", version_of_this_script) tasmota.publish_result(jm, "RESULT") end @@ -351,6 +361,39 @@ tasmota.add_cmd('UpdateDriverVersion', update_berry_driver) def flash_nextion(cmd, idx, payload, payload_json) def task() + nextion.flash_proto_version = 1 + nextion.flash_proto_baud = 921600 + nextion.flash_nextion(payload) + end + tasmota.set_timer(0,task) + tasmota.resp_cmnd_done() +end + +def flash_nextion_adv(cmd, idx, payload, payload_json) + def task() + if idx==0 + nextion.flash_proto_version = 1 + nextion.flash_proto_baud = 921600 + elif idx==1 + nextion.flash_proto_version = 0 + nextion.flash_proto_baud = 921600 + elif idx==2 + nextion.flash_proto_version = 1 + nextion.flash_proto_baud = 115200 + elif idx==3 + nextion.flash_proto_version = 0 + nextion.flash_proto_baud = 115200 + elif idx==4 + nextion.flash_proto_version = 1 + nextion.flash_proto_baud = 256000 + elif idx==5 + nextion.flash_proto_version = 0 + nextion.flash_proto_baud = 256000 + else + nextion.flash_proto_version = 0 + nextion.flash_proto_baud = 115200 + end + nextion.flash_nextion(payload) end tasmota.set_timer(0,task) @@ -370,3 +413,4 @@ end tasmota.add_cmd('Nextion', send_cmd) tasmota.add_cmd('CustomSend', send_cmd2) tasmota.add_cmd('FlashNextion', flash_nextion) +tasmota.add_cmd('FlashNextionAdv', flash_nextion_adv)