diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-01-24 02:31:52 -0800 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-01-24 02:31:52 -0800 |
| commit | 5d488d56434f486b42dae04d5326a5a81106ad31 (patch) | |
| tree | 22aef0b29bfaa09e2bed4a8c13b64efc7a21ff0a /chuniio.py | |
initial commit1.0
Diffstat (limited to 'chuniio.py')
| -rw-r--r-- | chuniio.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/chuniio.py b/chuniio.py new file mode 100644 index 0000000..e851063 --- /dev/null +++ b/chuniio.py @@ -0,0 +1,35 @@ +import ctypes +import mmap + +class SharedMemoryData(ctypes.Structure): + _fields_ = [ + ("airIoStatus", ctypes.c_uint8 * 6), + ("sliderIoStatus", ctypes.c_uint8 * 32), + ("ledRgbData", ctypes.c_uint8 * 96), + ("reserved", ctypes.c_uint8 * 4) + ] + +SHARED_MEMORY_NAME = "Local\\BROKENITHM_SHARED_BUFFER" +SHARED_MEMORY_SIZE = ctypes.sizeof(ctypes.c_uint8) * ctypes.sizeof(SharedMemoryData) + +def open_sharedmem(): + try: + shared_memory = mmap.mmap(-1, SHARED_MEMORY_SIZE, + tagname=SHARED_MEMORY_NAME, + access=mmap.ACCESS_DEFAULT) + return shared_memory + except Exception: + print("[Error] A Fatal Error occured while trying to write to the Shared Memory while initializing") + return None + +def write_to_airzone(air_zone_state: list, shared_memory: mmap.mmap): + if len(air_zone_state) != 6 and all(isinstance(state, bool) for state in air_zone_state): + raise ValueError("air_input must have exactly 6 elements") + air_states = bytes([128 if state else 0 for state in fix_air_order(air_zone_state)]) + shared_memory.seek(0) + shared_memory.write(bytes(air_states)) + +def fix_air_order(air_zone_state: list): + if len(air_zone_state) != 6: + raise ValueError("air_input must have exactly 6 elements") + return [air_zone_state[4], air_zone_state[5], air_zone_state[2], air_zone_state[3], air_zone_state[0], air_zone_state[1]] |
