forked from mirror/joycontrol
Merge branch 'pulls/326281544/37'
This commit is contained in:
@@ -27,6 +27,8 @@ class ControllerState:
|
||||
calibration = LeftStickCalibration.from_bytes(calibration_data)
|
||||
|
||||
self.l_stick_state = StickState(calibration=calibration)
|
||||
if calibration is not None:
|
||||
self.l_stick_state.set_center()
|
||||
|
||||
# create right stick state
|
||||
if controller in (Controller.PRO_CONTROLLER, Controller.JOYCON_R):
|
||||
@@ -39,6 +41,8 @@ class ControllerState:
|
||||
calibration = RightStickCalibration.from_bytes(calibration_data)
|
||||
|
||||
self.r_stick_state = StickState(calibration=calibration)
|
||||
if calibration is not None:
|
||||
self.r_stick_state.set_center()
|
||||
|
||||
self.sig_is_send = asyncio.Event()
|
||||
|
||||
|
||||
+17
-3
@@ -1,13 +1,27 @@
|
||||
|
||||
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:
|
||||
self.data = size * [0x00]
|
||||
else:
|
||||
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
|
||||
spi_flash_memory_data[0x603D:0x6046] = [0x00, 0x07, 0x70, 0x00, 0x08, 0x80, 0x00, 0x07, 0x70]
|
||||
# R-stick factory calibration
|
||||
spi_flash_memory_data[0x6046:0x604F] = [0x00, 0x08, 0x80, 0x00, 0x07, 0x70, 0x00, 0x07, 0x70]
|
||||
|
||||
self.data = spi_flash_memory_data
|
||||
|
||||
def __getitem__(self, item):
|
||||
|
||||
@@ -147,10 +147,12 @@ async def set_amiibo(controller_state, file_path):
|
||||
|
||||
async def _main(args):
|
||||
# parse the spi flash
|
||||
spi_flash = None
|
||||
if args.spi_flash:
|
||||
with open(args.spi_flash, 'rb') as spi_flash_file:
|
||||
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
|
||||
controller = Controller.from_arg(args.controller)
|
||||
|
||||
Reference in New Issue
Block a user