Skip to content

Commit 16e928f

Browse files
committed
cleanup. constructor update
1 parent 339f9a2 commit 16e928f

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

qwiic_scmd.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
#
77
# Written by SparkFun Electronics, May 2019
88
#
9-
# This python library supports the SparkFun Electroncis qwiic
10-
# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
11-
# board computers.
129
#
1310
# More information on qwiic is at https:# www.sparkfun.com/qwiic
1411
#
@@ -28,10 +25,6 @@
2825
# Define the device name and I2C addresses. These are set in the class defintion
2926
# as class variables, making them avilable without having to create a class instance.
3027
#
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-
#
3528
# The name of this device - note this is private
3629
_DEFAULT_NAME = "Qwiic Serial Control Motor Driver"
3730

@@ -62,11 +55,6 @@ def __init__(self):
6255
self.REG_OOR_CNT = 0
6356
self.REG_RO_WRITE_CNT = 0
6457

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-
7058
class QwiicScmd(object):
7159

7260
# Constructor
@@ -205,16 +193,25 @@ class QwiicScmd(object):
205193
SCMD_REM_READ = 0x7E
206194

207195

208-
def __init__(self, address=None):
196+
def __init__(self, address=None, i2c_driver=None):
197+
209198

199+
# Did the user specify an I2C address?
210200
self.address = address if address != None else self.available_addresses[0]
211201

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
213211

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)
218215

219216
def begin(self):
220217

0 commit comments

Comments
 (0)