【复现】使用Python将switch的joycon和taichi粘起来
安装CMake
>>> brew install cmake
安装hidapi
>>> pip3 install hidapi
安装swig
>>> brew install swig
编译libjoycon
>>> git clone https://github.com/Inokinoki/libjoycon.git
>>> cd libjoycon
>>> mkdir build && cd build
```bash
>>> cmake -DBUILD_EXAMPLE=ON ..
-- Found SWIG: /usr/local/bin/swig (found version "4.0.2")
CMake Deprecation Warning at /usr/local/Cellar/cmake/3.22.1/share/cmake/Modules/UseSWIG.cmake:734 (message):
SWIG_ADD_MODULE is deprecated. Use SWIG_ADD_LIBRARY instead.
Call Stack (most recent call first):
CMakeLists.txt:28 (swig_add_module)
CMake Warning (dev) at /usr/local/Cellar/cmake/3.22.1/share/cmake/Modules/UseSWIG.cmake:775 (message):
Policy CMP0078 is not set: UseSWIG generates standard target names. Run
"cmake --help-policy CMP0078" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.22.1/share/cmake/Modules/UseSWIG.cmake:735 (swig_add_library)
CMakeLists.txt:28 (swig_add_module)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at /usr/local/Cellar/cmake/3.22.1/share/cmake/Modules/UseSWIG.cmake:617 (message):
Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
flag. Run "cmake --help-policy CMP0086" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.22.1/share/cmake/Modules/UseSWIG.cmake:888 (SWIG_ADD_SOURCE_TO_MODULE)
/usr/local/Cellar/cmake/3.22.1/share/cmake/Modules/UseSWIG.cmake:735 (swig_add_library)
CMakeLists.txt:28 (swig_add_module)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Checking for module 'hidapi-hidraw'
-- No package 'hidapi-hidraw' found
-- Checking for module 'gl'
-- No package 'gl' found
-- Checking for module 'glu'
-- No package 'glu' found
-- Checking for module 'glut'
-- No package 'glut' found
HIDAPI not found, examples will not be built
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/microfat/other_Git/libjoycon/build
>>> make
[ 9%] Building C object src/CMakeFiles/joycon.dir/imu.c.o
/Users/microfat/other_Git/libjoycon/src/imu.c:9:37: warning: cast to 'int16_t *' (aka 'short *') from smaller integer type 'uint16_t' (aka 'unsigned short') [-Wint-to-pointer-cast]
float temperature_c = 25.0f + (*(int16_t *)temp) * 0.0625f;
^~~~~~~~~~~~~~~
/Users/microfat/other_Git/libjoycon/src/imu.c:13:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
}
^
2 warnings generated.
[ 18%] Building C object src/CMakeFiles/joycon.dir/input_report.c.o
[ 27%] Building C object src/CMakeFiles/joycon.dir/rumble.c.o
[ 36%] Building C object src/CMakeFiles/joycon.dir/spi.c.o
[ 45%] Building C object src/CMakeFiles/joycon.dir/mcu.c.o
[ 54%] Building C object src/CMakeFiles/joycon.dir/ir.c.o
[ 63%] Building C object src/CMakeFiles/joycon.dir/packet.c.o
[ 72%] Linking C shared library libjoycon.dylib
[ 72%] Built target joycon
Scanning dependencies of target libjoycon_swig_compilation
[ 81%] Swig compile /Users/microfat/other_Git/libjoycon/swig/libjoycon.i for python
[ 81%] Built target libjoycon_swig_compilation
[ 90%] Building C object CMakeFiles/_libjoycon.dir/CMakeFiles/_libjoycon.dir/libjoyconPYTHON_wrap.c.o
/Users/microfat/other_Git/libjoycon/build/CMakeFiles/_libjoycon.dir/libjoyconPYTHON_wrap.c:1756:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
0, /* tp_print */
^
/usr/local/Frameworks/Python.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
^
/usr/local/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
/Users/microfat/other_Git/libjoycon/build/CMakeFiles/_libjoycon.dir/libjoyconPYTHON_wrap.c:1923:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
0, /* tp_print */
^
/usr/local/Frameworks/Python.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
^
/usr/local/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
/Users/microfat/other_Git/libjoycon/build/CMakeFiles/_libjoycon.dir/libjoyconPYTHON_wrap.c:4695:9: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
0, /* tp_print */
^
/usr/local/Frameworks/Python.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
^
/usr/local/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
3 warnings generated.
[100%] Linking C shared module _libjoycon.so
[100%] Built target _libjoycon
运行例子
安装taichi
>>> pip3 install taichi
运行
>>> cp ../examples/*.py .
>>> python3 joycon_taichi_fractal.py