Skip to content

Commit

Permalink
Update pySVS.py
Browse files Browse the repository at this point in the history
Final fix for the scales I hope
  • Loading branch information
logon84 authored Dec 29, 2023
1 parent 22eafc3 commit 9dfd2b4
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions pySVS.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"STANDBY":{"id":4, "offset":0x4, "limits": [0,1,2], "limits_type":1, "n_bytes":2, "reset_id": 2 }, #discrete
"BRIGHTNESS":{"id":4, "offset":0x6, "limits": [0,1,2,3,4,5,6,7], "limits_type":1, "n_bytes":2, "reset_id": 14 }, #discrete
"LOW_PASS_FILTER_ALL_SETTINGS":{"id":4, "offset":0x8, "limits": [], "limits_type":"group", "n_bytes":6, "reset_id": 3 }, #group
"LPF_ENABLE":{"id":4, "offset":0x8, "limits": [0,1], "limits_type":1, "n_bytes":2, "reset_id": 3 }, #discrete
"LOW_PASS_FILTER_ENABLE":{"id":4, "offset":0x8, "limits": [0,1], "limits_type":1, "n_bytes":2, "reset_id": 3 }, #discrete
"LOW_PASS_FILTER_FREQ":{"id":4, "offset":0xa, "limits": [30, 200], "limits_type":0, "n_bytes":2, "reset_id": 3 }, #continous
"LOW_PASS_FILTER_SLOPE":{"id":4, "offset":0xc,"limits": [6, 12, 18, 24], "limits_type":1, "n_bytes":2, "reset_id": 3 }, #discrete
"PEQ1_ALL_SETTINGS":{"id":4, "offset":0xe,"limits": [], "limits_type":"group", "n_bytes":8, "reset_id": 5 }, #group
Expand Down Expand Up @@ -386,7 +386,7 @@ def autoon_combo_changed(self):

def lpf_opt_changed():
refresh_widgets()
TX.BUFFER += svs_encode("MEMWRITE","LPF_ENABLE", int(lpf_var.get()))
TX.BUFFER += svs_encode("MEMWRITE","LOW_PASS_FILTER_ENABLE", int(lpf_var.get()))

def update_lpfilter_freq(self):
if lpf_var.get():
Expand Down Expand Up @@ -448,9 +448,27 @@ def room_gain_opt_changed():
refresh_widgets()
TX.BUFFER += svs_encode("MEMWRITE","ROOM_GAIN_ENABLE", int(room_gain_var.get()))

def update_room_gain_freq(self):
def update_room_gain_freq(event):
if room_gain_var.get():
#as this callback is called when the click is released, be sure only to send svs memwrite only if room_gain = on
current_index = SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"].index(room_gain_slider.get())
if event.type == "5": #Button1Release
res = (max(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]) - min(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]))/room_gain_slider.cget("length")
click_release_value = min(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]) + res * event.x
if abs(room_gain_slider.get() - click_release_value) > 3:
#going here means we weren't dragging the slider but clicked the scale to move the slider to a new position
if click_release_value > room_gain_slider.get():
next_index = (current_index + 1) if current_index < (len(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]) - 1) else len(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]) - 1
room_gain_slider.set(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"][next_index])
else:
next_index = (current_index - 1) if current_index > 0 else 0
room_gain_slider.set(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"][next_index])
elif event.keysym == 'Right': #KeyRelease
next_index = (current_index + 1) if current_index < (len(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]) - 1) else len(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]) - 1
room_gain_slider.set(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"][next_index])
elif event.keysym == 'Left': #KeyRelease
next_index = (current_index - 1) if current_index > 0 else 0
room_gain_slider.set(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"][next_index])
TX.BUFFER += svs_encode("MEMWRITE","ROOM_GAIN_FREQ", room_gain_slider.get())

def update_room_gain_slope(self):
Expand Down Expand Up @@ -504,7 +522,7 @@ def refresh_widgets(values_dict={}):
for key in values_dict.keys():
if key == "STANDBY":
autoon_combo.current(int(values_dict[key]))
elif key == "LPF_ENABLE":
elif key == "LOW_PASS_FILTER_ENABLE":
lpf_var.set(bool(values_dict[key]))
elif key == "LOW_PASS_FILTER_FREQ":
lpfilter_slider.configure(state='normal')
Expand Down Expand Up @@ -640,7 +658,7 @@ def show_usage():
return

if __name__ == "__main__":
VERSION = "v3.32 Beta"
VERSION = "v3.4 Beta"
dev="hci0"
if len(sys.argv[1:]) > 0:
GUI = 0
Expand Down Expand Up @@ -678,7 +696,7 @@ def show_usage():
built_frames += svs_encode("SUB_INFO3", "")
elif opt in ("-l", "--lpf"):
if len(opt_val.split("@")) == 3:
sub_params = ["LPF_ENABLE","LOW_PASS_FILTER_FREQ","LOW_PASS_FILTER_SLOPE"]
sub_params = ["LOW_PASS_FILTER_ENABLE","LOW_PASS_FILTER_FREQ","LOW_PASS_FILTER_SLOPE"]
for i in range(0,3):
if len(opt_val.split("@")[i]) > 0:
built_frames += svs_encode("MEMREAD", sub_params[i]) if opt_val.split("@")[i].upper() == 'A' else svs_encode("MEMWRITE", sub_params[i], int(float(opt_val.split("@")[i])))
Expand Down Expand Up @@ -773,18 +791,21 @@ def show_usage():
vol_slider = tk.Scale(tab1, from_=min(SVS_PARAMS["VOLUME"]["limits"]), to=max(SVS_PARAMS["VOLUME"]["limits"]), label = "Volume (dB)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PHASE"]["limits"][0]) == int else 0.1, length=200, takefocus=1)
vol_slider.grid(column=4, row=3, padx = 20, pady = 15)
vol_slider.bind("<ButtonRelease-1>", update_vol)
vol_slider.bind("<ButtonRelease-2>", update_vol)
vol_slider.bind("<KeyRelease-Left>", update_vol)
vol_slider.bind("<KeyRelease-Right>", update_vol)

