|
6 | 6 | #
|
7 | 7 | # Written by SparkFun Electronics, May 2019
|
8 | 8 | #
|
9 |
| -# This python library supports the SparkFun Electroncis qwiic |
10 |
| -# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single |
11 |
| -# board computers. |
12 | 9 | #
|
13 | 10 | # More information on qwiic is at https:# www.sparkfun.com/qwiic
|
14 | 11 | #
|
|
28 | 25 | # Define the device name and I2C addresses. These are set in the class defintion
|
29 | 26 | # as class variables, making them avilable without having to create a class instance.
|
30 | 27 | #
|
31 |
| -# The base class and associated support functions use these class varables to |
32 |
| -# allow users to easily identify connected devices as well as provide basic |
33 |
| -# device services. |
34 |
| -# |
35 | 28 | # The name of this device - note this is private
|
36 | 29 | _DEFAULT_NAME = "Qwiic Serial Control Motor Driver"
|
37 | 30 |
|
@@ -62,11 +55,6 @@ def __init__(self):
|
62 | 55 | self.REG_OOR_CNT = 0
|
63 | 56 | self.REG_RO_WRITE_CNT = 0
|
64 | 57 |
|
65 |
| - |
66 |
| -# define the class that encapsulates the device being created. All information associated with this |
67 |
| -# device is encapsulated by this class. The device class should be the only value exported |
68 |
| -# from this module. |
69 |
| - |
70 | 58 | class QwiicScmd(object):
|
71 | 59 |
|
72 | 60 | # Constructor
|
@@ -205,16 +193,25 @@ class QwiicScmd(object):
|
205 | 193 | SCMD_REM_READ = 0x7E
|
206 | 194 |
|
207 | 195 |
|
208 |
| - def __init__(self, address=None): |
| 196 | + def __init__(self, address=None, i2c_driver=None): |
| 197 | + |
209 | 198 |
|
| 199 | + # Did the user specify an I2C address? |
210 | 200 | self.address = address if address != None else self.available_addresses[0]
|
211 | 201 |
|
212 |
| - # load the I2C driver |
| 202 | + # load the I2C driver if one isn't provided |
| 203 | + |
| 204 | + if i2c_driver == None: |
| 205 | + self._i2c = qwiic_i2c.getI2CDriver() |
| 206 | + if self._i2c == None: |
| 207 | + print("Unable to load I2C driver for this platform.") |
| 208 | + return |
| 209 | + else: |
| 210 | + self._i2c = i2c_driver |
213 | 211 |
|
214 |
| - self._i2c = qwiic_i2c.getI2CDriver() |
215 |
| - if self._i2c == None: |
216 |
| - print("Unable to load I2C driver for this platform.") |
217 |
| - return |
| 212 | + #---------------------------------------------- |
| 213 | + def isConnected(self): |
| 214 | + return qwiic_i2c.isDeviceConnected(self.address) |
218 | 215 |
|
219 | 216 | def begin(self):
|
220 | 217 |
|
|
0 commit comments