-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-lib.py
More file actions
64 lines (52 loc) · 2.55 KB
/
test-lib.py
File metadata and controls
64 lines (52 loc) · 2.55 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import time
from pathlib import Path
from PIL import Image
from cffi import FFI
f = FFI()
#f.cdef(Path('./target/libfip.h').read_text())
f.cdef(
'''
typedef void (__stdcall *Pfn_DirectOutput_EnumerateCallback)(void* hDevice, void* pCtxt);
typedef void (__stdcall *Pfn_DirectOutput_DeviceChange)(void* hDevice, bool bAdded, void* pCtxt);
typedef void (__stdcall *Pfn_DirectOutput_PageChange)(void* hDevice, DWORD dwPage, bool bSetActive, void* pCtxt);
typedef void (__stdcall *Pfn_DirectOutput_SoftButtonChange)(void* hDevice, DWORD dwButtons, void* pCtxt);
HRESULT __stdcall DirectOutput_Initialize(const wchar_t* wszPluginName);
HRESULT __stdcall DirectOutput_Deinitialize();
HRESULT __stdcall DirectOutput_RegisterDeviceCallback(Pfn_DirectOutput_DeviceChange pfnCb, void* pCtxt);
HRESULT __stdcall DirectOutput_Enumerate(Pfn_DirectOutput_EnumerateCallback pfnCb, void* pCtxt);
HRESULT __stdcall DirectOutput_RegisterPageCallback(void* hDevice, Pfn_DirectOutput_PageChange pfnCb, void* pCtxt);
HRESULT __stdcall DirectOutput_RegisterSoftButtonCallback(void* hDevice, Pfn_DirectOutput_SoftButtonChange pfnCb, void* pCtxt);
HRESULT __stdcall DirectOutput_SetLed(void* hDevice, DWORD dwPage, DWORD dwIndex, DWORD dwValue);
HRESULT __stdcall DirectOutput_SetImage(void* hDevice, DWORD dwPage, DWORD dwIndex, DWORD cbValue, const void* pvValue);
HRESULT __stdcall DirectOutput_GetSerialNumber(void* hDevice, wchar_t* pszSerialNumber, DWORD dwSize);
'''.replace('HRESULT', 'int64_t').replace('DWORD', 'int32_t')
)
m = f.dlopen('./target/debug/liblibfip.so')
#m = f.dlopen('./libfip/libfip.dll.so')
device_addr = None
@f.callback("void(void*, void *)")
def enumerate_callback(addr, handle):
global device_addr
print('enumerate_callback', addr, handle)
device_addr = addr
m.DirectOutput_Initialize('test')
try:
x = f.new("int *")
import time; time.sleep(0.5)
m.DirectOutput_Enumerate(enumerate_callback, x)
if device_addr is None:
print('No devices found!')
exit(1)
s = f.new("wchar_t[16]")
print(m.DirectOutput_GetSerialNumber(device_addr, s, len(s)))
print(*map(ord, s))
# m.DirectOutput_Enumerate(enumerate_callback, x)
image_pixels = Image.open('/home/leenr/saitek-fip-test/SMPTEColor.png').resize((320, 240)).tobytes()
m.DirectOutput_SetImage(device_addr, 0, 0, len(image_pixels), image_pixels)
while True:
for value in (True, False):
for i in range(1, 9):
print(i, m.DirectOutput_SetLed(device_addr, 2, i, int(value)))
time.sleep(0.075)
finally:
m.DirectOutput_Deinitialize()