10se1ucgo / cue_sdk

Python wrapper for the Corsair Utility Engine SDK
Other
21 stars 2 forks source link

SetLedsColorsAsync callback function #1

Closed 10se1ucgo closed 8 years ago

10se1ucgo commented 8 years ago

SetLedsColorsAsync doesn't currently take a callback function argument. I don't know C/ctypes at all so I'm not sure how this should be implemented.

10se1ucgo commented 8 years ago

The SetLedsColorsAsync function looks like this

bool CorsairSetLedsColorsAsync(int size, CorsairLedColor* ledsColors, void (*CallbackType)(void* context, bool result, CorsairError error), void *context)

Here is what I tried to implement in the CUE() class.

def SetLedsColorsAsync(self, size, led_color, callback, context):
    c_func = CFUNCTYPE(c_void_p, c_void_p, c_bool, c_int)
    c_callback = c_func(callback)
    self._libcue.CorsairSetLedsColorsAsync.restype = c_bool
    self._libcue.CorsairSetLedsColorsAsync.argtypes = [c_int, POINTER(CorsairLedColor), c_void_p, c_void_p]
    return self._libcue.CorsairSetLedsColorsAsync(size, led_color, c_callback, context)

And this is the test I was doing

from cue_sdk import *
import time

def test(context, result, error):
    print context, result, error
    return 0

Corsair = CUE("CUESDK.x64_2013.dll")
Corsair.RequestControl(CAM_ExclusiveLightingControl)
Corsair.SetLedsColorsAsync(1, CorsairLedColor(CLK_H, 255, 255, 255), test, 1)

while True:
    time.sleep(1)

However, it just runs, sets my H key to white and then exits with error code 3221225477 which on Windows is STATUS_ACCESS_VIOLATION

10se1ucgo commented 8 years ago

More info

<~Kasen> the third argument isn't a void pointer
<~Kasen> it's a function pointer, and that's the function's signature
<~Kasen> i don't know ctypes, so i'm not sure how to implement that, but that'll be why it's crashing
10se1ucgo commented 8 years ago

I'll try this now

def SetLedsColorsAsync(self, size, led_color, callback, context):
    c_callback_type = CFUNCTYPE(None, c_void_p, c_bool, c_int)
    c_callback = CallbackType(callback)
    self._libcue.CorsairSetLedsColorsAsync.restype = c_bool
    self._libcue.CorsairSetLedsColorsAsync.argtypes = [c_int, POINTER(CorsairLedColor), c_callback_type, c_void_p]
    return self._libcue.CorsairSetLedsColorsAsync(size, led_color, c_callback, context)

If this doesn't work, I'm giving up.

EDIT: Doesn't work. Crap.