143 lines
4.6 KiB
Python
143 lines
4.6 KiB
Python
from tkinter import *
|
|
import requests
|
|
import json
|
|
import tk_tools
|
|
|
|
api_baseurl = "http://192.168.99.193:5000/"
|
|
|
|
btn_bg_color = "light grey"
|
|
buttons = {}
|
|
|
|
def reset_buttons():
|
|
for btn in buttons:
|
|
buttons[btn].config(bg=btn_bg_color)
|
|
|
|
def getStatus():
|
|
try:
|
|
res = requests.get(api_baseurl + "status").text
|
|
status = json.loads(res)
|
|
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(5000, getStatus)
|
|
|
|
|
|
def press(keypad):
|
|
try:
|
|
res = requests.get(api_baseurl + "?cmd=" + keypad)
|
|
except:
|
|
led.to_red(on=True)
|
|
#getStatus()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
gui = Tk()
|
|
gui.title("HR50 Remote Control")
|
|
gui.geometry("730x220")
|
|
gui.resizable(False, False)
|
|
|
|
# Gauge for displaying PEP of last transmission
|
|
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 for displaying average power of last transmission
|
|
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 for displaying the temperature of the heatsink
|
|
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 for displaying the SWR suring the last transmission
|
|
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)
|
|
|
|
|
|
# Define and place buttons
|
|
buttons["160m"] = Button(gui, text='160m', command=lambda: press("hrbn10"))
|
|
buttons["160m"].grid(row=0, column=4)
|
|
|
|
buttons["80m"] = Button(gui, text='80m', command=lambda: press("hrbn9"))
|
|
buttons["80m"].grid(row=0, column=6)
|
|
|
|
buttons["60m"] = Button(gui, text='60m', command=lambda: press("hrbn8"))
|
|
buttons["60m"].grid(row=0, column=8)
|
|
|
|
buttons["PTT"] = Button(gui, text='PTT', command=lambda: press("HRMD1"))
|
|
buttons["PTT"].grid(row=0, column=10)
|
|
|
|
buttons["40m"] = Button(gui, text='40m', command=lambda: press("hrbn7"))
|
|
buttons["40m"].grid(row=1, column=4)
|
|
|
|
buttons["30m"] = Button(gui, text='30m', command=lambda: press("hrbn6"))
|
|
buttons["30m"].grid(row=1, column=6)
|
|
|
|
buttons["20m"] = Button(gui, text='20m', command=lambda: press("hrbn5"))
|
|
buttons["20m"].grid(row=1, column=8)
|
|
|
|
buttons["COR"] = Button(gui, text='COR', command=lambda: press("HRMD2"))
|
|
buttons["COR"].grid(row=1, column=10)
|
|
|
|
buttons["17m"] = Button(gui, text='17m', command=lambda: press("hrbn4"))
|
|
buttons["17m"].grid(row=2, column=4)
|
|
|
|
buttons["15m"] = Button(gui, text='15m', command=lambda: press("hrbn3"))
|
|
buttons["15m"].grid(row=2, column=6)
|
|
|
|
buttons["12m"] = Button(gui, text='12m', command=lambda: press("hrbn2"))
|
|
buttons["12m"].grid(row=2, column=8)
|
|
|
|
buttons["QRP"] = Button(gui, text='QRP', command=lambda: press("HRMD3"))
|
|
buttons["QRP"].grid(row=2, column=10)
|
|
|
|
buttons["10m"] = Button(gui, text='10m', command=lambda: press("hrbn1"))
|
|
buttons["10m"].grid(row=3, column=4)
|
|
|
|
buttons["6m"] = Button(gui, text='6m', command=lambda: press("hrbn0"))
|
|
buttons["6m"].grid(row=3, column=6)
|
|
|
|
buttons["OFF"] = Button(gui, text='OFF', command=lambda: press("HRMD0"))
|
|
buttons["OFF"].grid(row=3, column=10)
|
|
|
|
for btn in buttons:
|
|
buttons[btn].config(fg='black', bg=btn_bg_color, height=2, width=7)
|
|
|
|
# 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_green(on=True)
|
|
|
|
getStatus()
|
|
|
|
# start the GUI
|
|
gui.mainloop() |