„hr50-tk-remote-control.py“ ändern

This commit is contained in:
Michael Clemens 2021-11-19 22:57:06 +01:00
parent 79ed67be8c
commit 8bb6e51948
1 changed files with 33 additions and 65 deletions

View File

@ -3,45 +3,19 @@ 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 = {}
btn_bg_color = "light grey"
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')
@ -56,103 +30,98 @@ def getStatus():
led.to_green(on=True)
except:
led.to_red(on=True)
gui.after(4000, getStatus)
gui.after(5000, getStatus)
def press(num):
res = requests.get(api_baseurl + "?cmd=" + commands[num])
getStatus()
def press(keypad):
try:
res = requests.get(api_baseurl + "?cmd=" + keypad)
except:
led.to_red(on=True)
#getStatus()
# Driver code
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)
buttons["160m"] = Button(gui, text=' 160m ', fg='black', bg=btn_bg_color,
command=lambda: press("160m"), height=2, width=7)
# 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', fg='black', bg=btn_bg_color,
command=lambda: press("80m"), height=2, width=7)
buttons["80m"] = Button(gui, text='80m', command=lambda: press("hrbn9"))
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"] = Button(gui, text='60m', command=lambda: press("hrbn8"))
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"] = Button(gui, text='PTT', command=lambda: press("HRMD1"))
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"] = Button(gui, text='40m', command=lambda: press("hrbn7"))
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"] = Button(gui, text='30m', command=lambda: press("hrbn6"))
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"] = Button(gui, text='20m', command=lambda: press("hrbn5"))
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"] = Button(gui, text='COR', command=lambda: press("HRMD2"))
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"] = Button(gui, text='17m', command=lambda: press("hrbn4"))
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"] = Button(gui, text='15m', command=lambda: press("hrbn3"))
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"] = Button(gui, text='12m', command=lambda: press("hrbn2"))
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"] = Button(gui, text='QRP', command=lambda: press("HRMD3"))
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"] = Button(gui, text='10m', command=lambda: press("hrbn1"))
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"] = Button(gui, text='6m', command=lambda: press("hrbn0"))
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"] = 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)
@ -166,10 +135,9 @@ if __name__ == "__main__":
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()
gui.mainloop()