Closed 10se1ucgo closed 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
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
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.
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.