From 79ed67be8cfd4917ca2bebb7b92430de82ef27b8 Mon Sep 17 00:00:00 2001 From: Michael Clemens Date: Fri, 19 Nov 2021 19:46:33 +0100 Subject: [PATCH] first commit --- README.md | 0 hr50-tk-remote-control.py | 175 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 README.md create mode 100644 hr50-tk-remote-control.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/hr50-tk-remote-control.py b/hr50-tk-remote-control.py new file mode 100644 index 0000000..10b4c7c --- /dev/null +++ b/hr50-tk-remote-control.py @@ -0,0 +1,175 @@ +from tkinter import * +import requests +import json +import tk_tools + +# globally declare the expression variable +btn_bg_color = "light grey" +gauge_pep = None +gauge_avg = None +gauge_tmp = None +gauge_swr = None +api_baseurl = "http://192.168.99.193:5000/" +#status = {} + +buttons = {} + +commands = { + '6m': 'hrbn0', + '10m': 'hrbn1', + '12m': 'hrbn2', + '15m': 'hrbn3', + '17m': 'hrbn4', + '20m': 'hrbn5', + '30m': 'hrbn6', + '40m': 'hrbn7', + '60m': 'hrbn8', + '80m': 'hrbn9', + '160m': 'hrbn10', + 'PTT': 'HRMD1', + 'QRP': 'HRMD3', + 'COR': 'HRMD2', + 'OFF': 'HRMD0' +} + +def reset_buttons(): + for btn in buttons: + buttons[btn].config(bg=btn_bg_color) + +def getStatus(): + #global expression + try: + res = requests.get(api_baseurl + "status").text + status = json.loads(res) + status_text = "Power: " + status["PEP"] + "/" + status["AVG"] + "W SWR: " + status["SWR"] + " Temp: " + status["TMP"] + reset_buttons() + buttons[status["BND"].lower()].config(bg='green') + buttons[status["PTT"]].config(bg='green') + if gauge_pep and status["PEP"].isnumeric(): + gauge_pep.set_value(status["PEP"]) + if gauge_avg and status["AVG"].isnumeric(): + gauge_avg.set_value(status["AVG"]) + if gauge_tmp and status["TMP"][:-1].isnumeric(): + gauge_tmp.set_value(status["TMP"][:-1]) + if gauge_swr: + gauge_swr.set_value(float(status["SWR"])) + led.to_green(on=True) + except: + led.to_red(on=True) + gui.after(4000, getStatus) + + +def press(num): + res = requests.get(api_baseurl + "?cmd=" + commands[num]) + getStatus() + + +# Driver code +if __name__ == "__main__": + + gui = Tk() + gui.title("HR50 Remote Control") + gui.geometry("730x220") + + gauge_pep = tk_tools.Gauge(gui, max_value=70.0, + label='PEP', unit='W', yellow=72, red = 80) + gauge_pep.grid(row=0, column=0, rowspan=2) + gauge_pep.set_value(0) + + gauge_avg = tk_tools.Gauge(gui, max_value=70.0, + label='AVG', unit='W', yellow=72, red = 80) + gauge_avg.grid(row=0, column=1, rowspan=2) + gauge_avg.set_value(0) + + gauge_tmp = tk_tools.Gauge(gui, max_value=80.0, + label='Temp', unit='C') + gauge_tmp.grid(row=2, column=0, rowspan=2) + gauge_tmp.set_value(0) + + gauge_swr = tk_tools.Gauge(gui, max_value=10.0, + label='SWR', unit='', yellow=30, red = 50) + gauge_swr.grid(row=2, column=1, rowspan=2) + gauge_swr.set_value(0) + + + + buttons["160m"] = Button(gui, text=' 160m ', fg='black', bg=btn_bg_color, + command=lambda: press("160m"), height=2, width=7) + buttons["160m"].grid(row=0, column=4) + + buttons["80m"] = Button(gui, text='80m', fg='black', bg=btn_bg_color, + command=lambda: press("80m"), height=2, width=7) + buttons["80m"].grid(row=0, column=6) + + buttons["60m"] = Button(gui, text='60m', fg='black', bg=btn_bg_color, + command=lambda: press("60m"), height=2, width=7) + buttons["60m"].grid(row=0, column=8) + + buttons["PTT"] = Button(gui, text='PTT', fg='black', bg=btn_bg_color, + command=lambda: press("PTT"), height=2, width=7) + buttons["PTT"].grid(row=0, column=10) + + buttons["40m"] = Button(gui, text='40m', fg='black', bg=btn_bg_color, + command=lambda: press("40m"), height=2, width=7) + buttons["40m"].grid(row=1, column=4) + + buttons["30m"] = Button(gui, text='30m', fg='black', bg=btn_bg_color, + command=lambda: press("30m"), height=2, width=7) + buttons["30m"].grid(row=1, column=6) + + buttons["20m"] = Button(gui, text='20m', fg='black', bg=btn_bg_color, + command=lambda: press("20m"), height=2, width=7) + buttons["20m"].grid(row=1, column=8) + + buttons["COR"] = Button(gui, text='COR', fg='black', bg=btn_bg_color, + command=lambda: press("COR"), height=2, width=7) + buttons["COR"].grid(row=1, column=10) + + buttons["17m"] = Button(gui, text='17m', fg='black', bg=btn_bg_color, + command=lambda: press("17m"), height=2, width=7) + buttons["17m"].grid(row=2, column=4) + + buttons["15m"] = Button(gui, text='15m', fg='black', bg=btn_bg_color, + command=lambda: press("15m"), height=2, width=7) + buttons["15m"].grid(row=2, column=6) + + buttons["12m"] = Button(gui, text='12m', fg='black', bg=btn_bg_color, + command=lambda: press("12m"), height=2, width=7) + buttons["12m"].grid(row=2, column=8) + + buttons["QRP"] = Button(gui, text='QRP', fg='black', bg=btn_bg_color, + command=lambda: press("QRP"), height=2, width=7) + buttons["QRP"].grid(row=2, column=10) + + buttons["10m"] = Button(gui, text='10m', fg='black', bg=btn_bg_color, + command=lambda: press("10m"), height=2, width=7) + buttons["10m"].grid(row=3, column=4) + + buttons["6m"] = Button(gui, text='6m', fg='black', bg=btn_bg_color, + command=lambda: press("6m"), height=2, width=7) + buttons["6m"].grid(row=3, column=6) + + buttons["OFF"] = Button(gui, text='OFF', fg='black', bg=btn_bg_color, + command=lambda: press("OFF"), height=2, width=7) + buttons["OFF"].grid(row=3, column=10) + + # fake seperator columns + l0 = Label(gui, text=' \n ') + l0.grid(column=3, row=0, rowspan=4) + l1 = Label(gui, text=' \n ') + l1.grid(column=5, row=0, rowspan=4) + l2 = Label(gui, text=' \n ') + l2.grid(column=7, row=0, rowspan=4) + l3 = Label(gui, text=' \n ') + l3.grid(column=9, row=0, rowspan=4) + + led = tk_tools.Led(gui, size=40) + led.grid(row=3, column=8) + + led.to_red() + led.to_green(on=True) + + getStatus() + + # start the GUI + gui.mainloop()