This commit is contained in:
SelfConfusion 2024-07-13 03:29:49 +08:00
parent 3f3f834ed9
commit c069db02d8
1 changed files with 72 additions and 38 deletions

View File

@ -17,7 +17,9 @@ class App(ctk.CTk):
__column_weight = [1, 9, 3] __column_weight = [1, 9, 3]
serial_status = False serial_status = False
serial_baudrate = 9600 serial_baudrate = 9600
gain_default = [1.30, 0.70, 1.10, 2.20, 0.50] default_day = [1.10, 0.70, 1.10, 1.20, 0.60]
default_night = [1.30, 0.70, 1.10, 2.20, 0.50]
gain_default = default_day
gain_values = gain_default.copy() gain_values = gain_default.copy()
gain_values_store = gain_default.copy() gain_values_store = gain_default.copy()
gain_enable = [True for i in range(6)] gain_enable = [True for i in range(6)]
@ -244,35 +246,35 @@ class App(ctk.CTk):
blender_frame = ctk.CTkFrame(data_frame, fg_color="#596062") blender_frame = ctk.CTkFrame(data_frame, fg_color="#596062")
blender_frame.grid(column=0, row=0, rowspan=3, sticky=ctk.NSEW, padx=20) blender_frame.grid(column=0, row=0, rowspan=3, sticky=ctk.NSEW, padx=20)
gain_frame = [] gain_frame: list[ctk.CTkFrame] = []
gain_str = [] gain_str: list[ctk.StringVar] = []
gain_label = [] gain_label: list[ctk.CTkLabel] = []
gain_slider = [] self.gain_slider: list[ctk.CTkSlider] = []
gain_button = [] gain_button: list[ctk.CTkButton] = []
gain_checkbox = [] self.gain_checkbox: list[ctk.CTkCheckBox] = []
for i in range(5): for i in range(5):
if i == 0: if i == 0:
label_frame = ctk.CTkFrame(blender_frame, fg_color="#596062") label_frame = ctk.CTkFrame(blender_frame, fg_color="#596062")
label_frame.pack(side='top', fill=ctk.BOTH) label_frame.pack(side="top", fill=ctk.BOTH, pady=10)
gain_checkbox.append( self.gain_checkbox.append(
ctk.CTkCheckBox( ctk.CTkCheckBox(
label_frame, label_frame,
text="颜色矫正", text="颜色矫正",
font=self.font, font=self.font,
) )
) )
gain_checkbox[i].select() self.gain_checkbox[i].select()
gain_checkbox[i].pack(side="left", ipady=10, padx=70) self.gain_checkbox[i].pack(side="left", ipady=10, padx=70)
gain_checkbox.append( self.gain_checkbox.append(
ctk.CTkCheckBox( ctk.CTkCheckBox(
label_frame, label_frame,
text="自动白平衡", text="自动白平衡",
font=self.font, font=self.font,
command=functools.partial(switchCorrection, 5) command=functools.partial(switchCorrection, 5),
) )
) )
gain_checkbox[i + 1].select() self.gain_checkbox[i + 1].select()
gain_checkbox[i + 1].pack(side="right", ipady=10, padx=70) self.gain_checkbox[i + 1].pack(side="right", ipady=10, padx=70)
# gain_frame # gain_frame
if i < 3: if i < 3:
@ -288,36 +290,42 @@ class App(ctk.CTk):
side="top", ipady=10 side="top", ipady=10
) )
else: else:
gain_checkbox.append( self.gain_checkbox.append(
ctk.CTkCheckBox( ctk.CTkCheckBox(
gain_frame[i], gain_frame[i],
text=text[i], text=text[i],
font=self.font, font=self.font,
) )
) )
gain_checkbox[i - 1].select() self.gain_checkbox[i - 1].select()
gain_checkbox[i - 1].pack(side="top", ipady=10) self.gain_checkbox[i - 1].pack(side="top", ipady=10)
# slider # slider
gain_slider.append( self.gain_slider.append(
ctk.CTkSlider(gain_frame[i], from_=gain_min[i], to=gain_max[i]) ctk.CTkSlider(gain_frame[i], from_=gain_min[i], to=gain_max[i])
) )
gain_slider[i].set(self.gain_default[i]) self.gain_slider[i].set(self.gain_default[i])
gain_slider[i].pack(side="top", fill=ctk.X, padx=10) self.gain_slider[i].pack(side="top", fill=ctk.X, padx=10)
gain_str.append( gain_str.append(
ctk.StringVar(gain_slider[i], f"{self.gain_default[i]:.2f}") ctk.StringVar(self.gain_slider[i], f"{self.gain_default[i]:.2f}")
) )
# set command # set command
gain_slider[i].configure( self.gain_slider[i].configure(
command=functools.partial(setGain, i=i, stringVar=gain_str[i]) command=functools.partial(setGain, i=i, stringVar=gain_str[i])
) )
if i >= 3: if i >= 3:
gain_checkbox[0].configure( self.gain_checkbox[0].configure(
command=functools.partial(switchCorrection, 0, gain_slider[0], gain_slider[1], gain_slider[2]) command=functools.partial(
switchCorrection,
0,
self.gain_slider[0],
self.gain_slider[1],
self.gain_slider[2],
)
) )
gain_checkbox[i - 1].configure( self.gain_checkbox[i - 1].configure(
command=functools.partial(switchCorrection, i, gain_slider[i]) command=functools.partial(switchCorrection, i, self.gain_slider[i])
) )
# gain value # gain value
@ -342,7 +350,7 @@ class App(ctk.CTk):
data_frame, data_frame,
text="使用推荐配置", text="使用推荐配置",
command=functools.partial( command=functools.partial(
switchSlider, i=i, slider=gain_slider[i], value=gain_str[i] switchSlider, i=i, slider=self.gain_slider[i], value=gain_str[i]
), ),
font=self.font, font=self.font,
) )
@ -477,8 +485,22 @@ class App(ctk.CTk):
for i in range(5): for i in range(5):
if self.gain_enable[i]: if self.gain_enable[i]:
bytes = list(map(lambda x: ord(x), list(switchSign(i)))) bytes = list(map(lambda x: ord(x), list(switchSign(i))))
bytes.append(int(self.gain_values[i])) bytes.append(
bytes.append(int(self.gain_values[i] % 1 * 256)) int(
self.gain_values[i]
if self.gain_values[i] > 0
else 255
if self.gain_values[i] < 0 and self.gain_values[i] > -1.0
else (~int(abs(self.gain_values[i])) + 1) % 256
)
)
bytes.append(
int(
(self.gain_values[i] % 1 * 256)
if self.gain_values[i] > 0
else (~int(abs(self.gain_values[i] * 256)) + 1) % 256
)
)
bytes.append(ord("e")) bytes.append(ord("e"))
bytes.append(ord("d")) bytes.append(ord("d"))
print( print(
@ -494,15 +516,15 @@ class App(ctk.CTk):
messagebox.showError("Please Connect Serial Port") messagebox.showError("Please Connect Serial Port")
def setvideo(self, video: int) -> None: def setvideo(self, video: int) -> None:
def switchSign (i:int) -> str: def switchSign(i: int) -> str:
match i: match i:
case 0: # switch day case 0: # switch day
return "cmdvdd" return "cmdvdd"
case 1: # night case 1: # night
return "cmdvdn" return "cmdvdn"
case 2: # start video case 2: # start video
return "cmdvds" return "cmdvds"
case 3: # stop video case 3: # stop video
return "cmdvdp" return "cmdvdp"
case _: case _:
return "error" return "error"
@ -513,10 +535,22 @@ class App(ctk.CTk):
messagebox.showError("Please Connect to Serial") messagebox.showError("Please Connect to Serial")
else: else:
if is_open: if is_open:
if video >= 0 and video < 4: if video == 0 or video == 1:
self.serial.write(( switchSign(video) + 'ed' ).encode()) if video == 0:
self.gain_default = self.default_day
elif video == 1:
self.gain_default = self.default_night
self.serial.write((switchSign(video) + "ed").encode())
for i in range(4):
if self.gain_checkbox[i].get() == 0:
self.gain_checkbox[i].toggle()
time.sleep(0.001)
self.setISP()
elif video >= 2 and video <= 3:
self.serial.write((switchSign(video) + "ed").encode())
else: else:
messagebox.showError('Set Video Wrong') messagebox.showError("Set Video Wrong")
else: else:
messagebox.showError("Please Open Serial") messagebox.showError("Please Open Serial")
return None return None