Skip to content
Open
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ event_vrx_releases
monitor_releases
FW
MONITOR.bin
.spec
.spec
elrs_backpack
elrs_tx
hdzero_radio_stm32.bin
local_path
radio_releases
56 changes: 44 additions & 12 deletions Download.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self):
self.url = ""
self.save_path = ""
self.to_stop = 0
self.pre_download = 0

def download_file(self, url, save_path, clear):
print(f"Downloading {url}")
Expand Down Expand Up @@ -45,18 +46,9 @@ def download_file(self, url, save_path, clear):


def download_thread_proc():
my_download.download_file(
"https://api.github.com/repos/hd-zero/hdzero-vtx/releases", "resource/vtx_releases", 0)
my_download.download_file(
"https://raw.githubusercontent.com/hd-zero/hdzero-vtx/main/src/common.h", "resource/vtx_common", 0)
my_download.download_file(
"https://raw.githubusercontent.com/hd-zero/hdzero-vtx/main/vtx_targets.png", "resource/vtx_targets.png", 0)
my_download.download_file(
"https://api.github.com/repos/ligenxxxx/event-vrx/releases", "resource/event_vrx_releases", 1)
my_download.download_file(
"https://api.github.com/repos/ligenxxxx/hv/releases", "resource/monitor_releases", 1)

time.sleep(1)
while my_download.pre_download != 63:
time.sleep(0.1)

my_download.status = download_status.FILE_PARSE.value

while True:
Expand Down Expand Up @@ -99,7 +91,47 @@ def download_thread_proc():
else:
my_download.status = download_status.DOWNLOAD_EVENT_VRX_FW_FAILED.value

elif my_download.status == download_status.DOWNLOAD_RADIO_FW.value:
ret = my_download.download_file(
my_download.url, my_download.save_path, 1)
if ret == 1:
my_download.status = download_status.DOWNLOAD_RADIO_FW_DONE.value
elif ret == 2: # stop
my_download.status = download_status.IDLE.value
else:
my_download.status = download_status.DOWNLOAD_RADIO_FW_FAILED.value

elif my_download.status == download_status.DOWNLOAD_EXIT.value:
sys.exit()

time.sleep(0.01)

def download_vtx_releases():
my_download.download_file(
"https://api.github.com/repos/hd-zero/hdzero-vtx/releases", "resource/vtx_releases", 0)
my_download.pre_download += 1

def download_vtx_common():
my_download.download_file(
"https://raw.githubusercontent.com/hd-zero/hdzero-vtx/main/src/common.h", "resource/vtx_common", 0)
my_download.pre_download += 2

def download_vtx_targets_image():
my_download.download_file(
"https://raw.githubusercontent.com/hd-zero/hdzero-vtx/main/vtx_targets.png", "resource/vtx_targets.png", 0)
my_download.pre_download += 4

def download_event_vrx_releases():
my_download.download_file(
"https://api.github.com/repos/hd-zero/event-vrx/releases", "resource/event_vrx_releases", 1)
my_download.pre_download += 8

def download_monitor_releases():
my_download.download_file(
"https://api.github.com/repos/hd-zero/monitor/releases", "resource/monitor_releases", 1)
my_download.pre_download += 16

def download_radio_releases():
my_download.download_file(
"https://api.github.com/repos/ligenxxxx/radio/releases", "resource/radio_releases", 1)
my_download.pre_download += 32
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
## python version
## Python Version

windows 3.10.5 32-bit

## How To Run

### Create venv

### Install package

```
.venv/Scripts/python.exe -m pip install Pillow pyserial esptool xmodem requests pyinstaller
```

### Run hdzero_programmer.py

## generate exe

