merged run_amiibo_cli with run_controller_cli; some cleanups

This commit is contained in:
Robert Martin
2020-04-30 20:44:07 +02:00
parent be8dce71a0
commit c17ab21140
6 changed files with 87 additions and 154 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
import inspect
import logging
import shlex
from aioconsole import ainput
@@ -122,7 +123,7 @@ class ControllerCLI:
buttons_to_push = []
for command in user_input.split('&&'):
cmd, *args = command.split()
cmd, *args = shlex.split(command)
if cmd == 'exit':
return
+11
View File
@@ -18,3 +18,14 @@ class Controller(enum.Enum):
return 'Pro Controller'
else:
raise NotImplementedError()
@staticmethod
def from_arg(arg):
if arg == 'JOYCON_R':
return Controller.JOYCON_R
elif arg == 'JOYCON_L':
return Controller.JOYCON_L
elif arg == 'PRO_CONTROLLER':
return Controller.PRO_CONTROLLER
else:
raise ValueError(f'Unknown controller "{arg}".')
+3 -4
View File
@@ -48,6 +48,9 @@ class ControllerState:
def get_flash_memory(self):
return self._spi_flash
def set_nfc(self, nfc_content):
self._nfc_content = nfc_content
async def send(self):
"""
Invokes protocol.send_controller_state(). Returns after the controller state was send.
@@ -199,10 +202,6 @@ async def button_push(controller_state, *buttons, sec=0.1):
await controller_state.send()
async def set_nfc(controller_state, nfc_content):
controller_state._nfc_content = nfc_content
class _StickCalibration:
def __init__(self, h_center, v_center, h_max_above_center, v_max_above_center, h_max_below_center, v_max_below_center):
self.h_center = h_center
-1
View File
@@ -260,7 +260,6 @@ class ControllerProtocol(BaseProtocol):
else:
logging.info(f'Unknown MCU sub command {sub_command}')
async def _reply_to_sub_command(self, report):
# classify sub command
try: