aboutsummaryrefslogtreecommitdiffstats
path: root/chuniio.py
blob: e85106351979164b98f05454b110efba02faa354 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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]]
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage