Skip to content

Commit

Permalink
expose selected driver in python binding
Browse files Browse the repository at this point in the history
- adds `cirque_pinnacle.PINNACLE_DRIVER` string attribute to python binding
- uses new attr to dynamically declare pins in examples/cpython*.py
  • Loading branch information
2bndy5 committed Mar 22, 2024
1 parent a328a08 commit 74c9c82
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion examples/cpython/absolute_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
PinnacleTouchI2C,
PINNACLE_SW_DR,
PINNACLE_ABSOLUTE,
PINNACLE_DRIVER,
)

print("CirquePinnacle/examples/cpython/absolute_mode")
Expand All @@ -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"):
Expand Down
6 changes: 5 additions & 1 deletion examples/cpython/anymeas_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
6 changes: 5 additions & 1 deletion examples/cpython/relative_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
PinnacleTouchSPI,
PinnacleTouchI2C,
PINNACLE_SW_DR,
PINNACLE_DRIVER,
)

print("CirquePinnacle/examples/cpython/relative_mode\n")
Expand All @@ -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"):
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
1 change: 1 addition & 0 deletions src/cirque_pinnacle-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import List, overload

PINNACLE_SW_DR: int = ...
PINNACLE_DRIVER: str = ...

class PinnacleDataMode:
@property
Expand Down
1 change: 1 addition & 0 deletions src/py_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<PinnacleDataMode> dataMode(m, "PinnacleDataMode");
Expand Down

0 comments on commit 74c9c82

Please sign in to comment.