Skip to content

Commit

Permalink
set osd on/off with checkbutton
Browse files Browse the repository at this point in the history
  • Loading branch information
ligenxxxx committed May 15, 2024
1 parent 238205d commit 9b1105e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ch341.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self):
self.addr_backlight = 0x25
self.addr_cell_count = 0x26
self.addr_warning_cell_voltage = 0x27
self.addr_osd = 0x28
self.addr_fpga_device = 0x65 # 7bit address

self.target_id = 0
Expand Down Expand Up @@ -137,6 +138,8 @@ def read_setting(self):
global_var.cell_count = self.ch341read_i2c(self.addr_cell_count)
global_var.warning_cell_voltage = self.ch341read_i2c(
self.addr_warning_cell_voltage)
global_var.osd = self.ch341read_i2c(self.addr_osd)

fpga_version = self.ch341read_i2c(0xff)
print(f"cell:{global_var.cell_count:d} warning_cell:{global_var.warning_cell_voltage:d} fpga_version:0x{fpga_version:2x}")

Expand Down
45 changes: 44 additions & 1 deletion frame_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, parent):
self.addr_usb_write_backlight = 0x17
self.addr_usb_write_cell_count = 0x18
self.addr_usb_write_warning_cell_voltage = 0x19
self.addr_usb_write_osd = 0x1A

self.brightness_min = 0
self.brightness_max = 254
Expand All @@ -42,27 +43,35 @@ def __init__(self, parent):
self.warning_cell_voltage_min = 28
self.warning_cell_voltage_max = 42
self.warning_cell_voltage_default = 28
self.osd_min = 0
self.osd_max = 1
self.osd_default = 1

self.brightness_scale = 0
self.contrast_scale = 0
self.saturation_scale = 0
self.backlight_scale = 0
self.cell_count_scale = 0
self.warning_cell_voltage_scale = 0
self.osd_checkbutton = 0

self.osd_var = tk.BooleanVar()

self._frame.grid_rowconfigure(0, weight=1)
self._frame.grid_rowconfigure(1, weight=1)
self._frame.grid_rowconfigure(2, weight=1)
self._frame.grid_rowconfigure(3, weight=1)
self._frame.grid_rowconfigure(4, weight=1)
self._frame.grid_rowconfigure(5, weight=1)
self._frame.grid_rowconfigure(6, weight=1)

self._frame.grid_columnconfigure(0, weight=0)
self._frame.grid_columnconfigure(1, weight=0)
self._frame.grid_columnconfigure(2, weight=0)

self.init_image_setting()
self.init_power_setting()
self.init_osd_setting()

try:
self.dll = ctypes.WinDLL(self.dll_name)
Expand Down Expand Up @@ -108,7 +117,11 @@ def write_warning_cell_voltage(self, warning_cell):
self.write_i2c(self.addr_usb_write_warning_cell_voltage, warning_cell)
# print(f"write_warning_cell_voltage {warning_cell}")

def write_setting(self, b, c, s, l, cell, warning_cell):
def write_osd(self, osd):
global_var.osd = osd
self.write_i2c(self.addr_usb_write_osd, osd)

