Skip to content

Commit c095477

Browse files
committed
Small fixes.
1 parent 60e6866 commit c095477

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__pycache__
22
_build
33
*.pyc
4+
*.mpy

adafruit_tcs34725.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class TCS34725:
6969

7070
def __init__(self, i2c, address=0x29):
7171
self._device = i2c_device.I2CDevice(i2c, address)
72+
sensor_id = self._read_u8(_REGISTER_SENSORID)
7273
self._active = False
7374
self.integration_time = 2.4
7475
# Check sensor ID is expectd value.
@@ -78,34 +79,34 @@ def __init__(self, i2c, address=0x29):
7879

7980
def _read_u8(self, address):
8081
# Read an 8-bit unsigned value from the specified 8-bit address.
81-
with self._device:
82-
self._BUFFER[0] = address & 0xFF
83-
self._device.write(self._BUFFER, end=1)
84-
self._device.readinto(self._BUFFER, end=1)
82+
with self._device as i2c:
83+
self._BUFFER[0] = (address | _COMMAND_BIT) & 0xFF
84+
i2c.write(self._BUFFER, end=1, stop=False)
85+
i2c.readinto(self._BUFFER, end=1)
8586
return self._BUFFER[0]
8687

8788
def _read_u16(self, address):
8889
# Read a 16-bit BE unsigned value from the specified 8-bit address.
89-
with self._device:
90-
self._BUFFER[0] = address & 0xFF
91-
self._device.write(self._BUFFER, end=1)
92-
self._device.readinto(self._BUFFER, end=2)
90+
with self._device as i2c:
91+
self._BUFFER[0] = (address | _COMMAND_BIT) & 0xFF
92+
i2c.write(self._BUFFER, end=1, stop=False)
93+
i2c.readinto(self._BUFFER, end=2)
9394
return (self._BUFFER[0] << 8) | self._BUFFER[1]
9495

9596
def _write_u8(self, address, val):
9697
# Write an 8-bit unsigned value to the specified 8-bit address.
97-
with self._device:
98-
self._BUFFER[0] = address & 0xFF
98+
with self._device as i2c:
99+
self._BUFFER[0] = (address | _COMMAND_BIT) & 0xFF
99100
self._BUFFER[1] = val & 0xFF
100-
self._device.write(self._BUFFER, end=2)
101+
i2c.write(self._BUFFER, end=2)
101102

102103
def _write_u16(self, address, val):
103104
# Write a 16-bit BE unsigned value to the specified 8-bit address.
104-
with self._device:
105-
self._BUFFER[0] = address & 0xFF
105+
with self._device as i2c:
106+
self._BUFFER[0] = (address | _COMMAND_BIT) & 0xFF
106107
self._BUFFER[1] = (val >> 8) & 0xFF
107108
self._BUFFER[2] = val & 0xFF
108-
self._device.write(self._BUFFER)
109+
i2c.write(self._BUFFER)
109110

110111
@property
111112
def active(self):

0 commit comments

Comments
 (0)