From 43a57ff194777e4021e92291ae579b8505cda3ad Mon Sep 17 00:00:00 2001 From: pvvx Date: Thu, 28 Nov 2024 07:41:00 +0300 Subject: [PATCH] update --- README-ru.md | 4 ++- README.md | 4 ++- bthome_phy6222/rdwr_phy62x2.py | 64 +++++++++++++++++----------------- rdwr_phy62x2.py | 2 +- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/README-ru.md b/README-ru.md index f21742f..55d675b 100644 --- a/README-ru.md +++ b/README-ru.md @@ -5,6 +5,8 @@ Кастомные прошивки для устройств Tuya на чипсете PHY622x2. +(!) Не рекомендуется покупать термометры Tuya с датчиками CHT8305 и/или чипами драйверов ЖК-дисплея BL55028. Они имеют повышенное потребление и несовместимы с работой от батареек. Это муляж термометра от Tuya. + | [THB1](https://pvvx.github.io/THB1) | [THB2](https://pvvx.github.io/THB2) | [THB3](https://pvvx.github.io/THB3) | [BTH01](https://pvvx.github.io/BTH01/) | [TH05_V1.3](https://pvvx.github.io/TH05-v1.3) | [TH05_V1.4](https://pvvx.github.io/TH-05) | [TH05F](https://pvvx.github.io/TH05F) | |:---:|:---:|:---:|:---:|:---:|:---:|:---:| | ![THB1](https://pvvx.github.io/THB1/img/THB1.jpg) | ![THB2](https://pvvx.github.io/THB2/img/THB2.jpg) | ![THB3](https://pvvx.github.io/THB3/img/THB3.jpg) | ![BTH01](https://pvvx.github.io/BTH01/img/BTH01.jpg) | ![TH05V1.3](https://pvvx.github.io/TH05-v1.3/img/TH05-V1.3.jpg) | ![TH05V1.4](https://pvvx.github.io/TH-05/img/TH05V14.jpg) | ![TH05F](https://pvvx.github.io/TH05F/img/TH05F.jpg) @@ -178,7 +180,7 @@ python3 rdwr_phy62x2.py -p COM11 -r rc 0x11000000 0x80000 ff_thb2.bin python3 rdwr_phy62x2.py -p COM11 -b 1000000 -r we 0 ff_thb2.bin ``` -Не все адаптеры USB-COM поддерживают 1Mbit. Тогда удалите опцию `-b 1000000` или выберите другой вариант Baud rate. +Не все адаптеры USB-COM поддерживают 1Mbit. Тогда удалите опцию `-b 1000000` или выберите другой вариант Baud rate (115200, 250000, 500000, 1000000). 4. Прошивка зашита. Устройство работает. diff --git a/README.md b/README.md index f5ac5f2..f5b31d5 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ Custom firmware for Tuya devices based on the PHY622x2 chipset. +(!) It is not recommended to buy Tuya thermometers with CHT8305 sensors and/or BL55028 LCD driver chips. They have increased consumption and are not compatible with battery operation. This is a dummy thermometer from Tuya. + | [THB1](https://pvvx.github.io/THB1) | [THB2](https://pvvx.github.io/THB2) | [THB3](https://pvvx.github.io/THB3) | [BTH01](https://pvvx.github.io/BTH01/) | [TH05_V1.3](https://pvvx.github.io/TH05-v1.3) | [TH05_V1.4](https://pvvx.github.io/TH-05) | [TH05F](https://pvvx.github.io/TH05F) | |:---:|:---:|:---:|:---:|:---:|:---:|:---:| | ![THB1](https://pvvx.github.io/THB1/img/THB1.jpg) | ![THB2](https://pvvx.github.io/THB2/img/THB2.jpg) | ![THB3](https://pvvx.github.io/THB3/img/THB3.jpg) | ![BTH01](https://pvvx.github.io/BTH01/img/BTH01.jpg) | ![TH05V1.3](https://pvvx.github.io/TH05-v1.3/img/TH05-V1.3.jpg) | ![TH05V1.4](https://pvvx.github.io/TH-05/img/TH05V14.jpg) | ![TH05F](https://pvvx.github.io/TH05F/img/TH05F.jpg) @@ -176,7 +178,7 @@ python3 rdwr_phy62x2.py -p COM11 -r rc 0x11000000 0x80000 ff_thb2.bin python3 rdwr_phy62x2.py -p COM11 -b 1000000 -r we 0 ff_thb2.bin ``` -> Not all USB-COM adapters support 1Mbit. Then remove the `-b 1000000` option or select a different baud rate. +> Not all USB-COM adapters support 1Mbit. Then remove the `-b 1000000` option or select a different baud rate (115200, 250000, 500000, 1000000). 4. The firmware has been flashed and the device should work. diff --git a/bthome_phy6222/rdwr_phy62x2.py b/bthome_phy6222/rdwr_phy62x2.py index e2447de..8163d6c 100644 --- a/bthome_phy6222/rdwr_phy62x2.py +++ b/bthome_phy6222/rdwr_phy62x2.py @@ -2,8 +2,8 @@ # rdwr_phy62x2.py 11.01.2024 pvvx # -import serial; -import time; +import serial +import time import argparse import io import os @@ -88,15 +88,15 @@ class phyflasher: self.hexf.sec.extend(bytearray(struct.pack('>:' def SendResetCmd(self): - return self._port.write(str.encode('reset ')); + return self._port.write(str.encode('reset ')) def read_reg(self, addr): - pkt = 'rdreg%08x' % addr; - sent = self._port.write(pkt.encode()); - read = self._port.read(17); + pkt = 'rdreg%08x' % addr + sent = self._port.write(pkt.encode()) + read = self._port.read(17) if len(read) == 17 and read[0:3] == b'=0x' and read[11:17] == b'#OK>>:': return int(read[1:11], 16) return None @@ -124,13 +124,13 @@ class phyflasher: if mbit > 0: regcmd = regcmd | 0x40000 if dummy > 0: - regcmd = regcmd | (dummy << 7); + regcmd = regcmd | (dummy << 7) if not self.write_reg(0x4000c890, regcmd | 1): print('Error write Flash Command Register!') return False return True def flash_wait_idle(self): - i = 5; + i = 5 while i > 0: r = self.read_reg(0x4000c890) if r == None: @@ -179,9 +179,9 @@ class phyflasher: return self.wr_flash_cmd(6) and self.wr_flash_cmd(1, 0, 1) def ReadRevision(self): #0x001364c8 6222M005 #OK>>: - self._port.write(str.encode('rdrev+ ')); + self._port.write(str.encode('rdrev+ ')) self._port.timeout = 0.1 - read = self._port.read(26); + read = self._port.read(26) if len(read) == 26 and read[0:2] == b'0x' and read[20:26] == b'#OK>>:': print('Revision:', read[2:19]) if read[11:15] != b'6222': @@ -196,9 +196,9 @@ class phyflasher: def SetBaud(self, baud): if self._port.baudrate != baud: print ('Reopen %s port %i baud...' % (self.port, baud), end = ' '), - self._port.write(str.encode("uarts%i" % baud)); + self._port.write(str.encode("uarts%i" % baud)) self._port.timeout = 1 - read = self._port.read(3); + read = self._port.read(3) if read == b'#OK': print ('ok') self.baud = baud @@ -227,12 +227,12 @@ class phyflasher: self._port.setDTR(False) #TM (hi) self._port.setRTS(False) #RSTN (hi) self._port.timeout = 0.04 - ttcl = 50; + ttcl = 50 fct_mode = False pkt = 'UXTDWU' # UXTL16 UDLL48 UXTDWU while ttcl > 0: - sent = self._port.write(pkt.encode()); - read = self._port.read(6); + sent = self._port.write(pkt.encode()) + read = self._port.read(6) if read == b'cmd>>:' : break if read == b'fct>>:' : @@ -317,7 +317,7 @@ class phyflasher: def cmd_erase_all_flash(self): print ('Erase All Chip Flash...', end = ' '), if self.wr_flash_cmd(6) and self.wr_flash_cmd(0x60): #Write Enable, Chip Erase - i = 77; + i = 77 while i > 0: r = self.flash_read_status() if r == None: @@ -387,7 +387,7 @@ class phyflasher: return False data = stream.read(size) self._port.write(data) - read = self._port.read(23); #'checksum is: 0x00001d1e' + read = self._port.read(23) #'checksum is: 0x00001d1e' #print ('%s' % read), if read[0:15] != b'checksum is: 0x': print ('error!') @@ -510,14 +510,14 @@ def arg_auto_int(x): def main(): parser = argparse.ArgumentParser(description='%s version %s' % (__progname__, __version__), prog = __filename__) - parser.add_argument('--port', '-p', help = 'Serial port device', default='COM1'); - parser.add_argument('--baud', '-b', help = 'Set Port Baud (115200, 250000, 500000, 1000000)', type = arg_auto_int, default = DEF_RUN_BAUD); + parser.add_argument('--port', '-p', help = 'Serial port device', default='COM1') + parser.add_argument('--baud', '-b', help = 'Set Port Baud rate (115200, 250000, 500000, 1000000)', type = arg_auto_int, default = DEF_RUN_BAUD) - parser.add_argument('--allerase', '-a', action='store_true', help = 'Pre-processing: All Chip Erase'); - parser.add_argument('--erase', '-e', action='store_true', help = 'Pre-processing: Erase Flash work area'); - parser.add_argument('--reset', '-r', action='store_true', help = 'Post-processing: Reset'); - parser.add_argument('--start', '-s', help = 'Application start address for hex writer (default: 0x%08x)' % DEF_START_RUN_APP_ADDR, type = arg_auto_int, default = DEF_START_RUN_APP_ADDR); - parser.add_argument('--write', '-w', help = 'Flash starting address for hex writer (default: 0x%08x)' % DEF_START_WR_FLASH_ADDR, type = arg_auto_int, default = DEF_START_WR_FLASH_ADDR); + parser.add_argument('--allerase', '-a', action='store_true', help = 'Pre-processing: All Chip Erase') + parser.add_argument('--erase', '-e', action='store_true', help = 'Pre-processing: Erase Flash work area') + parser.add_argument('--reset', '-r', action='store_true', help = 'Post-processing: Reset') + parser.add_argument('--start', '-s', help = 'Application start address for hex writer (default: 0x%08x)' % DEF_START_RUN_APP_ADDR, type = arg_auto_int, default = DEF_START_RUN_APP_ADDR) + parser.add_argument('--write', '-w', help = 'Flash starting address for hex writer (default: 0x%08x)' % DEF_START_WR_FLASH_ADDR, type = arg_auto_int, default = DEF_START_WR_FLASH_ADDR) subparsers = parser.add_subparsers( dest='operation', @@ -596,11 +596,11 @@ def main(): #filename = "r%08x-%08x.bin" % (addr, length) if args.size == 0: print("Read Size = 0!" ) - exit(1); + exit(1) try: ff = open(args.filename, "wb") except: - print("Error file open '%s'" % filename) + print("Error file open '%s'" % args.filename) exit(2) if not phy.ReadBusToFile(ff, args.address, args.size): ff.close() @@ -634,7 +634,7 @@ def main(): sys.exit(1) aerase = args.operation == 'we' if args.erase == True or args.allerase == True: - aerase = False; + aerase = False if args.allerase == True: if not phy.cmd_erase_all_flash(): stream.close() @@ -643,7 +643,7 @@ def main(): else: if args.erase == True: if not phy.cmd_erase_work_flash(): - stream.close + stream.close() print ('Error: Erase Flash!') sys.exit(3) phy.SetAutoErase(aerase) @@ -672,7 +672,7 @@ def main(): print ('----------------------------------------------------------') aerase = True if args.erase == True or args.allerase == True: - aerase = False; + aerase = False if args.allerase == True: if not phy.cmd_erase_all_flash(): stream.close() @@ -681,7 +681,7 @@ def main(): else: if args.erase == True: if not phy.cmd_erase_work_flash(): - stream.close + stream.close() print ('Error: Erase Flash!') sys.exit(3) phy.SetAutoErase(aerase) diff --git a/rdwr_phy62x2.py b/rdwr_phy62x2.py index 585269c..8163d6c 100644 --- a/rdwr_phy62x2.py +++ b/rdwr_phy62x2.py @@ -511,7 +511,7 @@ def arg_auto_int(x): def main(): parser = argparse.ArgumentParser(description='%s version %s' % (__progname__, __version__), prog = __filename__) parser.add_argument('--port', '-p', help = 'Serial port device', default='COM1') - parser.add_argument('--baud', '-b', help = 'Set Port Baud (115200, 250000, 500000, 1000000)', type = arg_auto_int, default = DEF_RUN_BAUD) + parser.add_argument('--baud', '-b', help = 'Set Port Baud rate (115200, 250000, 500000, 1000000)', type = arg_auto_int, default = DEF_RUN_BAUD) parser.add_argument('--allerase', '-a', action='store_true', help = 'Pre-processing: All Chip Erase') parser.add_argument('--erase', '-e', action='store_true', help = 'Pre-processing: Erase Flash work area')