|
3 | 3 | import struct
|
4 | 4 | import board
|
5 | 5 | from digitalio import DigitalInOut
|
6 |
| -# if using a trackpad configured for SPI |
7 |
| -from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchSPI, ABSOLUTE, RELATIVE |
8 |
| -# if using a trackpad configured for I2C |
9 |
| -# from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchI2C, ABSOLUTE, RELATIVE |
10 |
| -# i2c = board.I2C() |
| 6 | +import circuitpython_cirque_pinnacle.glidepoint as Pinnacle |
11 | 7 |
|
12 | 8 | dr_pin = DigitalInOut(board.D2)
|
| 9 | +# NOTE The dr_pin is an optional keyword argument to the |
| 10 | +# constructor when using Absolute or Relative modes |
13 | 11 |
|
14 | 12 | # if using a trackpad configured for SPI
|
15 | 13 | spi = board.SPI()
|
16 | 14 | ss_pin = DigitalInOut(board.D7)
|
17 |
| -tpad = PinnacleTouchSPI(spi, ss_pin) # NOTE we did not pass the dr_pin |
| 15 | +tpad = Pinnacle.PinnacleTouchSPI(spi, ss_pin) |
18 | 16 | # if using a trackpad configured for I2C
|
19 |
| -# tpad = PinnacleTouchI2C(i2c) # NOTE we did not pass the dr_pin |
| 17 | +# i2c = board.I2C() |
| 18 | +# tpad = Pinnacle.PinnacleTouchI2C(i2c) |
20 | 19 |
|
21 |
| -tpad.data_mode = ABSOLUTE # ensure Absolute mode is enabled |
| 20 | +tpad.data_mode = Pinnacle.ABSOLUTE # ensure Absolute mode is enabled |
22 | 21 | tpad.absolute_mode_config(z_idle_count=1) # limit idle packet count to 1
|
23 | 22 |
|
24 | 23 | def print_data(timeout=6):
|
25 | 24 | """Print available data reports from the Pinnacle touch controller
|
26 | 25 | until there's no input for a period of ``timeout`` seconds."""
|
27 |
| - print("using {} mode".format("Relative" if tpad.data_mode < ABSOLUTE else "Absolute")) |
| 26 | + if tpad.data_mode == Pinnacle.RELATIVE: |
| 27 | + print("using Relative mode") |
| 28 | + elif tpad.data_mode == Pinnacle.ABSOLUTE: |
| 29 | + print("using Absolute mode") |
28 | 30 | start = time.monotonic()
|
29 | 31 | while time.monotonic() - start < timeout:
|
30 | 32 | if dr_pin.value: # is there new data?
|
31 | 33 | data = tpad.report(only_new=False)
|
32 | 34 | # Because we did not specify the dr_pin when instantiating the tpad variable,
|
33 |
| - # only_new=False skips the extra SPI transaction to check the SW_DR flag in |
34 |
| - # the STATUS register which is reflected on the dr_pin |
| 35 | + # only_new=False skips the extra SPI or I2C transaction to check the |
| 36 | + # SW_DR flag in the STATUS register which is reflected on the dr_pin |
35 | 37 |
|
36 |
| - if tpad.data_mode == ABSOLUTE and data[3]: # only when Z-axis is > 0 |
37 |
| - # spec sheet recommends clamping absolute position data of X & Y axis for |
38 |
| - # reliability |
| 38 | + if tpad.data_mode == Pinnacle.ABSOLUTE and data[3]: |
| 39 | + # NOTE ``and data[3]`` means only when Z-axis is > 0 |
| 40 | + # specification sheet recommends clamping absolute position data of |
| 41 | + # X & Y axis for reliability |
39 | 42 | data[1] = max(128, min(1920, data[1])) # X-axis
|
40 | 43 | data[2] = max(64, min(1472, data[2])) # Y-axis
|
41 |
| - elif tpad.data_mode == RELATIVE: |
| 44 | + elif tpad.data_mode == Pinnacle.RELATIVE: |
42 | 45 | # convert 2's compliment form into natural numbers
|
43 | 46 | data = struct.unpack('Bbbb', data)
|
44 | 47 | print(data)
|
|
0 commit comments