-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved clamping from report() to simpletest.py
- Loading branch information
Showing
6 changed files
with
82 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""A simple test example. this example also works with glidepoint_lite.py""" | ||
import time | ||
import struct | ||
import board | ||
from digitalio import DigitalInOut | ||
# if using a trackpad configured for SPI | ||
from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchSPI, ABSOLUTE, RELATIVE | ||
# if using a trackpad configured for I2C | ||
# from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchI2C, ABSOLUTE, RELATIVE | ||
# i2c = board.I2C() | ||
|
||
spi = board.SPI() # if using a trackpad configured for SPI | ||
ss_pin = DigitalInOut(board.D7) | ||
dr_pin = DigitalInOut(board.D2) | ||
|
||
# if using a trackpad configured for SPI | ||
tpad = PinnacleTouchSPI(spi, ss_pin) # NOTE we did not pass the dr_pin | ||
# if using a trackpad configured for I2C | ||
# tpad = PinnacleTouchI2C(i2c) # NOTE we did not pass the dr_pin | ||
|
||
tpad.data_mode = ABSOLUTE # ensure Absolute mode is enabled | ||
tpad.absolute_mode_config(z_idle_count=1) # limit idle packet count to 1 | ||
|
||
def print_data(timeout=6): | ||
"""Print available data reports from the Pinnacle touch controller | ||
until there's no touch for a period of ``timeout`` seconds.""" | ||
print("using {} mode".format("Relative" if tpad.data_mode < ABSOLUTE else "Absolute")) | ||
start = time.monotonic() | ||
while time.monotonic() - start < timeout: | ||
if dr_pin.value: # is there new data? | ||
data = tpad.report(only_new=False) | ||
# Because we did not specify the dr_pin when instantiating the tpad variable, | ||
# only_new=False skips the extra SPI transaction to check the SW_DR flag in | ||
# the STATUS register which is reflected on the dr_pin | ||
|
||
if tpad.data_mode == ABSOLUTE and data[3]: # only when Z-axis is > 0 | ||
# spec sheet recommends clamping absolute position data of X & Y axis for | ||
# reliability | ||
data[1] = max(128, min(1920, data[1])) # X-axis | ||
data[2] = max(64, min(1472, data[2])) # Y-axis | ||
elif tpad.data_mode == RELATIVE: | ||
# convert 2's compliment form into natural numbers | ||
data = struct.unpack('Bbbb', data) | ||
print(data) | ||
start = time.monotonic() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters