Skip to content

Commit

Permalink
Add to README, Add a few functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fchorney committed Mar 23, 2024
1 parent 1499d8c commit 1467c37
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ StepManiaX SDK for Python
Currently fairly incomplete. A lot of core functionality exists, but the rest of the SDK needs to be finished. At some point I can write out a list
of functions currently enabled and which ones have yet to be added.


### Ported Functions

- Get Device Info: Get basic stage information such as Player jumper, serial number, firmware version
- Get Config v5: Get the stage configuration (version 5 and up)
- Write Config v5: Write the stage configuration (version 5 and up)
- Factory Reset: Factory reset the stage to original settings
- Set Light Strip: Set the color of the underglow light strips (Currently only used in factory\_reset function)
- Force Recalibration: Force the stage to perform a recalibration
- Get Sensor Test Data: Get sensor test data for modes [uncalibrated, calibrated, noise, tare]
- Set Serial Numbers: Sets a stage serial if it doesn't exist yet. Does nothing if one exists
- Set Panel Test Mode: Turn on/off panel test mode

### Functions Left to Port

- Set Lights: Set panel lights (This seems fairly complicated at a quick glance)
- Upload GIF Data: Upload GIF Data to Panels
- Re-Enable Auto Lights: Assume this just turns auto GIFs on the pads back on to default?

## Installation (macOS)

These are the instructions that I have been using to run this on my system so far.
Expand Down
34 changes: 33 additions & 1 deletion pysmx/sdk/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dataclasses import dataclass, field
from random import SystemRandom
from string import ascii_uppercase, digits
from time import monotonic_ns

import hid
Expand All @@ -16,7 +18,12 @@
make_send_packets,
send_packets,
)
from pysmx.sdk.sensors import SensorTestMode, SMXDetailData, SMXSensorTestData
from pysmx.sdk.sensors import (
PanelTestMode,
SensorTestMode,
SMXDetailData,
SMXSensorTestData,
)
from pysmx.utils import BytesEnum, pad_list, s_to_ns


Expand All @@ -31,6 +38,8 @@ class APICommand(BytesEnum):
SET_LIGHT_STRIP = b"L"
FORCE_RECALIBRATION = b"C"
GET_SENSOR_TEST_DATA = b"y"
SET_SERIAL_NUMBERS = b"s"
SET_PANEL_TEST_MODE = b"t"


# StepManiaX Stage Hardware Identification
Expand Down Expand Up @@ -253,6 +262,29 @@ def get_device_info(self, player: int) -> SMXDeviceInfo:

return stage.device_info

def set_serial_numbers(self, player: int) -> None:
stage = self._get_stage(player)

# TODO: Make this a constant? I dunno
serial_number_length = 32
serial = list(map(ord, [SystemRandom().choice(ascii_uppercase + digits) for _ in range(serial_number_length)]))

cmd = [ord(APICommand.SET_SERIAL_NUMBERS)] + serial
stage.send_command(bytes(cmd), acknowledge=True)

def set_panel_test_mode(self, player: int, mode: PanelTestMode) -> None:
# TODO: WARNING. I don't think this works correctly. You can send the PRESSURE_TEST mode but pressing on the
# panels doesn't seem to do anything?
stage = self._get_stage(player)

# TODO: At some point we might need to keep track of what this is currently set to. I don't think we ever
# actually send `PanelTestMode.OFF` to the stages?
if mode == PanelTestMode.OFF:
return

# TODO: Apparently you need to send the panel test mode command periodically (about once every second)
stage.send_command(APICommand.SET_PANEL_TEST_MODE + mode, acknowledge=True)

def _find_stages(self) -> None:
logger.debug("Finding Stages...")

Expand Down
1 change: 1 addition & 0 deletions pysmx/sdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PackedSensorSettings(object):
fsr_low_threshold: list[int] # 4 values
fsr_high_threshold: list[int] # 4 values

# TODO: Figure out what this is for
combined_low_threshold: int
combined_high_threshold: int

Expand Down
1 change: 1 addition & 0 deletions pysmx/sdk/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def send_packets(
# If we are expecting an acknowledgement, check if the raw_data is equal to
# an acknowledgemenet packet
if acknowledge and raw_data == ACK_PACKET:
logger.debug("Successfully Acknowledged")
break

# Else we parse the packet until it is finished
Expand Down
1 change: 1 addition & 0 deletions pysmx/sdk/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PanelTestMode(BytesEnum):
PRESSURE_TEST = b"1"


# TODO: This might be backwards?
class Panel(IntEnum):
DOWN_LEFT = 0
DOWN = 1
Expand Down
13 changes: 13 additions & 0 deletions testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pysmx.sdk.api import SMXAPI
from pysmx.sdk.sensors import PanelTestMode


x = SMXAPI()

x._find_stages()

x.set_panel_test_mode(1, PanelTestMode.PRESSURE_TEST)

import pdb

pdb.set_trace()

0 comments on commit 1467c37

Please sign in to comment.