【Py】【并没什么用】Python控制joycon的例子

在这里插入图片描述


【复现】使用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

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值