def write_setting(self, b, c, s, l, cell, warning_cell, osd):
"""write setting from vrx.
usually used for sync vrx setting.
NOTE: Must run after setting_enable
Expand All @@ -126,12 +139,16 @@ def write_setting(self, b, c, s, l, cell, warning_cell):
if warning_cell < self.warning_cell_voltage_min or warning_cell > self.warning_cell_voltage_max:
warning_cell = self.warning_cell_voltage_default

if osd < self.osd_min or osd > self.osd_max:
osd = self.osd_default

self.write_brightness(b)
self.write_contrast(c)
self.write_saturation(s)
self.write_backlight(l)
self.write_cell_count(cell)
self.write_warning_cell_voltage(warning_cell)
self.write_osd(osd)

# update scale
self.brightness_scale.set(b)
Expand All @@ -141,6 +158,11 @@ def write_setting(self, b, c, s, l, cell, warning_cell):
self.cell_count_scale.set(cell)
self.warning_cell_voltage_scale.set(warning_cell)

if osd == 1:
self.osd_var.set(True)
else:
self.osd_var.set(False)

# update label
self.brightness_label.config(text=f'{b}')
self.contrast_label.config(text=f'{c}')
Expand All @@ -158,6 +180,7 @@ def setting_disable(self):
self.backlight_scale.configure(state="disabled")
self.cell_count_scale.configure(state="disabled")
self.warning_cell_voltage_scale.configure(state="disabled")
self.osd_checkbutton.configure(state="disabled")

def setting_enable(self):
self.brightness_scale.configure(state="normal")
Expand All @@ -166,6 +189,7 @@ def setting_enable(self):
self.backlight_scale.configure(state="normal")
self.cell_count_scale.configure(state="normal")
self.warning_cell_voltage_scale.configure(state="normal")
self.osd_checkbutton.configure(state="normal")

def reset_scale(self):
self.brightness_scale.set(self.brightness_min)
Expand All @@ -174,6 +198,7 @@ def reset_scale(self):
self.backlight_scale.set(self.backlight_min)
self.cell_count_scale.set(self.cell_count_min)
self.warning_cell_voltage_scale.set(self.warning_cell_voltage_min)
self.osd_var.set(False)

self.brightness_label.config(text=f"{int(float(self.brightness_min))}")
self.brightness_label.config(text=f"{int(float(self.contrast_min))}")
Expand All @@ -183,6 +208,8 @@ def reset_scale(self):
self.on_cell_count_scale_changed(self.cell_count_min)
self.on_warning_cell_voltage_scale_changed(
self.warning_cell_voltage_min)
self.osd_var.set(False)
self.on_osd_checkoutbutton_changed()

def frame(self):
return self._frame
Expand Down Expand Up @@ -215,6 +242,12 @@ def on_warning_cell_voltage_scale_changed(self, value):
text=f"{self.warning_cell_voltage/10}")
self.write_warning_cell_voltage(int(float(value)))

def on_osd_checkoutbutton_changed(self):
if self.osd_var.get() == True:
self.write_osd(1)
else:
self.write_osd(0)

def init_image_setting(self):
# brighrness
row = 0
Expand Down Expand Up @@ -288,3 +321,13 @@ def init_power_setting(self):
self.warning_cell_voltage_label = ttk.Label(self._frame, text="2.8")
self.warning_cell_voltage_label.grid(
row=row, column=2, sticky="w", padx=10)

def init_osd_setting(self):
row = 6

label = ttk.Label(self._frame, text="OSD")
label.grid(row=row, column=0, sticky="w", padx=20)

self.osd_checkbutton = ttk.Checkbutton(
self._frame, variable=self.osd_var, text = "", command=self.on_osd_checkoutbutton_changed)
self.osd_checkbutton.grid(row=row, column=0, sticky="w", padx=100)
1 change: 1 addition & 0 deletions global_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
backlight = 100
cell_count = 1
warning_cell_voltage = 28
osd = 0

nIndex = 0
PAGE_SIZE = 256
Expand Down
2 changes: 1 addition & 1 deletion main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def refresh(self):
# self._programmer_frame.update_button_disable()

self._monitor_frame.write_setting(global_var.brightness, global_var.contrast, global_var.saturation,
global_var.backlight, global_var.cell_count, global_var.warning_cell_voltage)
global_var.backlight, global_var.cell_count, global_var.warning_cell_voltage, global_var.osd)
self.monitor_is_alive = 1
elif self.monitor_is_alive == 1 and my_ch341.monitor_connected == 0: # to disconnect monitor
self.monitor_is_alive = 0
Expand Down

0 comments on commit 9b1105e

Please sign in to comment.