Skip to content

Commit

Permalink
Merge pull request #119 from mbridak/master
Browse files Browse the repository at this point in the history
back port from main.
  • Loading branch information
mbridak committed Jul 25, 2024
2 parents 45962cd + 51f9e52 commit b6b2132
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ generated, 'cause I'm lazy, list of those who've submitted PR's.

## Recent Changes

- [24-7-25-1] Have VFO dock widget handle disconnect/reconnect events of the USB VFO knob more gracefully.
- [24-7-25] Updated application categories for the desktop file.
- [24-7-25] Maybe let flrig send CW... Probably not.
- [24-7-19] Use Qt's QSettings to store window and dockwidgets states.
Expand Down
2 changes: 1 addition & 1 deletion not1mm/lib/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""It's the version"""

__version__ = "24.7.25"
__version__ = "24.7.25.1"
25 changes: 21 additions & 4 deletions not1mm/vfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class VfoWindow(QDockWidget):
message_shown = False
multicast_interface = None
current_palette = None
device_reconnect = False

def __init__(self):
super().__init__()
Expand All @@ -64,6 +65,7 @@ def __init__(self):
self.poll_rig_timer = QtCore.QTimer()
self.poll_rig_timer.timeout.connect(self.poll_radio)
self.poll_rig_timer.start(500)
self.visibilityChanged.connect(self.window_state_changed)

def setDarkMode(self, dark: bool) -> None:
"""Forces a darkmode palette."""
Expand Down Expand Up @@ -178,27 +180,37 @@ def discover_device(self) -> str:
if "vfoknob" in data.decode().strip():
return device

def setup_serial(self) -> None:
def window_state_changed(self):
"""Setup vfo knob if window is toggled on"""

if self.isVisible():
self.setup_serial()

def setup_serial(self, supress_msg=False) -> None:
"""
Setup the device returned by discover_device()
Or display message saying we didn't find one.
"""

if not self.isVisible():
return

device = self.discover_device()
if device:
try:
self.pico = serial.Serial("/dev/serial/by-id/" + device, 115200)
self.pico.timeout = 100
self.lcdNumber.setStyleSheet("QLCDNumber { color: white; }")
self.device_reconnect = True
except OSError:
if self.message_shown is False:
if self.message_shown is False and supress_msg is False:
self.message_shown = True
self.show_message_box(
"Unable to locate or open the VFO knob serial device."
)
self.lcdNumber.setStyleSheet("QLCDNumber { color: red; }")
else:
if self.message_shown is False:
if self.message_shown is False and supress_msg is False:
self.message_shown = True
self.show_message_box(
"Unable to locate or open the VFO knob serial device."
Expand Down Expand Up @@ -269,13 +281,14 @@ def poll_radio(self) -> None:
return
if vfo < 1700000 or vfo > 60000000:
return
if vfo != self.old_vfo:
if vfo != self.old_vfo or self.device_reconnect is True:
self.old_vfo = vfo
logger.debug(f"{vfo}")
self.showNumber(vfo)
# self.lcdNumber.display(dnum)
# app.processEvents()
cmd = f"F {vfo}\r"
self.device_reconnect = False
try:
if self.pico:
self.pico.write(cmd.encode())
Expand All @@ -302,10 +315,14 @@ def getwaiting(self) -> None:
self.showNumber(result)
# self.lcdNumber.display(result)
# app.processEvents()
else:
self.setup_serial(supress_msg=True)
except OSError:
logger.critical("Unable to write to serial device.")
self.pico = None
except AttributeError:
logger.critical("Unable to write to serial device.")
self.pico = None
# app.processEvents()

def show_message_box(self, message: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "not1mm"
version = "24.7.25"
version = "24.7.25.1"
description = "NOT1MM Logger"
readme = "README.md"
requires-python = ">=3.9"
Expand Down

0 comments on commit b6b2132

Please sign in to comment.