|
65 | 65 | # Drivers and driver baseclass |
66 | 66 | from .i2c_driver import I2CDriver |
67 | 67 |
|
| 68 | +# All supported platform module and class names |
| 69 | +sub_modules = ["linux_i2c", "circuitpy_i2c", "micropython_i2c"] |
| 70 | +class_names = ["LinuxI2C", "CircuitPythonI2C", "MicroPythonI2C"] |
| 71 | + |
| 72 | +# List of platform drivers found on this system |
68 | 73 | _drivers = [] |
69 | | -# foo = ["LinuxI2C", "CircuitPythonI2C", "MicroPythonI2C"] |
70 | | - |
71 | | -# for driver in foo: |
72 | | -# try: |
73 | | -# print("Importing:", driver) |
74 | | -# submodule = __import__(driver) |
75 | | -# print("Submodule:", submodule) |
76 | | -# _drivers.append(submodule) |
77 | | -# except: |
78 | | -# print("Could not import:", driver) |
79 | | -# pass |
80 | | - |
81 | | -try: |
82 | | - from .linux_i2c import LinuxI2C |
83 | | - _drivers.append(LinuxI2C) |
84 | | -except: |
85 | | - pass |
86 | | - |
87 | | -try: |
88 | | - from .circuitpy_i2c import CircuitPythonI2C |
89 | | - _drivers.append(CircuitPythonI2C) |
90 | | -except: |
91 | | - pass |
92 | | - |
93 | | -try: |
94 | | - from .micropython_i2c import MicroPythonI2C |
95 | | - _drivers.append(MicroPythonI2C) |
96 | | -except: |
97 | | - pass |
| 74 | + |
| 75 | +# Loop through all supported platform drivers, see if they're included, and |
| 76 | +# append them to the driver list if so |
| 77 | +for i in range(len(sub_modules)): |
| 78 | + try: |
| 79 | + full_name = "qwiic_i2c." + sub_modules[i] |
| 80 | + sub_module = __import__(full_name, None, None, [None]) |
| 81 | + _drivers.append(getattr(sub_module, class_names[i])) |
| 82 | + except: |
| 83 | + pass |
98 | 84 |
|
99 | 85 | _theDriver = None |
100 | 86 |
|
|
0 commit comments