From a328a08107eec4b75cade4b696c30b4274d17ffd Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Fri, 22 Mar 2024 12:09:10 -0700 Subject: [PATCH 1/2] arduino CI ignore src/py_bindings.cpp (in PR) --- .github/workflows/build_arduino.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_arduino.yml b/.github/workflows/build_arduino.yml index 89d13da..d3ca587 100644 --- a/.github/workflows/build_arduino.yml +++ b/.github/workflows/build_arduino.yml @@ -8,6 +8,7 @@ on: - "examples/**/*.ino" - "src/*.h" - "src/*.cpp" + - "!src/py_bindings.cpp" push: branches: [master] paths: From 74c9c828730bce1978c2207ca30d088450d8208f Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Fri, 22 Mar 2024 12:04:15 -0700 Subject: [PATCH 2/2] expose selected driver in python binding - adds `cirque_pinnacle.PINNACLE_DRIVER` string attribute to python binding - uses new attr to dynamically declare pins in examples/cpython*.py --- examples/cpython/absolute_mode.py | 6 +++++- examples/cpython/anymeas_mode.py | 6 +++++- examples/cpython/relative_mode.py | 6 +++++- src/CMakeLists.txt | 4 ++++ src/cirque_pinnacle-stubs/__init__.pyi | 1 + src/py_bindings.cpp | 1 + 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/cpython/absolute_mode.py b/examples/cpython/absolute_mode.py index 8b88519..c4a0411 100644 --- a/examples/cpython/absolute_mode.py +++ b/examples/cpython/absolute_mode.py @@ -14,6 +14,7 @@ PinnacleTouchI2C, PINNACLE_SW_DR, PINNACLE_ABSOLUTE, + PINNACLE_DRIVER, ) print("CirquePinnacle/examples/cpython/absolute_mode") @@ -22,7 +23,10 @@ dr_pin = PINNACLE_SW_DR # uses internal DR flag if not input("Use SW Data Ready? [y/N] ").lower().startswith("y"): print("-- Using HW Data Ready pin.") - dr_pin = 25 # GPIO25 (pin 22 if using MRAA driver) + if PINNACLE_DRIVER == "mraa": + dr_pin = 22 # GPIO25 + else: + dr_pin = 25 # GPIO25 trackpad: Union[PinnacleTouchSPI, PinnacleTouchI2C] if not input("Is the trackpad configured for I2C? [y/N] ").lower().startswith("y"): diff --git a/examples/cpython/anymeas_mode.py b/examples/cpython/anymeas_mode.py index f2c0254..eecc59e 100644 --- a/examples/cpython/anymeas_mode.py +++ b/examples/cpython/anymeas_mode.py @@ -11,11 +11,15 @@ PinnacleTouchSPI, PinnacleTouchI2C, # noqa: imported but unused PINNACLE_ANYMEAS, + PINNACLE_DRIVER, ) print("CirquePinnacle/examples/cpython/anymeas_mode\n") -dr_pin = 25 # GPIO25 (pin 22 if using MRAA driver) +if PINNACLE_DRIVER == "mraa": + dr_pin = 22 # GPIO25 +else: + dr_pin = 25 # GPIO25 trackpad: Union[PinnacleTouchSPI, PinnacleTouchI2C] if not input("Is the trackpad configured for I2C? [y/N] ").lower().startswith("y"): diff --git a/examples/cpython/relative_mode.py b/examples/cpython/relative_mode.py index 5ba3acc..711e3bc 100644 --- a/examples/cpython/relative_mode.py +++ b/examples/cpython/relative_mode.py @@ -12,6 +12,7 @@ PinnacleTouchSPI, PinnacleTouchI2C, PINNACLE_SW_DR, + PINNACLE_DRIVER, ) print("CirquePinnacle/examples/cpython/relative_mode\n") @@ -20,7 +21,10 @@ dr_pin = PINNACLE_SW_DR # uses internal DR flag if not input("Use SW Data Ready? [y/N] ").lower().startswith("y"): print("-- Using HW Data Ready pin.") - dr_pin = 25 # GPIO25 (pin 22 if using MRAA driver) + if PINNACLE_DRIVER == "mraa": + dr_pin = 22 # GPIO25 + else: + dr_pin = 25 # GPIO25 trackpad: Union[PinnacleTouchSPI, PinnacleTouchI2C] if not input("Is the trackpad configured for I2C? [y/N] ").lower().startswith("y"): diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cde0cb2..2ca4d90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -173,6 +173,10 @@ else() # if(${PINNACLE_PY_BINDING}) utility/includes.h ${PINNACLE_DRIVER_SOURCES} ) + # expose the selected driver in the python binding + target_compile_definitions(cirque_pinnacle PUBLIC + PINNACLE_DRIVER="${PINNACLE_DRIVER}" + ) if(DEFINED PINNACLE_SPI_SPEED) message(STATUS "PINNACLE_SPI_SPEED set to ${PINNACLE_SPI_SPEED}") diff --git a/src/cirque_pinnacle-stubs/__init__.pyi b/src/cirque_pinnacle-stubs/__init__.pyi index dbea8c3..2931a75 100644 --- a/src/cirque_pinnacle-stubs/__init__.pyi +++ b/src/cirque_pinnacle-stubs/__init__.pyi @@ -17,6 +17,7 @@ from typing import List, overload PINNACLE_SW_DR: int = ... +PINNACLE_DRIVER: str = ... class PinnacleDataMode: @property diff --git a/src/py_bindings.cpp b/src/py_bindings.cpp index a48435f..aaf8aeb 100644 --- a/src/py_bindings.cpp +++ b/src/py_bindings.cpp @@ -98,6 +98,7 @@ void setCalibrationMatrix_wrapper(PinnacleTouch* self, py::list& matrix) PYBIND11_MODULE(cirque_pinnacle, m) { m.attr("PINNACLE_SW_DR") = PINNACLE_SW_DR; + m.attr("PINNACLE_DRIVER") = PINNACLE_DRIVER; // ******************** expose PinnacleDataMode py::enum_ dataMode(m, "PinnacleDataMode");