Skip to content

Commit

Permalink
address namespace confusion in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Apr 8, 2020
1 parent dbe21a7 commit 1a0dba3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
27 changes: 12 additions & 15 deletions examples/cirque_pinnacle_anymeas_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@
import struct
import board
from digitalio import DigitalInOut
# if using a trackpad configured for SPI
from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchSPI, ANYMEAS
# if using a trackpad configured for I2C
# from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchI2C, ANYMEAS
# i2c = board.I2C()

# if using a trackpad configured for SPI
spi = board.SPI()
ss_pin = DigitalInOut(board.D7)
import circuitpython_cirque_pinnacle.glidepoint as Pinnacle

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

# NOTE The dr_pin is a required arg to use AnyMeas mode
# if using a trackpad configured for SPI
tpad = PinnacleTouchSPI(spi, ss_pin, dr_pin=dr_pin)
spi = board.SPI()
ss_pin = DigitalInOut(board.D7)
tpad = Pinnacle.PinnacleTouchSPI(spi, ss_pin, dr_pin=dr_pin)
# if using a trackpad configured for I2C
# tpad = PinnacleTouchI2C(i2c, dr_pin=dr_pin)
# i2c = board.I2C()
# tpad = Pinnacle.PinnacleTouchI2C(i2c, dr_pin=dr_pin)

# if dr_pin was not specified upon instantiation.
# this command will raise an AttributeError exception
tpad.data_mode = ANYMEAS
tpad.data_mode = Pinnacle.ANYMEAS

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

Expand Down
33 changes: 18 additions & 15 deletions examples/cirque_pinnacle_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,45 @@
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()
import circuitpython_cirque_pinnacle.glidepoint as Pinnacle

dr_pin = DigitalInOut(board.D2)
# NOTE The dr_pin is an optional keyword argument to the
# constructor when using Absolute or Relative modes

# if using a trackpad configured for SPI
spi = board.SPI()
ss_pin = DigitalInOut(board.D7)
tpad = PinnacleTouchSPI(spi, ss_pin) # NOTE we did not pass the dr_pin
tpad = Pinnacle.PinnacleTouchSPI(spi, ss_pin)
# if using a trackpad configured for I2C
# tpad = PinnacleTouchI2C(i2c) # NOTE we did not pass the dr_pin
# i2c = board.I2C()
# tpad = Pinnacle.PinnacleTouchI2C(i2c)

tpad.data_mode = ABSOLUTE # ensure Absolute mode is enabled
tpad.data_mode = Pinnacle.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 input for a period of ``timeout`` seconds."""
print("using {} mode".format("Relative" if tpad.data_mode < ABSOLUTE else "Absolute"))
if tpad.data_mode == Pinnacle.RELATIVE:
print("using Relative mode")
elif tpad.data_mode == Pinnacle.ABSOLUTE:
print("using Absolute mode")
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
# only_new=False skips the extra SPI or I2C 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
if tpad.data_mode == Pinnacle.ABSOLUTE and data[3]:
# NOTE ``and data[3]`` means only when Z-axis is > 0
# specification 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:
elif tpad.data_mode == Pinnacle.RELATIVE:
# convert 2's compliment form into natural numbers
data = struct.unpack('Bbbb', data)
print(data)
Expand Down
15 changes: 7 additions & 8 deletions examples/cirque_pinnacle_usb_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
import board
from digitalio import DigitalInOut
import usb_hid
# if using a trackpad configured for SPI
from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchSPI, RELATIVE
# if using a trackpad configured for I2C
# from circuitpython_cirque_pinnacle.glidepoint import PinnacleTouchI2C, RELATIVE
# i2c = board.I2C()
import circuitpython_cirque_pinnacle.glidepoint as Pinnacle

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

# if using a trackpad configured for SPI
spi = board.SPI()
ss_pin = DigitalInOut(board.D7)
tpad = PinnacleTouchSPI(spi, ss_pin) # NOTE we did not pass the dr_pin
tpad = Pinnacle.PinnacleTouchSPI(spi, ss_pin, dr_pin=dr_pin)
# if using a trackpad configured for I2C
# tpad = PinnacleTouchI2C(i2c) # NOTE we did not pass the dr_pin
# i2c = board.I2C()
# tpad = Pinnacle.PinnacleTouchI2C(i2c, dr_pin=dr_pin)

tpad.data_mode = RELATIVE # ensure mouse mode is enabled
tpad.data_mode = Pinnacle.RELATIVE # ensure mouse mode is enabled

mouse = None
for dev in usb_hid.devices:
Expand Down

0 comments on commit 1a0dba3

Please sign in to comment.