fix bugs
This commit is contained in:
parent
3f3f834ed9
commit
c069db02d8
110
src/main.py
110
src/main.py
|
@ -17,7 +17,9 @@ class App(ctk.CTk):
|
|||
__column_weight = [1, 9, 3]
|
||||
serial_status = False
|
||||
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_store = gain_default.copy()
|
||||
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.grid(column=0, row=0, rowspan=3, sticky=ctk.NSEW, padx=20)
|
||||
|
||||
gain_frame = []
|
||||
gain_str = []
|
||||
gain_label = []
|
||||
gain_slider = []
|
||||
gain_button = []
|
||||
gain_checkbox = []
|
||||
gain_frame: list[ctk.CTkFrame] = []
|
||||
gain_str: list[ctk.StringVar] = []
|
||||
gain_label: list[ctk.CTkLabel] = []
|
||||
self.gain_slider: list[ctk.CTkSlider] = []
|
||||
gain_button: list[ctk.CTkButton] = []
|
||||
self.gain_checkbox: list[ctk.CTkCheckBox] = []
|
||||
for i in range(5):
|
||||
if i == 0:
|
||||
label_frame = ctk.CTkFrame(blender_frame, fg_color="#596062")
|
||||
label_frame.pack(side='top', fill=ctk.BOTH)
|
||||
gain_checkbox.append(
|
||||
label_frame.pack(side="top", fill=ctk.BOTH, pady=10)
|
||||
self.gain_checkbox.append(
|
||||
ctk.CTkCheckBox(
|
||||
label_frame,
|
||||
text="颜色矫正",
|
||||
font=self.font,
|
||||
)
|
||||
)
|
||||
gain_checkbox[i].select()
|
||||
gain_checkbox[i].pack(side="left", ipady=10, padx=70)
|
||||
gain_checkbox.append(
|
||||
self.gain_checkbox[i].select()
|
||||
self.gain_checkbox[i].pack(side="left", ipady=10, padx=70)
|
||||
self.gain_checkbox.append(
|
||||
ctk.CTkCheckBox(
|
||||
label_frame,
|
||||
text="自动白平衡",
|
||||
font=self.font,
|
||||
command=functools.partial(switchCorrection, 5)
|
||||
command=functools.partial(switchCorrection, 5),
|
||||
)
|
||||
)
|
||||
gain_checkbox[i + 1].select()
|
||||
gain_checkbox[i + 1].pack(side="right", ipady=10, padx=70)
|
||||
self.gain_checkbox[i + 1].select()
|
||||
self.gain_checkbox[i + 1].pack(side="right", ipady=10, padx=70)
|
||||
|
||||
# gain_frame
|
||||
if i < 3:
|
||||
|
@ -288,36 +290,42 @@ class App(ctk.CTk):
|
|||
side="top", ipady=10
|
||||
)
|
||||
else:
|
||||
gain_checkbox.append(
|
||||
self.gain_checkbox.append(
|
||||
ctk.CTkCheckBox(
|
||||
gain_frame[i],
|
||||
text=text[i],
|
||||
font=self.font,
|
||||
)
|
||||
)
|
||||
gain_checkbox[i - 1].select()
|
||||
gain_checkbox[i - 1].pack(side="top", ipady=10)
|
||||
self.gain_checkbox[i - 1].select()
|
||||
self.gain_checkbox[i - 1].pack(side="top", ipady=10)
|
||||
|
||||
# slider
|
||||
gain_slider.append(
|
||||
self.gain_slider.append(
|
||||
ctk.CTkSlider(gain_frame[i], from_=gain_min[i], to=gain_max[i])
|
||||
)
|
||||
gain_slider[i].set(self.gain_default[i])
|
||||
gain_slider[i].pack(side="top", fill=ctk.X, padx=10)
|
||||
self.gain_slider[i].set(self.gain_default[i])
|
||||
self.gain_slider[i].pack(side="top", fill=ctk.X, padx=10)
|
||||
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
|
||||
gain_slider[i].configure(
|
||||
self.gain_slider[i].configure(
|
||||
command=functools.partial(setGain, i=i, stringVar=gain_str[i])
|
||||
)
|
||||
if i >= 3:
|
||||
gain_checkbox[0].configure(
|
||||
command=functools.partial(switchCorrection, 0, gain_slider[0], gain_slider[1], gain_slider[2])
|
||||
self.gain_checkbox[0].configure(
|
||||
command=functools.partial(
|
||||
switchCorrection,
|
||||
0,
|
||||
self.gain_slider[0],
|
||||
self.gain_slider[1],
|
||||
self.gain_slider[2],
|
||||
)
|
||||
)
|
||||
gain_checkbox[i - 1].configure(
|
||||
command=functools.partial(switchCorrection, i, gain_slider[i])
|
||||
self.gain_checkbox[i - 1].configure(
|
||||
command=functools.partial(switchCorrection, i, self.gain_slider[i])
|
||||
)
|
||||
|
||||
# gain value
|
||||
|
@ -342,7 +350,7 @@ class App(ctk.CTk):
|
|||
data_frame,
|
||||
text="使用推荐配置",
|
||||
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,
|
||||
)
|
||||
|
@ -477,8 +485,22 @@ class App(ctk.CTk):
|
|||
for i in range(5):
|
||||
if self.gain_enable[i]:
|
||||
bytes = list(map(lambda x: ord(x), list(switchSign(i))))
|
||||
bytes.append(int(self.gain_values[i]))
|
||||
bytes.append(int(self.gain_values[i] % 1 * 256))
|
||||
bytes.append(
|
||||
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("d"))
|
||||
print(
|
||||
|
@ -494,15 +516,15 @@ class App(ctk.CTk):
|
|||
messagebox.showError("Please Connect Serial Port")
|
||||
|
||||
def setvideo(self, video: int) -> None:
|
||||
def switchSign (i:int) -> str:
|
||||
def switchSign(i: int) -> str:
|
||||
match i:
|
||||
case 0: # switch day
|
||||
case 0: # switch day
|
||||
return "cmdvdd"
|
||||
case 1: # night
|
||||
case 1: # night
|
||||
return "cmdvdn"
|
||||
case 2: # start video
|
||||
case 2: # start video
|
||||
return "cmdvds"
|
||||
case 3: # stop video
|
||||
case 3: # stop video
|
||||
return "cmdvdp"
|
||||
case _:
|
||||
return "error"
|
||||
|
@ -513,10 +535,22 @@ class App(ctk.CTk):
|
|||
messagebox.showError("Please Connect to Serial")
|
||||
else:
|
||||
if is_open:
|
||||
if video >= 0 and video < 4:
|
||||
self.serial.write(( switchSign(video) + 'ed' ).encode())
|
||||
if video == 0 or video == 1:
|
||||
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:
|
||||
messagebox.showError('Set Video Wrong')
|
||||
messagebox.showError("Set Video Wrong")
|
||||
else:
|
||||
messagebox.showError("Please Open Serial")
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue