Skip to content

Commit 559c8aa

Browse files
authored
Merge pull request #123 from astro-pi/feature/rgb-function
Feature/rgb function
2 parents 91e9c89 + dd335ff commit 559c8aa

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

docs/api.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@ The following properties of the `ColourSensor` object provide direct access to t
881881
`blue_raw` | int | The amount of incident blue light, between 0 and `max_raw`
882882
`clear_raw` | int | The amount of incident light (brightness), between 0 and `max_raw`
883883
`colour_raw` | tuple | A 4-tuple containing the RGBC (Red, Green, Blue and Clear) raw sensor readings, each between 0 and `max_raw`
884+
`rgb` | tuple | A 3-tuple containing the RGB raw sensor readings, each between 0 and `max_raw`.
885+
`brightness` | int | An alias to the `clear_raw` property - the amount of incident light, between 0 and `max_raw`
884886

885887
Here is an example comparing raw values to the corresponding scaled ones, for a given number of integration cycles.
886888

@@ -901,4 +903,4 @@ print(f"Scaled values: {sense.colour.colour}")
901903

902904
Custom Sense HAT exceptions are statically defined in the `sense_hat.exceptions` module.
903905
The exceptions relate to problems encountered while initialising the colour chip or due to setting invalid parameters.
904-
Each exception includes a message describing the issue encountered, and is subclassed from the base class `SenseHatException`.
906+
Each exception includes a message describing the issue encountered, and is subclassed from the base class `SenseHatException`.

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## v2
44

5+
### 2.4.0
6+
- Added `rgb` method to allow for easy reuse of sense hat colour sensor values
7+
- Added `brightness` method alias for the sense hat colour sensor
8+
59
### 2.3.x
610

711
- Added support for the light/colour sensor in the v2 Sense HAT

sense_hat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
ACTION_HELD,
1414
)
1515

16-
__version__ = '2.3.1'
16+
__version__ = '2.4.0'

sense_hat/colour.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class HardwareInterface:
1515
actual hardware. Using this intermediate layer of abstraction, a
1616
`ColourSensor` object interacts with the hardware without being
1717
aware of how this interaction is implemented.
18-
1918
Different subclasses of the `HardwareInterface` class can provide
2019
access to the hardware through e.g. I2C, `libiio` and its system
2120
files or even a hardware emulator.
@@ -131,7 +130,6 @@ class I2C(HardwareInterface):
131130
"""
132131
An implementation of the `HardwareInterface` for the TCS34725 sensor
133132
that uses I2C to control the sensor and retrieve measurements.
134-
135133
Use the datasheet as a reference: https://ams.com/tcs34725#tab/documents
136134
"""
137135

@@ -342,6 +340,7 @@ def colour_raw(self):
342340
green_raw = property(lambda self: self.interface.get_green())
343341
blue_raw = property(lambda self: self.interface.get_blue())
344342
clear_raw = property(lambda self: self.interface.get_clear())
343+
brightness = clear_raw
345344

346345
@property
347346
def _scaling(self):
@@ -351,6 +350,10 @@ def _scaling(self):
351350
def colour(self):
352351
return tuple(reading // self._scaling for reading in self.colour_raw)
353352

353+
@property
354+
def rgb(self):
355+
return tuple(reading // self._scaling for reading in self.colour_raw)[0:3]
356+
354357
color = colour
355358
red = property(lambda self: self.red_raw // self._scaling )
356359
green = property(lambda self: self.green_raw // self._scaling )

0 commit comments

Comments
 (0)