Skip to content

Commit a4a963d

Browse files
Modify function to append dummy clear value if not provided (#1231)
closes RaspberryPiFoundation/digital-editor-issues#610 Tested using - ``` _ish.colourRead = lambda: [100, 150, 200, 128] sh = SenseHat() # TEST 1: Full colour tuple rgba = sh.colour.colour assert isinstance(rgba, tuple), "colour should return a tuple" assert len(rgba) == 4, "colour should return a 4-tuple (R, G, B, Clear)" assert rgba == (100, 150, 200, 128), f"Unexpected colour values: {rgba}" # TEST 2: Individual colour components assert sh.colour.red == 100, f"Red value incorrect: {sh.colour.red}" assert sh.colour.green == 150, f"Green value incorrect: {sh.colour.green}" assert sh.colour.blue == 200, f"Blue value incorrect: {sh.colour.blue}" assert sh.colour.clear == 128, f"Clear value incorrect: {sh.colour.clear}" # TEST 3: Aliases assert sh.colour.color == sh.colour.colour, "color alias not matching colour" assert sh.colour.color_raw == sh.colour.colour_raw, "color_raw alias not matching colour_raw" # TEST 4: Raw colour data raw = sh.colour.colour_raw assert isinstance(raw, tuple), "colour_raw should return a tuple" assert raw == (100, 150, 200, 128), f"Unexpected raw values: {raw}" print("✅ All tests passed successfully!") ```
1 parent 09d28c7 commit a4a963d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
- Enabled `hyphens: auto` globally (with exceptions) to prevent overflow with longer words (#1215)
1616
- Removed fixed size from `ProjectBar` to prevent overflow when text wraps (#1221)
1717
- Added missing translation strings (#1222)
18+
- Changed `colour_raw` to now correctly return a 4-tuple (R, G, B, Clear) in simulation
1819

1920
## Changed
2021

public/shims/sense_hat/sense_hat_blob.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,14 @@ def max_raw(self):
673673

674674
@property
675675
def colour_raw(self):
676-
return _ish.colourRead()
676+
"""
677+
Ensure a 4 length tuple is returned even if simulation only provides 3 values
678+
"""
679+
data = _ish.colourRead()
680+
if len(data) == 3:
681+
data.append(256) # Append dummy Clear value
682+
return tuple(data)
683+
677684

678685
@property
679686
def red_raw(self):
@@ -1507,7 +1514,7 @@ def get_compass(self):
15071514
# but the emulator cannot do fusionPose as we derive everything from the orientation.
15081515
# Therefore, we a shortcut and read directly from our internal module that applies compass tilt compensation algorithm
15091516
# and returns the heading in radians.
1510-
1517+
15111518
deg = math.degrees(_ish.headingRead())
15121519

15131520
return deg + 360 if deg < 0 else deg

0 commit comments

Comments
 (0)