set default memory in run_controller_cli; set center if stick calibration available

This commit is contained in:
Robert Martin
2020-05-09 12:19:38 +02:00
parent a05d3c7ef2
commit 62a7fdec56
3 changed files with 27 additions and 11 deletions
+4
View File
@@ -27,6 +27,8 @@ class ControllerState:
calibration = LeftStickCalibration.from_bytes(calibration_data) calibration = LeftStickCalibration.from_bytes(calibration_data)
self.l_stick_state = StickState(calibration=calibration) self.l_stick_state = StickState(calibration=calibration)
if calibration is not None:
self.l_stick_state.set_center()
# create right stick state # create right stick state
if controller in (Controller.PRO_CONTROLLER, Controller.JOYCON_R): if controller in (Controller.PRO_CONTROLLER, Controller.JOYCON_R):
@@ -39,6 +41,8 @@ class ControllerState:
calibration = RightStickCalibration.from_bytes(calibration_data) calibration = RightStickCalibration.from_bytes(calibration_data)
self.r_stick_state = StickState(calibration=calibration) self.r_stick_state = StickState(calibration=calibration)
if calibration is not None:
self.r_stick_state.set_center()
self.sig_is_send = asyncio.Event() self.sig_is_send = asyncio.Event()
+20 -10
View File
@@ -1,18 +1,28 @@
class FlashMemory: class FlashMemory:
def __init__(self, spi_flash_memory_data=None, size=0x80000): def __init__(self, spi_flash_memory_data=None, default_stick_cal=False, size=0x80000):
"""
:param spi_flash_memory_data: data from a memory dump (can be created using dump_spi_flash.py).
:param default_stick_cal: If True, override stick calibration bytes with factory default
:param size of the memory dump, should be constant
"""
if spi_flash_memory_data is None: if spi_flash_memory_data is None:
self.data = [0xFF] * size # Blank data is all 0xFF spi_flash_memory_data = [0xFF] * size # Blank data is all 0xFF
default_stick_cal = True
if len(spi_flash_memory_data) != size:
raise ValueError(f'Given data size {len(spi_flash_memory_data)} does not match size {size}.')
if isinstance(spi_flash_memory_data, bytes):
spi_flash_memory_data = list(spi_flash_memory_data)
# set default controller stick calibration
if default_stick_cal:
# L-stick factory calibration # L-stick factory calibration
self.data[0x603D:0x6046] = [0x00, 0x07, 0x70, 0x00, 0x08, 0x80, 0x00, 0x07, 0x70] spi_flash_memory_data[0x603D:0x6046] = [0x00, 0x07, 0x70, 0x00, 0x08, 0x80, 0x00, 0x07, 0x70]
# R-stick factory calibration # R-stick factory calibration
self.data[0x6046:0x604F] = [0x00, 0x08, 0x80, 0x00, 0x07, 0x70, 0x00, 0x07, 0x70] spi_flash_memory_data[0x6046:0x604F] = [0x00, 0x08, 0x80, 0x00, 0x07, 0x70, 0x00, 0x07, 0x70]
else:
if len(spi_flash_memory_data) != size: self.data = spi_flash_memory_data
raise ValueError(f'Given data size {len(spi_flash_memory_data)} does not match size {size}.')
if isinstance(spi_flash_memory_data, bytes):
spi_flash_memory_data = list(spi_flash_memory_data)
self.data = spi_flash_memory_data
def __getitem__(self, item): def __getitem__(self, item):
return self.data[item] return self.data[item]
+3 -1
View File
@@ -147,10 +147,12 @@ async def set_amiibo(controller_state, file_path):
async def _main(args): async def _main(args):
# parse the spi flash # parse the spi flash
spi_flash = None
if args.spi_flash: if args.spi_flash:
with open(args.spi_flash, 'rb') as spi_flash_file: with open(args.spi_flash, 'rb') as spi_flash_file:
spi_flash = FlashMemory(spi_flash_file.read()) spi_flash = FlashMemory(spi_flash_file.read())
else:
# Create memory containing default controller stick calibration
spi_flash = FlashMemory()
# Get controller name to emulate from arguments # Get controller name to emulate from arguments
controller = Controller.from_arg(args.controller) controller = Controller.from_arg(args.controller)