Skip to content

Commit 1a0dba3

Browse files
committed
address namespace confusion in examples
1 parent dbe21a7 commit 1a0dba3

File tree

3 files changed

+37
-38
lines changed

3 files changed

+37
-38
lines changed

examples/cirque_pinnacle_anymeas_test.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@
55
import struct
66
import board
77
from digitalio import DigitalInOut
8-
# if using a trackpad configured for SPI
9-
from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchSPI, ANYMEAS
10-
# if using a trackpad configured for I2C
11-
# from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchI2C, ANYMEAS
12-
# i2c = board.I2C()
13-
14-
# if using a trackpad configured for SPI
15-
spi = board.SPI()
16-
ss_pin = DigitalInOut(board.D7)
8+
import circuitpython_cirque_pinnacle.glidepoint as Pinnacle
179

1810
dr_pin = DigitalInOut(board.D2)
11+
# NOTE The dr_pin is a required keyword argument to the
12+
# constructor when using AnyMeas mode
1913

20-
# NOTE The dr_pin is a required arg to use AnyMeas mode
2114
# if using a trackpad configured for SPI
22-
tpad = PinnacleTouchSPI(spi, ss_pin, dr_pin=dr_pin)
15+
spi = board.SPI()
16+
ss_pin = DigitalInOut(board.D7)
17+
tpad = Pinnacle.PinnacleTouchSPI(spi, ss_pin, dr_pin=dr_pin)
2318
# if using a trackpad configured for I2C
24-
# tpad = PinnacleTouchI2C(i2c, dr_pin=dr_pin)
19+
# i2c = board.I2C()
20+
# tpad = Pinnacle.PinnacleTouchI2C(i2c, dr_pin=dr_pin)
2521

2622
# if dr_pin was not specified upon instantiation.
2723
# this command will raise an AttributeError exception
28-
tpad.data_mode = ANYMEAS
24+
tpad.data_mode = Pinnacle.ANYMEAS
2925

3026
# setup toggle and polarity bits for measuring with PNP gate muxing
3127
class MeasVector:
@@ -51,8 +47,9 @@ def compensate(count=5):
5147
"""take ``count`` measurements, then average them together """
5248
for i, v in enumerate(vectors):
5349
idle_vectors[i] = 0
54-
for _ in range(count): #
55-
idle_vectors[i] += struct.unpack('h', tpad.measure_adc(v.toggle, v.polarity))[0]
50+
for _ in range(count):
51+
result = struct.unpack('h', tpad.measure_adc(v.toggle, v.polarity))[0]
52+
idle_vectors[i] += result
5653
idle_vectors[i] /= count
5754
print("compensation {}: {}".format(i, idle_vectors[i]))
5855

examples/cirque_pinnacle_simpletest.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,45 @@
33
import struct
44
import board
55
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
117

128
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
1311

1412
# if using a trackpad configured for SPI
1513
spi = board.SPI()
1614
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)
1816
# 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)
2019

21-
tpad.data_mode = ABSOLUTE # ensure Absolute mode is enabled
20+
tpad.data_mode = Pinnacle.ABSOLUTE # ensure Absolute mode is enabled
2221
tpad.absolute_mode_config(z_idle_count=1) # limit idle packet count to 1
2322

2423
def print_data(timeout=6):
2524
"""Print available data reports from the Pinnacle touch controller
2625
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")
2830
start = time.monotonic()
2931
while time.monotonic() - start < timeout:
3032
if dr_pin.value: # is there new data?
3133
data = tpad.report(only_new=False)
3234
# 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
3537

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
3942
data[1] = max(128, min(1920, data[1])) # X-axis
4043
data[2] = max(64, min(1472, data[2])) # Y-axis
41-
elif tpad.data_mode == RELATIVE:
44+
elif tpad.data_mode == Pinnacle.RELATIVE:
4245
# convert 2's compliment form into natural numbers
4346
data = struct.unpack('Bbbb', data)
4447
print(data)

examples/cirque_pinnacle_usb_mouse.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@
55
import board
66
from digitalio import DigitalInOut
77
import usb_hid
8-
# if using a trackpad configured for SPI
9-
from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchSPI, RELATIVE
10-
# if using a trackpad configured for I2C
11-
# from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchI2C, RELATIVE
12-
# i2c = board.I2C()
8+
import circuitpython_cirque_pinnacle.glidepoint as Pinnacle
139

1410
dr_pin = DigitalInOut(board.D2)
11+
# NOTE Specifying the optional keyword argument ``dr_pin`` to the
12+
# constructor expedites ``report()`` when using Absolute or Relative modes
1513

1614
# if using a trackpad configured for SPI
1715
spi = board.SPI()
1816
ss_pin = DigitalInOut(board.D7)
19-
tpad = PinnacleTouchSPI(spi, ss_pin) # NOTE we did not pass the dr_pin
17+
tpad = Pinnacle.PinnacleTouchSPI(spi, ss_pin, dr_pin=dr_pin)
2018
# if using a trackpad configured for I2C
21-
# tpad = PinnacleTouchI2C(i2c) # NOTE we did not pass the dr_pin
19+
# i2c = board.I2C()
20+
# tpad = Pinnacle.PinnacleTouchI2C(i2c, dr_pin=dr_pin)
2221

23-
tpad.data_mode = RELATIVE # ensure mouse mode is enabled
22+
tpad.data_mode = Pinnacle.RELATIVE # ensure mouse mode is enabled
2423

2524
mouse = None
2625
for dev in usb_hid.devices:

0 commit comments

Comments
 (0)