diff options
author | Devaev Maxim <[email protected]> | 2018-10-05 20:03:40 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-10-05 20:06:39 +0300 |
commit | a87963e300b489831c3809c4321c8747752fc6c6 (patch) | |
tree | 57480d30fd822ac648df39cfb711e6a3aadaf5e1 /kvmd | |
parent | bbaf99c1b4a19ec6438f794bc045777443cbaaf2 (diff) |
msd pinout
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/extras/cleanup/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/msd.py | 27 | ||||
-rw-r--r-- | kvmd/server.py | 6 |
4 files changed, 34 insertions, 4 deletions
diff --git a/kvmd/__init__.py b/kvmd/__init__.py index 110b80a7..da430634 100644 --- a/kvmd/__init__.py +++ b/kvmd/__init__.py @@ -37,8 +37,11 @@ def main() -> None: ) msd = MassStorageDevice( + target=int(config["msd"]["pinout"]["target"]), + reset=int(config["msd"]["pinout"]["reset"]), device_path=str(config["msd"]["device"]), init_delay=float(config["msd"]["init_delay"]), + reset_delay=float(config["msd"]["reset_delay"]), write_meta=bool(config["msd"]["write_meta"]), loop=loop, ) diff --git a/kvmd/extras/cleanup/__init__.py b/kvmd/extras/cleanup/__init__.py index 5ac09ecb..75b35562 100644 --- a/kvmd/extras/cleanup/__init__.py +++ b/kvmd/extras/cleanup/__init__.py @@ -16,6 +16,8 @@ def main() -> None: logger.info("Cleaning up ...") with gpio.bcm(): for (name, pin) in [ + ("msd_target", config["msd"]["pinout"]["target"]), + ("msd_reset", config["msd"]["pinout"]["reset"]), ("atx_power_switch", config["atx"]["pinout"]["power_switch"]), ("atx_reset_switch", config["atx"]["pinout"]["reset_switch"]), ("streamer_cap", config["streamer"]["pinout"]["cap"]), diff --git a/kvmd/msd.py b/kvmd/msd.py index 5b2fa592..575f8ffb 100644 --- a/kvmd/msd.py +++ b/kvmd/msd.py @@ -16,6 +16,7 @@ import aiofiles import aiofiles.base from . import aioregion +from . import gpio from .logging import get_logger @@ -164,15 +165,25 @@ def _msd_operated(method: Callable) -> Callable: class MassStorageDevice: # pylint: disable=too-many-instance-attributes def __init__( self, + target: int, + reset: int, + device_path: str, init_delay: float, + reset_delay: float, write_meta: bool, + loop: asyncio.AbstractEventLoop, ) -> None: + self.__target = gpio.set_output(target) + self.__reset = gpio.set_output(reset) + self._device_path = device_path self.__init_delay = init_delay + self.__reset_delay = reset_delay self.__write_meta = write_meta + self.__loop = loop self.__device_info: Optional[_MassStorageDeviceInfo] = None @@ -202,7 +213,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes with self.__region: if self.__device_info: raise MsdAlreadyConnectedToKvmError() - # TODO: disable gpio + gpio.write(self.__target, False) if not no_delay: await asyncio.sleep(self.__init_delay) await self.__load_device_info() @@ -213,10 +224,17 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes with self.__region: if not self.__device_info: raise MsdAlreadyConnectedToPcError() - # TODO: enable gpio + gpio.write(self.__target, True) self.__device_info = None get_logger().info("Mass-storage device switched to Server") + @_msd_operated + async def reset(self) -> None: + with self.__region: + gpio.write(self.__reset, True) + await asyncio.sleep(self.__reset_delay) + gpio.write(self.__reset, False) + def get_state(self) -> Dict: info = (self.__saved_device_info._asdict() if self.__saved_device_info else None) if info: @@ -237,7 +255,8 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes async def cleanup(self) -> None: await self.__close_device_file() - # TODO: disable gpio + gpio.write(self.__target, False) + gpio.write(self.__reset, False) @_msd_operated async def __aenter__(self) -> "MassStorageDevice": @@ -298,6 +317,6 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes await self.__device_file.close() except Exception: get_logger().exception("Can't close mass-storage device file") - # TODO: reset device file + await self.reset() self.__device_file = None self.__written = 0 diff --git a/kvmd/server.py b/kvmd/server.py index a4444ecc..efdb48c0 100644 --- a/kvmd/server.py +++ b/kvmd/server.py @@ -147,6 +147,7 @@ class Server: # pylint: disable=too-many-instance-attributes app.router.add_get("/msd", self.__msd_state_handler) app.router.add_post("/msd/connect", self.__msd_connect_handler) app.router.add_post("/msd/write", self.__msd_write_handler) + app.router.add_post("/msd/reset", self.__msd_reset_handler) app.router.add_get("/streamer", self.__streamer_state_handler) app.router.add_post("/streamer/set_params", self.__streamer_set_params_handler) @@ -298,6 +299,11 @@ class Server: # pylint: disable=too-many-instance-attributes logger.info("Written %d bytes to mass-storage device", written) return _json({"written": written}) + @_wrap_exceptions_for_web("Mass-storage error") + async def __msd_reset_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response: + await self.__msd.reset() + return _json() + # ===== STREAMER async def __streamer_state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response: |