diff --git a/circuitpython_cirque_pinnacle/glidepoint.py b/circuitpython_cirque_pinnacle/glidepoint.py index e48095c..e4fbb92 100644 --- a/circuitpython_cirque_pinnacle/glidepoint.py +++ b/circuitpython_cirque_pinnacle/glidepoint.py @@ -1,5 +1,5 @@ """ -A driver class for the Cirque Pinnacle ASIC on the Cirque capacitive touch +A driver class for the Cirque Pinnacle ASIC on the Cirque capacitve touch based circular trackpads. """ __version__ = "0.0.0-auto.0" @@ -7,7 +7,6 @@ import time from struct import pack, unpack from micropython import const - try: from ubus_device import SPIDevice, I2CDevice except ImportError: @@ -36,10 +35,8 @@ CRTL_REPEAT = const(0x80) CRTL_PWR_IDLE = const(0x40) - class PinnacleTouch: """The abstract base class for driving the Pinnacle ASIC.""" - def __init__(self, dr_pin=None): self.dr_pin = dr_pin if dr_pin is not None: @@ -78,7 +75,7 @@ def data_mode(self): @data_mode.setter def data_mode(self, mode): if mode not in (ANYMEAS, RELATIVE, ABSOLUTE): - raise ValueError("Unrecognized input value for data_mode.") + raise ValueError("Unrecognised input value for data_mode.") sys_config = self._rap_read(3) & 0xE7 # clear AnyMeas mode flags if mode in (RELATIVE, ABSOLUTE): if self.data_mode == ANYMEAS: # if leaving AnyMeas mode @@ -104,16 +101,11 @@ def data_mode(self, mode): def hard_configured(self): """This `bool` attribute can be used to inform applications about factory customized hardware configuration.""" - return bool(self._rap_read(0x1F)) - - def relative_mode_config( - self, - rotate90=False, - taps=True, - secondary_tap=True, - glide_extend=True, - intellimouse=False, - ): + return bool(self._rap_read(0x1f)) + + def relative_mode_config(self, rotate90=False, taps=True, + secondary_tap=True, glide_extend=True, + intellimouse=False): """Configure settings specific to Relative mode (AKA Mouse mode) data reporting.""" if self.data_mode == RELATIVE: @@ -121,7 +113,8 @@ def relative_mode_config( config2 |= ((not secondary_tap) << 2) | ((not taps) << 1) self._rap_write(5, config2 | bool(intellimouse)) - def absolute_mode_config(self, z_idle_count=30, invert_x=False, invert_y=False): + def absolute_mode_config(self, z_idle_count=30, + invert_x=False, invert_y=False): """Configure settings specific to Absolute mode (reports axis positions).""" if self.data_mode == ABSOLUTE: @@ -202,9 +195,8 @@ def sample_rate(self, val): val = val if val in (100, 80, 60, 40, 20, 10) else 100 self._rap_write(9, val) - def detect_finger_stylus( - self, enable_finger=True, enable_stylus=True, sample_rate=100 - ): + def detect_finger_stylus(self, enable_finger=True, + enable_stylus=True, sample_rate=100): """This function will configure the Pinnacle ASIC to detect either finger, stylus, or both.""" finger_stylus = self._era_read(0x00EB) @@ -212,7 +204,8 @@ def detect_finger_stylus( self._era_write(0x00EB, finger_stylus) self.sample_rate = sample_rate - def calibrate(self, run, tap=True, track_error=True, nerd=True, background=True): + def calibrate(self, run, tap=True, track_error=True, nerd=True, + background=True): """Set calibration parameters when the Pinnacle ASIC calibrates itself.""" if self.data_mode != ANYMEAS: @@ -231,13 +224,13 @@ def calibration_matrix(self): measurements.""" # combine every 2 bytes from resulting buffer into list of signed # 16-bits integers - return list(unpack("46h", self._era_read_bytes(0x01DF, 92))) + return list(unpack('46h', self._era_read_bytes(0x01DF, 92))) @calibration_matrix.setter def calibration_matrix(self, matrix): - matrix += [0] * (46 - len(matrix)) # pad short matrices w/ 0s + matrix += [0] * (46 - len(matrix)) # padd short matrices w/ 0s for index in range(46): - buf = pack("h", matrix[index]) + buf = pack('h', matrix[index]) self._era_write(0x01DF + index * 2, buf[0]) self._era_write(0x01DF + index * 2 + 1, buf[1]) @@ -249,26 +242,21 @@ def set_adc_gain(self, sensitivity): val = self._era_read(0x0187) & 0x3F | (sensitivity << 6) self._era_write(0x0187, val) - def tune_edge_sensitivity(self, x_axis_wide_z_min=0x04, y_axis_wide_z_min=0x03): + def tune_edge_sensitivity(self, x_axis_wide_z_min=0x04, + y_axis_wide_z_min=0x03): """Changes thresholds to improve detection of fingers.""" self._era_write(0x0149, x_axis_wide_z_min) self._era_write(0x0168, y_axis_wide_z_min) - def anymeas_mode_config( - self, - gain=GAIN_200, - frequency=FREQ_0, - sample_length=512, - mux_ctrl=MUX_PNP, - apperture_width=500, - ctrl_pwr_cnt=1, - ): + def anymeas_mode_config(self, gain=GAIN_200, frequency=FREQ_0, + sample_length=512, mux_ctrl=MUX_PNP, + apperture_width=500, ctrl_pwr_cnt=1): """This function configures the Pinnacle ASIC to output raw ADC measurements.""" if self.data_mode == ANYMEAS: anymeas_config = [2, 3, 4, 0, 4, 0, 19, 0, 0, 1] anymeas_config[0] = gain | frequency - anymeas_config[1] = max(1, min(int(sample_length / 128), 3)) + anymeas_config[1] = (max(1, min(int(sample_length / 128), 3))) anymeas_config[2] = mux_ctrl anymeas_config[4] = max(2, min(int(apperture_width / 125), 15)) anymeas_config[9] = ctrl_pwr_cnt @@ -326,7 +314,7 @@ def _rap_write_bytes(self, reg, values): def _era_read(self, reg): prev_feed_state = self.feed_enable self.feed_enable = False # accessing raw memory, so do this - self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xFF]) + self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xff]) self._rap_write(0x1E, 1) # indicate reading only 1 byte while self._rap_read(0x1E): # read until reg == 0 pass # also sets Command Complete flag in Status register @@ -339,7 +327,7 @@ def _era_read_bytes(self, reg, numb_bytes): buf = b"" prev_feed_state = self.feed_enable self.feed_enable = False # accessing raw memory, so do this - self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xFF]) + self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xff]) for _ in range(numb_bytes): self._rap_write(0x1E, 5) # indicate reading sequential bytes while self._rap_read(0x1E): # read until reg == 0 @@ -353,7 +341,7 @@ def _era_write(self, reg, value): prev_feed_state = self.feed_enable self.feed_enable = False # accessing raw memory, so do this self._rap_write(0x1B, value) # write value - self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xFF]) + self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xff]) self._rap_write(0x1E, 2) # indicate writing only 1 byte while self._rap_read(0x1E): # read until reg == 0 pass # also sets Command Complete flag in Status register @@ -365,7 +353,7 @@ def _era_write_bytes(self, reg, value, numb_bytes): prev_feed_state = self.feed_enable self.feed_enable = False # accessing raw memory, so do this self._rap_write(0x1B, value) # write value - self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xFF]) + self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xff]) self._rap_write(0x1E, 0x0A) # indicate writing sequential bytes for _ in range(numb_bytes): while self._rap_read(0x1E): # read until reg == 0 @@ -373,12 +361,10 @@ def _era_write_bytes(self, reg, value, numb_bytes): self.clear_flags() self.feed_enable = prev_feed_state # resume previous feed state - # pylint: disable=no-member class PinnacleTouchI2C(PinnacleTouch): """Parent class for interfacing with the Pinnacle ASIC via the I2C protocol.""" - def __init__(self, i2c, address=0x2A, dr_pin=None): self._i2c = I2CDevice(i2c, address) super(PinnacleTouchI2C, self).__init__(dr_pin=dr_pin) @@ -408,13 +394,12 @@ def _rap_write_bytes(self, reg, values): with self._i2c as i2c: i2c.write(buf) - class PinnacleTouchSPI(PinnacleTouch): """Parent class for interfacing with the Pinnacle ASIC via the SPI protocol.""" - def __init__(self, spi, ss_pin, spi_frequency=12000000, dr_pin=None): - self._spi = SPIDevice(spi, chip_select=ss_pin, phase=1, baudrate=spi_frequency) + self._spi = SPIDevice(spi, chip_select=ss_pin, phase=1, + baudrate=spi_frequency) super(PinnacleTouchSPI, self).__init__(dr_pin=dr_pin) def _rap_read(self, reg): diff --git a/circuitpython_cirque_pinnacle/glidepoint_lite.py b/circuitpython_cirque_pinnacle/glidepoint_lite.py index 3dc6d9b..4c04dbc 100644 --- a/circuitpython_cirque_pinnacle/glidepoint_lite.py +++ b/circuitpython_cirque_pinnacle/glidepoint_lite.py @@ -3,7 +3,6 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/2bndy5/CircuitPython_Cirque_Pinnacle.git" import time - try: from ubus_device import SPIDevice, I2CDevice except ImportError: @@ -13,7 +12,6 @@ RELATIVE = 0x00 ABSOLUTE = 0x02 - class PinnacleTouch: def __init__(self, dr_pin=None): self.dr_pin = dr_pin @@ -46,27 +44,23 @@ def data_mode(self): @data_mode.setter def data_mode(self, mode): if mode not in (RELATIVE, ABSOLUTE): - raise ValueError("Unrecognized input value for data_mode.") + raise ValueError("Unrecognised input value for data_mode.") self._rap_write(4, 1 | mode) self._mode = mode @property def hard_configured(self): - return bool(self._rap_read(0x1F)) - - def relative_mode_config( - self, - rotate90=False, - taps=True, - secondary_tap=True, - glide_extend=True, - intellimouse=False, - ): + return bool(self._rap_read(0x1f)) + + def relative_mode_config(self, rotate90=False, taps=True, + secondary_tap=True, glide_extend=True, + intellimouse=False): config2 = (rotate90 << 7) | ((not glide_extend) << 4) config2 |= ((not secondary_tap) << 2) | ((not taps) << 1) self._rap_write(5, config2 | bool(intellimouse)) - def absolute_mode_config(self, z_idle_count=30, invert_x=False, invert_y=False): + def absolute_mode_config(self, z_idle_count=30, + invert_x=False, invert_y=False): self._rap_write(0x0A, max(0, min(z_idle_count, 255))) config1 = self._rap_read(4) & 0x3F | (invert_y << 7) self._rap_write(4, config1 | (invert_x << 6)) @@ -147,7 +141,7 @@ def _rap_write_bytes(self, reg, values): def _era_read(self, reg): prev_feed_state = self.feed_enable self.feed_enable = False - self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xFF]) + self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xff]) self._rap_write(0x1E, 1) while self._rap_read(0x1E): pass @@ -157,10 +151,10 @@ def _era_read(self, reg): return buf def _era_read_bytes(self, reg, numb_bytes): - buf = b"" + buf = b'' prev_feed_state = self.feed_enable self.feed_enable = False - self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xFF]) + self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xff]) for _ in range(numb_bytes): self._rap_write(0x1E, 5) while self._rap_read(0x1E): @@ -174,14 +168,13 @@ def _era_write(self, reg, value): prev_feed_state = self.feed_enable self.feed_enable = False self._rap_write(0x1B, value) - self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xFF]) + self._rap_write_bytes(0x1C, [reg >> 8, reg & 0xff]) self._rap_write(0x1E, 2) while self._rap_read(0x1E): pass self.clear_flags() self.feed_enable = prev_feed_state - # pylint: disable=no-member class PinnacleTouchI2C(PinnacleTouch): def __init__(self, i2c, address=0x2A, dr_pin=None): @@ -209,10 +202,10 @@ def _rap_write_bytes(self, reg, values): with self._i2c as i2c: i2c.write(buf) - class PinnacleTouchSPI(PinnacleTouch): def __init__(self, spi, ss_pin, spi_frequency=12000000, dr_pin=None): - self._spi = SPIDevice(spi, chip_select=ss_pin, phase=1, baudrate=spi_frequency) + self._spi = SPIDevice(spi, chip_select=ss_pin, phase=1, + baudrate=spi_frequency) super(PinnacleTouchSPI, self).__init__(dr_pin=dr_pin) def _rap_read(self, reg):