```
Expand Down
46 changes: 46 additions & 0 deletions ch341.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import os
from ctypes import create_string_buffer
from frame_monitor import frame_monitor
from program_radio import my_radio
import tkinter as tk
from tkinter import ttk
from global_var import *
from ctypes import *
import global_var
import subprocess
import zipfile


class ch341_class(object):
Expand Down Expand Up @@ -78,6 +80,9 @@ def __init__(self):
self.buffer_size = 2560
self.write_buffer = create_string_buffer(self.buffer_size)

self.fw_index = 0
self.update_error_flag = 0

try:
self.dll = ctypes.WinDLL(self.dll_name)
except:
Expand Down Expand Up @@ -125,6 +130,13 @@ def parse_event_vrx_fw(self, fw_path):
return 0
except:
return 0
def parse_radio_fw(self, fw_path):
try:
with zipfile.ZipFile(fw_path, "r") as z:
z.extractall("resource/")
return 1
except:
return 0

def ch341read_i2c(self, addr):
self.dll.CH341ReadI2C(0, self.addr_fpga_device, addr, self.iobuffer)
Expand Down Expand Up @@ -609,5 +621,39 @@ def ch341_thread_proc():
else:
my_ch341.write_event_vrx_fw_to_flash(my_ch341.fw_path)
my_ch341.status = ch341_status.EVENT_VRX_UPDATEDONE.value

# ---------------------- Radio ------------------------------------
elif my_ch341.status == ch341_status.RADIO_DISCONNECTED.value: # connect radio
if my_radio.radio_is_active() != 0:
my_ch341.status = ch341_status.RADIO_CONNECTED.value
elif my_ch341.status == ch341_status.RADIO_UPDATE_ELRS_TX.value: # update elrs tx
if my_ch341.parse_radio_fw(my_ch341.fw_path) == 0:
my_ch341.status = ch341_status.RADIO_FW_ERROR.value

my_ch341.fw_index = 1
my_ch341.update_error_flag = 0

if my_radio.program_elrs_tx() == False:
my_ch341.update_error_flag = 1
my_ch341.status = ch341_status.RADIO_UPDATE_ELRS_BACKPACK.value

elif my_ch341.status == ch341_status.RADIO_UPDATE_ELRS_BACKPACK.value: # update elrs backpack
my_ch341.written_len = 400
my_ch341.fw_index = 2

if my_radio.program_elrs_backpack() == False:
my_ch341.update_error_flag += 2
my_ch341.status = ch341_status.RADIO_UPDATE_STM32.value

elif my_ch341.status == ch341_status.RADIO_UPDATE_STM32.value: # update elrs backpack
my_ch341.written_len = 800
my_ch341.fw_index = 3
if my_radio.program_stm32() == False:
my_ch341.status = ch341_status.RADIO_UPDATE_STM32_FAILED.value
elif my_ch341.update_error_flag:
my_ch341.status = ch341_status.RADIO_UPDATE_ELRS_FAILED.value
else:
my_ch341.status = ch341_status.RADIO_UPDATE_DONE.value

else:
time.sleep(0.1)
22 changes: 22 additions & 0 deletions frame_radio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk


class frame_radio:
def __init__(self, parent):
self._parent = parent
self._frame = tk.Frame(parent)
parent.add(self._frame, text="Radio")
self.image_path = "resource/radio.png"
self.show_image()

def frame(self):
return self._frame

def show_image(self):
image = Image.open(self.image_path)
photo = ImageTk.PhotoImage(image)
label = ttk.Label(self._frame, image=photo)
label.image = photo
label.pack()
17 changes: 17 additions & 0 deletions global_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class ch341_status(Enum):
EVENT_VRX_UPDATEDONE = 25
EVENT_VRX_FW_ERROR = 26

RADIO_DISCONNECTED = 31
RADIO_CONNECTED = 32
RADIO_GET_FW = 33
RADIO_UPDATE_ELRS_TX = 34
RADIO_UPDATE_ELRS_BACKPACK = 35
RADIO_UPDATE_STM32 = 36
RADIO_UPDATE_DONE = 37
RADIO_FW_ERROR = 38
RADIO_UPDATE_STM32_FAILED = 39
RADIO_UPDATE_ELRS_FAILED = 40

STATUS_EXIT = 255


Expand All @@ -55,4 +66,10 @@ class download_status(Enum):
DOWNLOAD_EVENT_VRX_FW = 20
DOWNLOAD_EVENT_VRX_FW_DONE = 21
DOWNLOAD_EVENT_VRX_FW_FAILED = 22

DOWNLOAD_RADIO_FW = 30
DOWNLOAD_RADIO_FW_DONE = 31
DOWNLOAD_RADIO_FW_FAILED = 32


DOWNLOAD_EXIT = 255
38 changes: 35 additions & 3 deletions hdzero_programmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
import os
import sys
import shutil
import time
from main_window import ui_thread_proc
from download import download_thread_proc
from download import download_vtx_releases
from download import download_vtx_common
from download import download_vtx_targets_image
from download import download_event_vrx_releases
from download import download_monitor_releases
from download import download_radio_releases
from ch341 import ch341_thread_proc


Expand Down Expand Up @@ -37,16 +44,41 @@ def check_and_release_resource():

def main():
check_and_release_resource()
download_thread = threading.Thread(
target=download_thread_proc, name="download")
download_thread.start()

ui_thread = threading.Thread(target=ui_thread_proc, name="ui")
ui_thread.start()

ch341_thread = threading.Thread(target=ch341_thread_proc, name="ch341")
ch341_thread.start()

time.sleep(1)

download_0 = threading.Thread(
target=download_vtx_releases, name="download_vtx_releases")
download_0.start()
download_1 = threading.Thread(
target=download_vtx_common, name="download_vtx_common")
download_1.start()

download_2 = threading.Thread(
target=download_vtx_targets_image, name="download_vtx_targets_image")
download_2.start()

download_3 = threading.Thread(
target=download_event_vrx_releases, name="download_event_vrx_releases")
download_3.start()

download_4 = threading.Thread(
target=download_monitor_releases, name="download_monitor_releases")
download_4.start()

download_5 = threading.Thread(
target=download_radio_releases, name="download_radio_releases")
download_5.start()

download_thread = threading.Thread(
target=download_thread_proc, name="download")
download_thread.start()

if __name__ == '__main__':
main()
Loading