forked from mirror/joycontrol
Revert "Merge pull request #29 from spacemeowx2/nfc-r3"
This reverts commitb1390805d9, reversing changes made to2f85c4ce08.
This commit is contained in:
+8
-77
@@ -11,8 +11,6 @@ from joycontrol.controller_state import ControllerState
|
||||
from joycontrol.memory import FlashMemory
|
||||
from joycontrol.report import OutputReport, SubCommand, InputReport, OutputReportID
|
||||
from joycontrol.transport import NotConnectedError
|
||||
from joycontrol.ir_nfc_mcu import IrNfcMcu, McuState, Action
|
||||
from crc8 import crc8
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -42,8 +40,6 @@ class ControllerProtocol(BaseProtocol):
|
||||
self._controller_state = ControllerState(self, controller, spi_flash=spi_flash)
|
||||
self._controller_state_sender = None
|
||||
|
||||
self._mcu = IrNfcMcu()
|
||||
|
||||
# None = Just answer to sub commands
|
||||
self._input_report_mode = None
|
||||
|
||||
@@ -166,9 +162,8 @@ class ControllerProtocol(BaseProtocol):
|
||||
elif output_report_id == OutputReportID.SUB_COMMAND:
|
||||
reply_send = await self._reply_to_sub_command(report)
|
||||
elif output_report_id == OutputReportID.REQUEST_IR_NFC_MCU:
|
||||
# TODO: This does not reply anything
|
||||
# reply_send = await self._reply_to_ir_nfc_mcu(report)
|
||||
await self._reply_to_ir_nfc_mcu(report)
|
||||
# TODO NFC
|
||||
raise NotImplementedError('NFC communictation is not implemented.')
|
||||
else:
|
||||
logger.warning(f'Report unknown output report "{output_report_id}" - IGNORE')
|
||||
except ValueError as v_err:
|
||||
@@ -184,11 +179,9 @@ class ControllerProtocol(BaseProtocol):
|
||||
# TODO: set some sensor data
|
||||
input_report.set_6axis_data()
|
||||
|
||||
# set nfc data
|
||||
# TODO NFC - set nfc data
|
||||
if input_report.get_input_report_id() == 0x31:
|
||||
self._mcu.set_nfc(self._controller_state.get_nfc())
|
||||
self._mcu.update_nfc_report()
|
||||
input_report.set_ir_nfc_data(bytes(self._mcu))
|
||||
pass
|
||||
|
||||
await self.write(input_report)
|
||||
|
||||
@@ -237,50 +230,6 @@ class ControllerProtocol(BaseProtocol):
|
||||
else:
|
||||
logger.warning(f'Output report {output_report_id} not implemented - ignoring')
|
||||
|
||||
async def _reply_to_ir_nfc_mcu(self, report):
|
||||
"""
|
||||
TODO: Cleanup
|
||||
We aren't replying to anything here, do we need to?
|
||||
"""
|
||||
sub_command = report.data[11]
|
||||
sub_command_data = report.data[12:]
|
||||
|
||||
# logging.info(f'received output report - Request MCU sub command {sub_command}')
|
||||
|
||||
if self._mcu.get_action() in (Action.READ_TAG, Action.READ_TAG_2, Action.READ_FINISHED):
|
||||
return
|
||||
|
||||
# Request mcu state
|
||||
if sub_command == 0x01:
|
||||
# input_report = InputReport()
|
||||
# input_report.set_input_report_id(0x21)
|
||||
# input_report.set_misc()
|
||||
|
||||
# input_report.set_ack(0xA0)
|
||||
# input_report.reply_to_subcommand_id(0x21)
|
||||
|
||||
self._mcu.set_action(Action.REQUEST_STATUS)
|
||||
# input_report.set_mcu(self._mcu)
|
||||
|
||||
# await self.write(input_report)
|
||||
# Send Start tag discovery
|
||||
elif sub_command == 0x02:
|
||||
# 0: Cancel all, 4: StartWaitingReceive
|
||||
if sub_command_data[0] == 0x04:
|
||||
self._mcu.set_action(Action.START_TAG_DISCOVERY)
|
||||
# 1: Start polling
|
||||
elif sub_command_data[0] == 0x01:
|
||||
self._mcu.set_action(Action.START_TAG_POLLING)
|
||||
# 2: stop polling
|
||||
elif sub_command_data[0] == 0x02:
|
||||
self._mcu.set_action(Action.NON)
|
||||
elif sub_command_data[0] == 0x06:
|
||||
self._mcu.set_action(Action.READ_TAG)
|
||||
else:
|
||||
logging.info(f'Unknown sub_command_data arg {sub_command_data}')
|
||||
else:
|
||||
logging.info(f'Unknown MCU sub command {sub_command}')
|
||||
|
||||
async def _reply_to_sub_command(self, report):
|
||||
# classify sub command
|
||||
try:
|
||||
@@ -467,6 +416,7 @@ class ControllerProtocol(BaseProtocol):
|
||||
await self.write(input_report)
|
||||
|
||||
async def _command_set_nfc_ir_mcu_config(self, sub_command_data):
|
||||
# TODO NFC
|
||||
input_report = InputReport()
|
||||
input_report.set_input_report_id(0x21)
|
||||
input_report.set_misc()
|
||||
@@ -474,30 +424,14 @@ class ControllerProtocol(BaseProtocol):
|
||||
input_report.set_ack(0xA0)
|
||||
input_report.reply_to_subcommand_id(SubCommand.SET_NFC_IR_MCU_CONFIG.value)
|
||||
|
||||
self._mcu.update_status()
|
||||
data = list(bytes(self._mcu)[0:34])
|
||||
crc = crc8()
|
||||
crc.update(bytes(data[:-1]))
|
||||
checksum = crc.digest()
|
||||
data[-1] = ord(checksum)
|
||||
|
||||
data = [1, 0, 255, 0, 8, 0, 27, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 200]
|
||||
for i in range(len(data)):
|
||||
input_report.data[16+i] = data[i]
|
||||
|
||||
# Set MCU mode cmd
|
||||
if sub_command_data[1] == 0:
|
||||
if sub_command_data[2] == 0:
|
||||
self._mcu.set_state(McuState.STAND_BY)
|
||||
elif sub_command_data[2] == 4:
|
||||
self._mcu.set_state(McuState.NFC)
|
||||
else:
|
||||
logger.info(f"unknown mcu state {sub_command_data[2]}")
|
||||
else:
|
||||
logger.info(f"unknown mcu config command {sub_command_data}")
|
||||
input_report.data[16 + i] = data[i]
|
||||
|
||||
await self.write(input_report)
|
||||
|
||||
async def _command_set_nfc_ir_mcu_state(self, sub_command_data):
|
||||
# TODO NFC
|
||||
input_report = InputReport()
|
||||
input_report.set_input_report_id(0x21)
|
||||
input_report.set_misc()
|
||||
@@ -506,13 +440,10 @@ class ControllerProtocol(BaseProtocol):
|
||||
# 0x01 = Resume
|
||||
input_report.set_ack(0x80)
|
||||
input_report.reply_to_subcommand_id(SubCommand.SET_NFC_IR_MCU_STATE.value)
|
||||
self._mcu.set_action(Action.NON)
|
||||
self._mcu.set_state(McuState.STAND_BY)
|
||||
elif sub_command_data[0] == 0x00:
|
||||
# 0x00 = Suspend
|
||||
input_report.set_ack(0x80)
|
||||
input_report.reply_to_subcommand_id(SubCommand.SET_NFC_IR_MCU_STATE.value)
|
||||
self._mcu.set_state(McuState.STAND_BY)
|
||||
else:
|
||||
raise NotImplementedError(f'Argument {sub_command_data[0]} of {SubCommand.SET_NFC_IR_MCU_STATE} '
|
||||
f'not implemented.')
|
||||
|
||||
Reference in New Issue
Block a user