@@ -69,6 +69,7 @@ class TCS34725:
69
69
70
70
def __init__ (self , i2c , address = 0x29 ):
71
71
self ._device = i2c_device .I2CDevice (i2c , address )
72
+ sensor_id = self ._read_u8 (_REGISTER_SENSORID )
72
73
self ._active = False
73
74
self .integration_time = 2.4
74
75
# Check sensor ID is expectd value.
@@ -78,34 +79,34 @@ def __init__(self, i2c, address=0x29):
78
79
79
80
def _read_u8 (self , address ):
80
81
# 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 )
85
86
return self ._BUFFER [0 ]
86
87
87
88
def _read_u16 (self , address ):
88
89
# 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 )
93
94
return (self ._BUFFER [0 ] << 8 ) | self ._BUFFER [1 ]
94
95
95
96
def _write_u8 (self , address , val ):
96
97
# 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
99
100
self ._BUFFER [1 ] = val & 0xFF
100
- self . _device .write (self ._BUFFER , end = 2 )
101
+ i2c .write (self ._BUFFER , end = 2 )
101
102
102
103
def _write_u16 (self , address , val ):
103
104
# 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
106
107
self ._BUFFER [1 ] = (val >> 8 ) & 0xFF
107
108
self ._BUFFER [2 ] = val & 0xFF
108
- self . _device .write (self ._BUFFER )
109
+ i2c .write (self ._BUFFER )
109
110
110
111
@property
111
112
def active (self ):
0 commit comments