|
45 | 45 |
|
46 | 46 |
|
47 | 47 | _GT_DEFAULT_I2C_ADDR = 0x5D |
| 48 | +_GT_SECONDARY_I2C_ADDR = 0x14 |
48 | 49 |
|
49 | 50 | _GT_COMMAND = const(0x8040) |
50 | 51 |
|
@@ -73,23 +74,39 @@ class GT911_Touch: |
73 | 74 | A driver for the GT911 capacitive touch sensor. |
74 | 75 | """ |
75 | 76 |
|
76 | | - def __init__(self, i2c, res_pin, address=_GT_DEFAULT_I2C_ADDR, debug=False, irq_pin=None): |
| 77 | + def __init__(self, i2c, res_pin, i2c_address=None, debug=False, irq_pin=None): |
77 | 78 |
|
78 | 79 | self._debug = debug |
79 | 80 | self._irq_pin = irq_pin |
80 | 81 |
|
81 | 82 | if type(res_pin) != digitalio.DigitalInOut: |
82 | 83 | raise RuntimeError("res_pin must be of type digitalio.DigitalInOut") |
83 | 84 |
|
| 85 | + if i2c_address is not None: |
| 86 | + address = i2c_address |
| 87 | + else: |
| 88 | + address = _GT_DEFAULT_I2C_ADDR |
| 89 | + |
84 | 90 | self._reset(address,res_pin,irq_pin) |
85 | 91 | try: |
86 | 92 | self._i2c = I2CDevice(i2c, address) |
87 | 93 | except: |
88 | 94 | if debug: |
89 | 95 | print("Second reset attempt") |
90 | | - self._reset(address,res_pin,irq_pin) |
91 | | - self._i2c = I2CDevice(i2c, address) |
| 96 | + if i2c_address is None: |
| 97 | + address = _GT_SECONDARY_I2C_ADDR |
| 98 | + try: |
| 99 | + self._i2c = I2CDevice(i2c,address) |
| 100 | + except: |
| 101 | + self._reset(address,res_pin,irq_pin) |
| 102 | + self._i2c = I2CDevice(i2c, address) |
| 103 | + else: |
| 104 | + self._reset(address,res_pin,irq_pin) |
| 105 | + self._i2c = I2CDevice(i2c, address) |
92 | 106 |
|
| 107 | + if debug: |
| 108 | + print("I2C Address:",address) |
| 109 | + |
93 | 110 | self._last_touch = self._read_last_touch() |
94 | 111 |
|
95 | 112 | chip_id = chr(self._read(_GT_REG_PRODID_1,1)[0]) |
@@ -169,7 +186,7 @@ def touches(self) -> List[dict]: |
169 | 186 | return touchpoints |
170 | 187 |
|
171 | 188 | def _reset(self, address, res_pin, irq_pin=None) -> None: |
172 | | - """ Initialize board """ |
| 189 | + """ Initialize board - This sometimes fails, Ctrl-D reset to recover """ |
173 | 190 | time.sleep(.0001) |
174 | 191 | res_pin.direction = digitalio.Direction.OUTPUT |
175 | 192 | res_pin.value = True |
|
0 commit comments