|
117 | 117 | _BIT_POS_PERS_PPERS = const(4)
|
118 | 118 | _BIT_MASK_PERS_PPERS = const(0xF0)
|
119 | 119 |
|
| 120 | +_BIT_POS_CONTROL_AGAIN = const(0) |
| 121 | +_BIT_MASK_CONTROL_AGAIN = const(3) |
120 | 122 |
|
| 123 | +# pylint: disable-msg=too-many-instance-attributes |
121 | 124 | class APDS9960:
|
122 | 125 | """
|
123 | 126 | Provide basic driver services for the APDS9960 breakout board
|
@@ -218,10 +221,10 @@ def __init__(
|
218 | 221 | self._write8(_APDS9960_GCONF2, 0x41)
|
219 | 222 | # GPULSE: 5 (6 pulses), GPLEN: 2 (16 us)
|
220 | 223 | self._write8(_APDS9960_GPULSE, 0x85)
|
221 |
| - # ATIME: 255 (712ms color integration time, max count of 65535) |
222 |
| - self._write8(_APDS9960_ATIME, 0x00) |
223 |
| - # AGAIN: 1 (4x color gain), PGAIN: 0 (1x) (default), LDRIVE: 0 (100 mA) (default) |
224 |
| - self._write8(_APDS9960_CONTROL, 0x01) |
| 224 | + # ATIME: 256 (712ms color integration time, max count of 65535) |
| 225 | + self.color_integration_time = 256 |
| 226 | + # AGAIN: 1 (4x color gain) |
| 227 | + self.color_gain = 1 |
225 | 228 |
|
226 | 229 | ## BOARD
|
227 | 230 | @property
|
@@ -328,6 +331,53 @@ def color_data_ready(self) -> int:
|
328 | 331 | This flag is reset when `color_data` is read."""
|
329 | 332 | return self._get_bit(_APDS9960_STATUS, _BIT_MASK_STATUS_AVALID)
|
330 | 333 |
|
| 334 | + @property |
| 335 | + def color_gain(self) -> int: |
| 336 | + """Color/light sensor gain value. |
| 337 | +
|
| 338 | + This sets the gain multiplier for the ADC during color/light engine operations. |
| 339 | +
|
| 340 | + .. csv-table:: |
| 341 | + :header: "``color_gain``", "Gain Multiplier", "Note" |
| 342 | +
|
| 343 | + 0, "1x", "Power-on Default" |
| 344 | + 1, "4x", "Driver Default" |
| 345 | + 2, "16x", "" |
| 346 | + 3, "64x", "" |
| 347 | + """ |
| 348 | + return self._get_bits( |
| 349 | + _APDS9960_CONTROL, _BIT_POS_CONTROL_AGAIN, _BIT_MASK_CONTROL_AGAIN |
| 350 | + ) |
| 351 | + |
| 352 | + @color_gain.setter |
| 353 | + def color_gain(self, value: int) -> None: |
| 354 | + self._set_bits( |
| 355 | + _APDS9960_CONTROL, _BIT_POS_CONTROL_AGAIN, _BIT_MASK_CONTROL_AGAIN, value |
| 356 | + ) |
| 357 | + |
| 358 | + @property |
| 359 | + def color_integration_time(self) -> int: |
| 360 | + """Color/light sensor gain. |
| 361 | +
|
| 362 | + Represents the integration time in number of 2.78 ms cycles for the ADC during color/light |
| 363 | + engine operations. This also effectively sets the maxmium value returned for each channel |
| 364 | + by `color_data`. |
| 365 | +
|
| 366 | + .. csv-table:: |
| 367 | + :header: "``color_integration_time``", "Time", "Max Count", "Note" |
| 368 | +
|
| 369 | + 1, "2.78 ms", 1025, "Power-on Default" |
| 370 | + 10, "27.8 ms", 10241, "" |
| 371 | + 37, "103 ms", 37889, "" |
| 372 | + 72, "200 ms", 65535, "Driver Default" |
| 373 | + 256, "712 ms", 65535, "" |
| 374 | + """ |
| 375 | + return 256 - self._read8(_APDS9960_ATIME) |
| 376 | + |
| 377 | + @color_integration_time.setter |
| 378 | + def color_integration_time(self, value: int) -> None: |
| 379 | + self._write8(_APDS9960_ATIME, 256 - value) |
| 380 | + |
331 | 381 | ## PROXIMITY
|
332 | 382 | @property
|
333 | 383 | def proximity(self) -> int:
|
|
0 commit comments