mirror of
https://codeberg.org/mclemens/HR50_Tk_Remote_Control.git
synced 2024-06-13 03:30:42 +00:00
„hr50-tk-remote-control.py“ ändern
This commit is contained in:
parent
79ed67be8c
commit
8bb6e51948
|
@ -3,45 +3,19 @@ import requests
|
||||||
import json
|
import json
|
||||||
import tk_tools
|
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/"
|
api_baseurl = "http://192.168.99.193:5000/"
|
||||||
#status = {}
|
|
||||||
|
|
||||||
|
btn_bg_color = "light grey"
|
||||||
buttons = {}
|
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():
|
def reset_buttons():
|
||||||
for btn in buttons:
|
for btn in buttons:
|
||||||
buttons[btn].config(bg=btn_bg_color)
|
buttons[btn].config(bg=btn_bg_color)
|
||||||
|
|
||||||
def getStatus():
|
def getStatus():
|
||||||
#global expression
|
|
||||||
try:
|
try:
|
||||||
res = requests.get(api_baseurl + "status").text
|
res = requests.get(api_baseurl + "status").text
|
||||||
status = json.loads(res)
|
status = json.loads(res)
|
||||||
status_text = "Power: " + status["PEP"] + "/" + status["AVG"] + "W SWR: " + status["SWR"] + " Temp: " + status["TMP"]
|
|
||||||
reset_buttons()
|
reset_buttons()
|
||||||
buttons[status["BND"].lower()].config(bg='green')
|
buttons[status["BND"].lower()].config(bg='green')
|
||||||
buttons[status["PTT"]].config(bg='green')
|
buttons[status["PTT"]].config(bg='green')
|
||||||
|
@ -56,103 +30,98 @@ def getStatus():
|
||||||
led.to_green(on=True)
|
led.to_green(on=True)
|
||||||
except:
|
except:
|
||||||
led.to_red(on=True)
|
led.to_red(on=True)
|
||||||
gui.after(4000, getStatus)
|
gui.after(5000, getStatus)
|
||||||
|
|
||||||
|
|
||||||
def press(num):
|
def press(keypad):
|
||||||
res = requests.get(api_baseurl + "?cmd=" + commands[num])
|
try:
|
||||||
getStatus()
|
res = requests.get(api_baseurl + "?cmd=" + keypad)
|
||||||
|
except:
|
||||||
|
led.to_red(on=True)
|
||||||
|
#getStatus()
|
||||||
|
|
||||||
|
|
||||||
# Driver code
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
gui = Tk()
|
gui = Tk()
|
||||||
gui.title("HR50 Remote Control")
|
gui.title("HR50 Remote Control")
|
||||||
gui.geometry("730x220")
|
gui.geometry("730x220")
|
||||||
|
gui.resizable(False, False)
|
||||||
|
|
||||||
|
# Gauge for displaying PEP of last transmission
|
||||||
gauge_pep = tk_tools.Gauge(gui, max_value=70.0,
|
gauge_pep = tk_tools.Gauge(gui, max_value=70.0,
|
||||||
label='PEP', unit='W', yellow=72, red = 80)
|
label='PEP', unit='W', yellow=72, red = 80)
|
||||||
gauge_pep.grid(row=0, column=0, rowspan=2)
|
gauge_pep.grid(row=0, column=0, rowspan=2)
|
||||||
gauge_pep.set_value(0)
|
gauge_pep.set_value(0)
|
||||||
|
|
||||||
|
# Gauge for displaying average power of last transmission
|
||||||
gauge_avg = tk_tools.Gauge(gui, max_value=70.0,
|
gauge_avg = tk_tools.Gauge(gui, max_value=70.0,
|
||||||
label='AVG', unit='W', yellow=72, red = 80)
|
label='AVG', unit='W', yellow=72, red = 80)
|
||||||
gauge_avg.grid(row=0, column=1, rowspan=2)
|
gauge_avg.grid(row=0, column=1, rowspan=2)
|
||||||
gauge_avg.set_value(0)
|
gauge_avg.set_value(0)
|
||||||
|
|
||||||
|
# Gauge for displaying the temperature of the heatsink
|
||||||
gauge_tmp = tk_tools.Gauge(gui, max_value=80.0,
|
gauge_tmp = tk_tools.Gauge(gui, max_value=80.0,
|
||||||
label='Temp', unit='C')
|
label='Temp', unit='C')
|
||||||
gauge_tmp.grid(row=2, column=0, rowspan=2)
|
gauge_tmp.grid(row=2, column=0, rowspan=2)
|
||||||
gauge_tmp.set_value(0)
|
gauge_tmp.set_value(0)
|
||||||
|
|
||||||
|
# Gauge for displaying the SWR suring the last transmission
|
||||||
gauge_swr = tk_tools.Gauge(gui, max_value=10.0,
|
gauge_swr = tk_tools.Gauge(gui, max_value=10.0,
|
||||||
label='SWR', unit='', yellow=30, red = 50)
|
label='SWR', unit='', yellow=30, red = 50)
|
||||||
gauge_swr.grid(row=2, column=1, rowspan=2)
|
gauge_swr.grid(row=2, column=1, rowspan=2)
|
||||||
gauge_swr.set_value(0)
|
gauge_swr.set_value(0)
|
||||||
|
|
||||||
|
|
||||||
|
# Define and place buttons
|
||||||
buttons["160m"] = Button(gui, text=' 160m ', fg='black', bg=btn_bg_color,
|
buttons["160m"] = Button(gui, text='160m', command=lambda: press("hrbn10"))
|
||||||
command=lambda: press("160m"), height=2, width=7)
|
|
||||||
buttons["160m"].grid(row=0, column=4)
|
buttons["160m"].grid(row=0, column=4)
|
||||||
|
|
||||||
buttons["80m"] = Button(gui, text='80m', fg='black', bg=btn_bg_color,
|
buttons["80m"] = Button(gui, text='80m', command=lambda: press("hrbn9"))
|
||||||
command=lambda: press("80m"), height=2, width=7)
|
|
||||||
buttons["80m"].grid(row=0, column=6)
|
buttons["80m"].grid(row=0, column=6)
|
||||||
|
|
||||||
buttons["60m"] = Button(gui, text='60m', fg='black', bg=btn_bg_color,
|
buttons["60m"] = Button(gui, text='60m', command=lambda: press("hrbn8"))
|
||||||
command=lambda: press("60m"), height=2, width=7)
|
|
||||||
buttons["60m"].grid(row=0, column=8)
|
buttons["60m"].grid(row=0, column=8)
|
||||||
|
|
||||||
buttons["PTT"] = Button(gui, text='PTT', fg='black', bg=btn_bg_color,
|
buttons["PTT"] = Button(gui, text='PTT', command=lambda: press("HRMD1"))
|
||||||
command=lambda: press("PTT"), height=2, width=7)
|
|
||||||
buttons["PTT"].grid(row=0, column=10)
|
buttons["PTT"].grid(row=0, column=10)
|
||||||
|
|
||||||
buttons["40m"] = Button(gui, text='40m', fg='black', bg=btn_bg_color,
|
buttons["40m"] = Button(gui, text='40m', command=lambda: press("hrbn7"))
|
||||||
command=lambda: press("40m"), height=2, width=7)
|
|
||||||
buttons["40m"].grid(row=1, column=4)
|
buttons["40m"].grid(row=1, column=4)
|
||||||
|
|
||||||
buttons["30m"] = Button(gui, text='30m', fg='black', bg=btn_bg_color,
|
buttons["30m"] = Button(gui, text='30m', command=lambda: press("hrbn6"))
|
||||||
command=lambda: press("30m"), height=2, width=7)
|
|
||||||
buttons["30m"].grid(row=1, column=6)
|
buttons["30m"].grid(row=1, column=6)
|
||||||
|
|
||||||
buttons["20m"] = Button(gui, text='20m', fg='black', bg=btn_bg_color,
|
buttons["20m"] = Button(gui, text='20m', command=lambda: press("hrbn5"))
|
||||||
command=lambda: press("20m"), height=2, width=7)
|
|
||||||
buttons["20m"].grid(row=1, column=8)
|
buttons["20m"].grid(row=1, column=8)
|
||||||
|
|
||||||
buttons["COR"] = Button(gui, text='COR', fg='black', bg=btn_bg_color,
|
buttons["COR"] = Button(gui, text='COR', command=lambda: press("HRMD2"))
|
||||||
command=lambda: press("COR"), height=2, width=7)
|
|
||||||
buttons["COR"].grid(row=1, column=10)
|
buttons["COR"].grid(row=1, column=10)
|
||||||
|
|
||||||
buttons["17m"] = Button(gui, text='17m', fg='black', bg=btn_bg_color,
|
buttons["17m"] = Button(gui, text='17m', command=lambda: press("hrbn4"))
|
||||||
command=lambda: press("17m"), height=2, width=7)
|
|
||||||
buttons["17m"].grid(row=2, column=4)
|
buttons["17m"].grid(row=2, column=4)
|
||||||
|
|
||||||
buttons["15m"] = Button(gui, text='15m', fg='black', bg=btn_bg_color,
|
buttons["15m"] = Button(gui, text='15m', command=lambda: press("hrbn3"))
|
||||||
command=lambda: press("15m"), height=2, width=7)
|
|
||||||
buttons["15m"].grid(row=2, column=6)
|
buttons["15m"].grid(row=2, column=6)
|
||||||
|
|
||||||
buttons["12m"] = Button(gui, text='12m', fg='black', bg=btn_bg_color,
|
buttons["12m"] = Button(gui, text='12m', command=lambda: press("hrbn2"))
|
||||||
command=lambda: press("12m"), height=2, width=7)
|
|
||||||
buttons["12m"].grid(row=2, column=8)
|
buttons["12m"].grid(row=2, column=8)
|
||||||
|
|
||||||
buttons["QRP"] = Button(gui, text='QRP', fg='black', bg=btn_bg_color,
|
buttons["QRP"] = Button(gui, text='QRP', command=lambda: press("HRMD3"))
|
||||||
command=lambda: press("QRP"), height=2, width=7)
|
|
||||||
buttons["QRP"].grid(row=2, column=10)
|
buttons["QRP"].grid(row=2, column=10)
|
||||||
|
|
||||||
buttons["10m"] = Button(gui, text='10m', fg='black', bg=btn_bg_color,
|
buttons["10m"] = Button(gui, text='10m', command=lambda: press("hrbn1"))
|
||||||
command=lambda: press("10m"), height=2, width=7)
|
|
||||||
buttons["10m"].grid(row=3, column=4)
|
buttons["10m"].grid(row=3, column=4)
|
||||||
|
|
||||||
buttons["6m"] = Button(gui, text='6m', fg='black', bg=btn_bg_color,
|
buttons["6m"] = Button(gui, text='6m', command=lambda: press("hrbn0"))
|
||||||
command=lambda: press("6m"), height=2, width=7)
|
|
||||||
buttons["6m"].grid(row=3, column=6)
|
buttons["6m"].grid(row=3, column=6)
|
||||||
|
|
||||||
buttons["OFF"] = Button(gui, text='OFF', fg='black', bg=btn_bg_color,
|
buttons["OFF"] = Button(gui, text='OFF', command=lambda: press("HRMD0"))
|
||||||
command=lambda: press("OFF"), height=2, width=7)
|
|
||||||
buttons["OFF"].grid(row=3, column=10)
|
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
|
# fake seperator columns
|
||||||
l0 = Label(gui, text=' \n ')
|
l0 = Label(gui, text=' \n ')
|
||||||
l0.grid(column=3, row=0, rowspan=4)
|
l0.grid(column=3, row=0, rowspan=4)
|
||||||
|
@ -166,7 +135,6 @@ if __name__ == "__main__":
|
||||||
led = tk_tools.Led(gui, size=40)
|
led = tk_tools.Led(gui, size=40)
|
||||||
led.grid(row=3, column=8)
|
led.grid(row=3, column=8)
|
||||||
|
|
||||||
led.to_red()
|
|
||||||
led.to_green(on=True)
|
led.to_green(on=True)
|
||||||
|
|
||||||
getStatus()
|
getStatus()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user