Skip to content

Commit

Permalink
Add pyserial into the equation
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed May 20, 2020
1 parent 5dccced commit 72ab73a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ openvario-shell = {editable = true,path = "."}
urwid = "*"
typing-extensions = "*"
importlib-metadata = "*"
pyserial-asyncio = "*"
pyserial = "*"
24 changes: 20 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions src/ovshell_core/ext.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Sequence
import asyncio

from ovshell import protocol

from ovshell_core import settings
from ovshell_core import serial


class CoreExtension(protocol.Extension):
Expand All @@ -26,7 +26,10 @@ def list_settings(self) -> Sequence[protocol.Setting]:
]

def start(self) -> None:
self.shell.processes.start(maintain_serial_devices())
devlookup = serial.SerialDeviceLookupImpl()
self.shell.processes.start(
serial.maintain_serial_devices(self.shell, devlookup)
)

def _init_settings(self) -> None:
config = self.shell.settings
Expand All @@ -38,8 +41,3 @@ def _apply_font(self) -> None:
font = config.get("core.font", str)
if font is not None:
settings.apply_font(self.shell.os, font)


async def maintain_serial_devices():
while True:
await asyncio.sleep(1)
26 changes: 26 additions & 0 deletions src/ovshell_core/serial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Sequence
from typing_extensions import Protocol
import asyncio

from serial.tools import list_ports

from ovshell import protocol


class SerialDeviceLookup(Protocol):
def enumerate(self) -> Sequence[str]:
pass


class SerialDeviceLookupImpl(SerialDeviceLookup):
def enumerate(self) -> Sequence[str]:
devs = list_ports.comports(include_links=False)
return [d.device for d in devs]


async def maintain_serial_devices(
shell: protocol.OpenVarioShell, devlookup: SerialDeviceLookup
) -> None:
while True:
devs = devlookup.enumerate()
await asyncio.sleep(1)

0 comments on commit 72ab73a

Please sign in to comment.