phase_slider = tk.Scale(tab1, from_=min(SVS_PARAMS["PHASE"]["limits"]), to=max(SVS_PARAMS["PHASE"]["limits"]), label = "Phase (°)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PHASE"]["limits"][0]) == int else 0.1, length=200, takefocus=1)
phase_slider.grid(column=4, row=5, padx = 20, pady = 15)
phase_slider.bind("<ButtonRelease-1>", update_phase)
phase_slider.bind("<ButtonRelease-2>", update_phase)
phase_slider.bind("<KeyRelease-Left>", update_phase)
phase_slider.bind("<KeyRelease-Right>", update_phase)

lpfilter_slider = tk.Scale(tab1, from_=min(SVS_PARAMS["LOW_PASS_FILTER_FREQ"]["limits"]), to=max(SVS_PARAMS["LOW_PASS_FILTER_FREQ"]["limits"]), label = "Low Pass Filter Freq. (Hz)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["LOW_PASS_FILTER_FREQ"]["limits"][0]) == int else 0.1, length=200, takefocus=1)
lpfilter_slider.grid(column=4, row=7, padx = 20, pady = 15)
lpfilter_slider.bind("<ButtonRelease-1>", update_lpfilter_freq)
lpfilter_slider.bind("<ButtonRelease-2>", update_lpfilter_freq)
lpfilter_slider.bind("<KeyRelease-Left>", update_lpfilter_freq)
lpfilter_slider.bind("<KeyRelease-Right>", update_lpfilter_freq)
lpfilter_slope_combo=ttk.Combobox(tab1,values=[str(l) + " dB" for l in SVS_PARAMS["LOW_PASS_FILTER_SLOPE"]["limits"]],width=7,state='readonly')
Expand All @@ -796,6 +817,7 @@ def show_usage():

room_gain_slider = tk.Scale(tab1, from_=min(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]), to=max(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"]), label = "Room Gain Freq. (Hz)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["ROOM_GAIN_FREQ"]["limits"][0]) == int else 0.1, length=200, takefocus=1, command=make_room_gain_freq_discrete_slider)
room_gain_slider.bind("<ButtonRelease-1>", update_room_gain_freq)
room_gain_slider.bind("<ButtonRelease-2>", update_room_gain_freq)
room_gain_slider.bind("<KeyRelease-Left>", update_room_gain_freq)
room_gain_slider.bind("<KeyRelease-Right>", update_room_gain_freq)
room_gain_slider.grid(column=4, row=9, padx = 20, pady = 15)
Expand All @@ -820,16 +842,19 @@ def show_usage():
PEQ1_checkbox.place(x=40,y=15)
PEQ1_freq_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ1_FREQ"]["limits"]), to=max(SVS_PARAMS["PEQ1_FREQ"]["limits"]), label = "Freq (Hz)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ1_FREQ"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ1_freq_slider.bind("<ButtonRelease-1>", update_peq1_freq)
PEQ1_freq_slider.bind("<ButtonRelease-2>", update_peq1_freq)
PEQ1_freq_slider.bind("<KeyRelease-Left>", update_peq1_freq)
PEQ1_freq_slider.bind("<KeyRelease-Right>", update_peq1_freq)
PEQ1_freq_slider.grid(column=7, row=3, padx = 35, pady = 35)
PEQ1_boost_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ1_BOOST"]["limits"]), to=max(SVS_PARAMS["PEQ1_BOOST"]["limits"]), label = "Boost (dB)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ1_BOOST"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ1_boost_slider.bind("<ButtonRelease-1>", update_peq1_boost)
PEQ1_boost_slider.bind("<ButtonRelease-2>", update_peq1_boost)
PEQ1_boost_slider.bind("<KeyRelease-Left>", update_peq1_boost)
PEQ1_boost_slider.bind("<KeyRelease-Right>", update_peq1_boost)
PEQ1_boost_slider.grid(column=7, row=5, padx = 20, pady = 15)
PEQ1_qfactor_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ1_QFACTOR"]["limits"]), to=max(SVS_PARAMS["PEQ1_QFACTOR"]["limits"]), label = "Q-Factor", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ1_QFACTOR"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ1_qfactor_slider.bind("<ButtonRelease-1>", update_peq1_qfactor)
PEQ1_qfactor_slider.bind("<ButtonRelease-2>", update_peq1_qfactor)
PEQ1_qfactor_slider.bind("<KeyRelease-Left>", update_peq1_qfactor)
PEQ1_qfactor_slider.bind("<KeyRelease-Right>", update_peq1_qfactor)
PEQ1_qfactor_slider.grid(column=7, row=7, padx = 20, pady = 35)
Expand All @@ -839,16 +864,19 @@ def show_usage():
PEQ2_checkbox.place(x=215,y=15)
PEQ2_freq_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ2_FREQ"]["limits"]), to=max(SVS_PARAMS["PEQ2_FREQ"]["limits"]), label = "Freq (Hz)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ2_FREQ"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ2_freq_slider.bind("<ButtonRelease-1>", update_peq2_freq)
PEQ2_freq_slider.bind("<ButtonRelease-2>", update_peq2_freq)
PEQ2_freq_slider.bind("<KeyRelease-Left>", update_peq2_freq)
PEQ2_freq_slider.bind("<KeyRelease-Right>", update_peq2_freq)
PEQ2_freq_slider.grid(column=8, row=3, padx = 35, pady = 35)
PEQ2_boost_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ2_BOOST"]["limits"]), to=max(SVS_PARAMS["PEQ2_BOOST"]["limits"]), label = "Boost (dB)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ2_BOOST"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ2_boost_slider.bind("<ButtonRelease-1>", update_peq2_boost)
PEQ2_boost_slider.bind("<ButtonRelease-2>", update_peq2_boost)
PEQ2_boost_slider.bind("<KeyRelease-Left>", update_peq2_boost)
PEQ2_boost_slider.bind("<KeyRelease-Right>", update_peq2_boost)
PEQ2_boost_slider.grid(column=8, row=5, padx = 20, pady = 15)
PEQ2_qfactor_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ2_QFACTOR"]["limits"]), to=max(SVS_PARAMS["PEQ2_QFACTOR"]["limits"]), label = "Q-Factor", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ2_QFACTOR"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ2_qfactor_slider.bind("<ButtonRelease-1>", update_peq2_qfactor)
PEQ2_qfactor_slider.bind("<ButtonRelease-2>", update_peq2_qfactor)
PEQ2_qfactor_slider.bind("<KeyRelease-Left>", update_peq2_qfactor)
PEQ2_qfactor_slider.bind("<KeyRelease-Right>", update_peq2_qfactor)
PEQ2_qfactor_slider.grid(column=8, row=7, padx = 20, pady = 35)
Expand All @@ -858,16 +886,19 @@ def show_usage():
PEQ3_checkbox.place(x=390,y=15)
PEQ3_freq_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ3_FREQ"]["limits"]), to=max(SVS_PARAMS["PEQ3_FREQ"]["limits"]), label = "Freq (Hz)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ3_FREQ"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ3_freq_slider.bind("<ButtonRelease-1>", update_peq3_freq)
PEQ3_freq_slider.bind("<ButtonRelease-2>", update_peq3_freq)
PEQ3_freq_slider.bind("<KeyRelease-Left>", update_peq3_freq)
PEQ3_freq_slider.bind("<KeyRelease-Right>", update_peq3_freq)
PEQ3_freq_slider.grid(column=9, row=3, padx = 35, pady = 35)
PEQ3_boost_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ3_BOOST"]["limits"]), to=max(SVS_PARAMS["PEQ3_BOOST"]["limits"]), label = "Boost (dB)", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ3_BOOST"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ3_boost_slider.bind("<ButtonRelease-1>", update_peq3_boost)
PEQ3_boost_slider.bind("<ButtonRelease-2>", update_peq3_boost)
PEQ3_boost_slider.bind("<KeyRelease-Left>", update_peq3_boost)
PEQ3_boost_slider.bind("<KeyRelease-Right>", update_peq3_boost)
PEQ3_boost_slider.grid(column=9, row=5, padx = 20, pady = 15)
PEQ3_qfactor_slider = tk.Scale(tab2, from_=min(SVS_PARAMS["PEQ3_QFACTOR"]["limits"]), to=max(SVS_PARAMS["PEQ3_QFACTOR"]["limits"]), label = "Q-Factor", orient=tk.HORIZONTAL, resolution=1 if type(SVS_PARAMS["PEQ3_QFACTOR"]["limits"][0]) == int else 0.1, length=100, takefocus=1)
PEQ3_qfactor_slider.bind("<ButtonRelease-1>", update_peq3_qfactor)
PEQ3_qfactor_slider.bind("<ButtonRelease-2>", update_peq3_qfactor)
PEQ3_qfactor_slider.bind("<KeyRelease-Left>", update_peq3_qfactor)
PEQ3_qfactor_slider.bind("<KeyRelease-Right>", update_peq3_qfactor)
PEQ3_qfactor_slider.grid(column=9, row=7, padx = 20, pady = 35)
Expand Down

0 comments on commit 9dfd2b4

Please sign in to comment.