mirror of
https://github.com/AG7GN/nexus-utilities.git
synced 2025-05-16 06:30:09 -07:00
Added color customizations to radio-monitor.py
This commit is contained in:
parent
1b2f0d5e47
commit
84e30ecc5e
56
README.md
56
README.md
@ -347,7 +347,61 @@ Your Nexus DR-X image already has the systemd service file for the shutdown scri
|
|||||||
|
|
||||||
## Radio Monitor script
|
## Radio Monitor script
|
||||||
|
|
||||||
`radio-monitor.py` monitors the TX/RX status of your radios via the GPIO pins (BCM 12 for the left radio and BCM 23 for the right radio). The associated Hamradio menu item is in the `radio-monitor.desktop` file.
|
`radio-monitor.py` monitors the TX/RX status of your radios via the GPIO pins. The associated Hamradio menu item is in the `radio-monitor.desktop` file. By default, it monitors BCM GPIO pin 12 for the left radio and BCM GPIO pin 23 for the right radio. You can change these as well as the text color, and background color for TX and RX states from the command line. For options, run `radio-monitor.py -h` in Terminal to see this output:
|
||||||
|
|
||||||
|
usage: radio-monitor.py [-h] [-v]
|
||||||
|
[--left_gpio LEFT_GPIO]
|
||||||
|
[--right_gpio RIGHT_GPIO]
|
||||||
|
[--left_text_color {white,black,red,green,blue,cyan,yellow,magenta}]
|
||||||
|
[--left_bg_rx_color {white,black,red,green,blue,cyan,yellow,magenta}]
|
||||||
|
[--left_bg_tx_color {white,black,red,green,blue,cyan,yellow,magenta}]
|
||||||
|
[--right_text_color {white,black,red,green,blue,cyan,yellow,magenta}]
|
||||||
|
[--right_bg_rx_color {white,black,red,green,blue,cyan,yellow,magenta}]
|
||||||
|
[--right_bg_tx_color {white,black,red,green,blue,cyan,yellow,magenta}]
|
||||||
|
|
||||||
|
TX/RX Status
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
-v, --version show program's version number and exit
|
||||||
|
--left_gpio LEFT_GPIO
|
||||||
|
Left radio PTT GPIO (BCM numbering)
|
||||||
|
(default: 12)
|
||||||
|
--right_gpio RIGHT_GPIO
|
||||||
|
Right radio PTT GPIO (BCM numbering)
|
||||||
|
(default: 23)
|
||||||
|
--left_text_color {white,black,red,green,blue,cyan,yellow,magenta}
|
||||||
|
Text color for left radio indicator
|
||||||
|
(default: yellow)
|
||||||
|
--left_bg_rx_color {white,black,red,green,blue,cyan,yellow,magenta}
|
||||||
|
Background color for left radio RX indicator
|
||||||
|
(default: green)
|
||||||
|
--left_bg_tx_color {white,black,red,green,blue,cyan,yellow,magenta}
|
||||||
|
Background color for left radio TX indicator
|
||||||
|
(default: blue)
|
||||||
|
--right_text_color {white,black,red,green,blue,cyan,yellow,magenta}
|
||||||
|
Text color for right radio indicator
|
||||||
|
(default: yellow)
|
||||||
|
--right_bg_rx_color {white,black,red,green,blue,cyan,yellow,magenta}
|
||||||
|
Background color for right radio RX indicator
|
||||||
|
(default: green)
|
||||||
|
--right_bg_tx_color {white,black,red,green,blue,cyan,yellow,magenta}
|
||||||
|
Background color for right radio TX indicator
|
||||||
|
(default: red)
|
||||||
|
|
||||||
|
To change the way the script runs when launched from the __Hamradio__ menu:
|
||||||
|
|
||||||
|
- Click __Raspberry > Hamradio__, then right-click on __Radio_PTT_Monitor__
|
||||||
|
- Click __Properties__.
|
||||||
|
- Select the __Desktop Entry__ tab.
|
||||||
|
|
||||||
|
As an example, say you want to change the RX background color for the right radio to black and the TX background of the left radio to red. Change the contents of the __Command:__ field to:
|
||||||
|
|
||||||
|
/usr/local/bin/radio-monitor.py --right_bg_rx_color=black --left_bg_tx_color=red
|
||||||
|
|
||||||
|
- Click __OK__
|
||||||
|
|
||||||
|
Note that editing a menu item in this way will create a new `.desktop` file in your `$HOME/.local/share/applications` folder with the same name as the system `.desktop` file in `/usr/local/share/applications` folder. Your local menu item will take precedence over the system file.
|
||||||
|
|
||||||
## Piano Script example
|
## Piano Script example
|
||||||
|
|
||||||
|
119
radio-monitor.py
119
radio-monitor.py
@ -1,60 +1,61 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# ptt.py
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Monitors the status of a BCM GPIO pin in output and updates
|
# Monitors the status of a BCM GPIO pin in output and updates
|
||||||
# a label accordingly.
|
# a label accordingly.
|
||||||
#
|
#
|
||||||
# Author: Steve Magnuson AG7GN
|
|
||||||
|
|
||||||
import Tkinter
|
|
||||||
import tkFont
|
|
||||||
|
|
||||||
|
import tkinter
|
||||||
|
import tkinter.font as tkfont
|
||||||
|
import argparse
|
||||||
from RPi import GPIO
|
from RPi import GPIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
version='0.1.1'
|
__author__ = "Steve Magnuson AG7GN"
|
||||||
win_title='TX/RX Status '
|
__copyright__ = "Copyright 2020, Steve Magnuson"
|
||||||
win_title += version
|
__credits__ = ["Steve Magnuson"]
|
||||||
|
__license__ = "GPL"
|
||||||
|
__version__ = "1.0.0"
|
||||||
|
__maintainer__ = "Steve Magnuson"
|
||||||
|
__email__ = "ag7gn@arrl.net"
|
||||||
|
__status__ = "Production"
|
||||||
|
left_PTT_pin_default = 12
|
||||||
|
right_PTT_pin_default = 23
|
||||||
|
title = 'TX/RX Status'
|
||||||
|
colors=["white", "black", "red", "green", "blue", "cyan", "yellow", "magenta"]
|
||||||
|
|
||||||
left_PTT_pin = 12
|
class StatusWindow(object):
|
||||||
right_PTT_pin = 23
|
|
||||||
|
|
||||||
class StatusWindow:
|
|
||||||
|
|
||||||
poll_interval = 100
|
poll_interval = 100
|
||||||
|
|
||||||
def __init__(self, left_PTT_pin, right_PTT_pin):
|
def __init__(self, iterable=(), **kwargs):
|
||||||
self.left_PTT_pin = left_PTT_pin
|
self.__dict__.update(iterable, **kwargs)
|
||||||
self.right_PTT_pin = right_PTT_pin
|
self.win_title = title
|
||||||
|
self.tkroot = tkinter.Tk()
|
||||||
self.tkroot = Tkinter.Tk()
|
labelFont = tkfont.Font(family = 'Helvetica', size = 18, weight = 'bold')
|
||||||
labelFont = tkFont.Font(family = 'Helvetica', size = 18, weight = 'bold')
|
buttonFont = tkfont.Font(family = 'Helvetica', size = 14)
|
||||||
buttonFont = tkFont.Font(family = 'Helvetica', size = 14)
|
|
||||||
self.tkroot.geometry("400x160")
|
self.tkroot.geometry("400x160")
|
||||||
self.tkroot.title(win_title)
|
self.tkroot.title(f"{self.win_title} - {__version__}")
|
||||||
|
|
||||||
self.set_up_GPIO()
|
self.set_up_GPIO()
|
||||||
|
|
||||||
if GPIO.input(self.left_PTT_pin):
|
if GPIO.input(self.left_PTT_pin):
|
||||||
self.leftRadioStatus = Tkinter.Label(self.tkroot, text="Left Radio\nTX", font=labelFont,
|
self.leftRadioStatus = tkinter.Label(self.tkroot, text="Left Radio\nTX", font=labelFont,
|
||||||
bg="blue", fg="yellow")
|
bg=self.left_bg_tx_color, fg=self.left_text_color)
|
||||||
else:
|
else:
|
||||||
self.leftRadioStatus = Tkinter.Label(self.tkroot, text="Left Radio\nRX", font=labelFont,
|
self.leftRadioStatus = tkinter.Label(self.tkroot, text="Left Radio\nRX", font=labelFont,
|
||||||
bg="green", fg="yellow")
|
bg=self.left_bg_rx_color, fg=self.left_text_color)
|
||||||
self.leftRadioStatus.pack(padx=10, pady=5, side=Tkinter.LEFT, expand=True, fill=Tkinter.X)
|
self.leftRadioStatus.pack(padx=10, pady=5, side=tkinter.LEFT, expand=True, fill=tkinter.X)
|
||||||
if GPIO.input(self.right_PTT_pin):
|
if GPIO.input(self.right_PTT_pin):
|
||||||
self.leftRadioStatus = Tkinter.Label(self.tkroot, text="Right Radio\nTX", font=labelFont,
|
self.leftRadioStatus = tkinter.Label(self.tkroot, text="Right Radio\nTX", font=labelFont,
|
||||||
bg="red", fg="yellow")
|
bg=self.right_bg_rx_color, fg=self.right_text_color)
|
||||||
else:
|
else:
|
||||||
self.rightRadioStatus = Tkinter.Label(self.tkroot, text="Right Radio\nRX", font=labelFont,
|
self.rightRadioStatus = tkinter.Label(self.tkroot, text="Right Radio\nRX", font=labelFont,
|
||||||
bg="green", fg="yellow")
|
bg=self.right_bg_rx_color, fg=self.right_text_color)
|
||||||
self.rightRadioStatus.pack(padx=10, pady=5, side=Tkinter.RIGHT, expand=True, fill=Tkinter.X)
|
self.rightRadioStatus.pack(padx=10, pady=5, side=tkinter.RIGHT, expand=True, fill=tkinter.X)
|
||||||
|
|
||||||
self.exitButton = Tkinter.Button(self.tkroot, text="Quit", command=self.exit,
|
self.exitButton = tkinter.Button(self.tkroot, text="Quit", command=self.exit,
|
||||||
font=buttonFont, relief="raised")
|
font=buttonFont, relief="raised")
|
||||||
self.exitButton.pack(padx=10, pady=5, side=Tkinter.BOTTOM)
|
self.exitButton.pack(padx=10, pady=5, side=tkinter.BOTTOM)
|
||||||
|
|
||||||
self.tkroot.after(self.poll_interval, self.status_handler)
|
self.tkroot.after(self.poll_interval, self.status_handler)
|
||||||
|
|
||||||
@ -73,16 +74,52 @@ class StatusWindow:
|
|||||||
|
|
||||||
def status_handler(self):
|
def status_handler(self):
|
||||||
if GPIO.input(self.left_PTT_pin):
|
if GPIO.input(self.left_PTT_pin):
|
||||||
self.leftRadioStatus.configure(text="Left Radio\nTX", bg="blue")
|
self.leftRadioStatus.configure(text="Left Radio\nTX", bg=self.left_bg_tx_color)
|
||||||
else:
|
else:
|
||||||
self.leftRadioStatus.config(text="Left Radio\nRX", bg="green")
|
self.leftRadioStatus.config(text="Left Radio\nRX", bg=self.left_bg_rx_color)
|
||||||
if GPIO.input(self.right_PTT_pin):
|
if GPIO.input(self.right_PTT_pin):
|
||||||
self.rightRadioStatus.configure(text="Right Radio\nTX", bg="red")
|
self.rightRadioStatus.configure(text="Right Radio\nTX", bg=self.right_bg_tx_color)
|
||||||
else:
|
else:
|
||||||
self.rightRadioStatus.config(text="Right Radio\nRX", bg="green")
|
self.rightRadioStatus.config(text="Right Radio\nRX", bg=self.right_bg_rx_color)
|
||||||
self.tkroot.after(self.poll_interval, self.status_handler)
|
self.tkroot.after(self.poll_interval, self.status_handler)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
win = StatusWindow(left_PTT_pin, right_PTT_pin)
|
parser = argparse.ArgumentParser(prog='radio-monitor.py',
|
||||||
|
description=title,
|
||||||
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
|
parser.add_argument('-v', '--version', action='version',
|
||||||
|
version=f"Version: {__version__}")
|
||||||
|
parser.add_argument("--left_gpio", type=int,
|
||||||
|
help="Left radio PTT GPIO (BCM numbering)",
|
||||||
|
default=left_PTT_pin_default)
|
||||||
|
parser.add_argument("--right_gpio", type=int,
|
||||||
|
help="Right radio PTT GPIO (BCM numbering)",
|
||||||
|
default=right_PTT_pin_default)
|
||||||
|
parser.add_argument("--left_text_color", choices=colors,
|
||||||
|
type=str, default="yellow",
|
||||||
|
help="Text color for left radio indicator")
|
||||||
|
parser.add_argument("--left_bg_rx_color", choices=colors,
|
||||||
|
type=str, default="green",
|
||||||
|
help="Background color for left radio RX indicator")
|
||||||
|
parser.add_argument("--left_bg_tx_color", choices=colors,
|
||||||
|
type=str, default="blue",
|
||||||
|
help="Background color for left radio TX indicator")
|
||||||
|
parser.add_argument("--right_text_color", choices=colors,
|
||||||
|
type=str, default="yellow",
|
||||||
|
help="Text color for right radio indicator")
|
||||||
|
parser.add_argument("--right_bg_rx_color", choices=colors,
|
||||||
|
type=str, default="green",
|
||||||
|
help="Background color for right radio RX indicator")
|
||||||
|
parser.add_argument("--right_bg_tx_color", choices=colors,
|
||||||
|
type=str, default="red",
|
||||||
|
help="Background color for right radio TX indicator")
|
||||||
|
arg_info = parser.parse_args()
|
||||||
|
win = StatusWindow(left_PTT_pin=arg_info.left_gpio,
|
||||||
|
right_PTT_pin=arg_info.right_gpio,
|
||||||
|
left_text_color=arg_info.left_text_color,
|
||||||
|
left_bg_rx_color=arg_info.left_bg_rx_color,
|
||||||
|
left_bg_tx_color=arg_info.left_bg_tx_color,
|
||||||
|
right_text_color=arg_info.right_text_color,
|
||||||
|
right_bg_rx_color=arg_info.right_bg_rx_color,
|
||||||
|
right_bg_tx_color=arg_info.right_bg_tx_color)
|
||||||
win.mainloop()
|
win.mainloop()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user