-
Notifications
You must be signed in to change notification settings - Fork 26
Add AddressableLEDBuffer #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
auscompgeek
wants to merge
18
commits into
robotpy:main
Choose a base branch
from
auscompgeek:led-buffer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9ad8db6
WIP: Add AddressableLEDBuffer
auscompgeek 58df7cf
Fully qualify frc::AddressableLED
auscompgeek 3983a09
Fully qualify Color
auscompgeek 102d43d
Add AddressableLEDBuffer::View
auscompgeek 239e800
Get it building
auscompgeek d7a3f75
AddressableLEDBuffer[slice] -> View
auscompgeek a600dc8
tests
auscompgeek 1961055
take slice to create view
auscompgeek 5712640
LEDPattern now writes to AddressableLEDBuffer
auscompgeek 22c498b
split AddressableLEDBuffer method bodies into TU
auscompgeek d517048
Merge tag '2027.0.0a6' into led-buffer
auscompgeek 7e10d07
reformat
auscompgeek e6129fe
fix test for 2027
auscompgeek 7152d70
I hate MSVC
auscompgeek b78eab3
override LEDPattern::ApplyTo std::span overloads
auscompgeek c5d979a
fix AddressableLED example
auscompgeek 794d389
overload AddressableLED::SetData
auscompgeek 8eeadfd
const-qualified implicit conversion to span
auscompgeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
subprojects/robotpy-wpilib/semiwrap/AddressableLEDBuffer.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| classes: | ||
| wpi::AddressableLEDBuffer: | ||
| methods: | ||
| AddressableLEDBuffer: | ||
| SetRGB: | ||
| SetHSV: | ||
| SetLED: | ||
| overloads: | ||
| size_t, const wpi::util::Color&: | ||
| size_t, const wpi::util::Color8Bit&: | ||
| size: | ||
| rename: __len__ | ||
| GetRed: | ||
| GetGreen: | ||
| GetBlue: | ||
| GetLED: | ||
| GetLED8Bit: | ||
| at: | ||
| rename: __getitem__ | ||
| begin: | ||
| ignore: true | ||
| end: | ||
| ignore: true | ||
| CreateView: | ||
| rename: __getitem__ | ||
| keepalive: | ||
| - [0, 1] | ||
| inline_code: | | ||
| .def("__iter__", [](wpi::AddressableLEDBuffer& self) { | ||
| return py::make_iterator(self.begin(), self.end()); | ||
| }, py::keep_alive<0, 1>()) | ||
| wpi::AddressableLEDBuffer::View: | ||
| methods: | ||
| size: | ||
| rename: __len__ | ||
| SetRGB: | ||
| SetHSV: | ||
| SetLED: | ||
| overloads: | ||
| size_t, const wpi::util::Color&: | ||
| size_t, const wpi::util::Color8Bit&: | ||
| at: | ||
| rename: __getitem__ | ||
| overloads: | ||
| size_t: | ||
| size_t [const]: | ||
| ignore: true | ||
| begin: | ||
| ignore: true | ||
| end: | ||
| ignore: true | ||
| GetLED: | ||
| GetLED8Bit: | ||
| inline_code: | | ||
| .def("__iter__", [](wpi::AddressableLEDBuffer::View& self) { | ||
| return py::make_iterator(self.begin(), self.end()); | ||
| }, py::keep_alive<0, 1>()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
subprojects/robotpy-wpilib/tests/test_addressable_led_buffer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # Copyright (c) FIRST and other WPILib contributors. | ||
| # Open Source Software; you can modify and/or share it under the terms of | ||
| # the WPILib BSD license file in the root directory of this project. | ||
|
|
||
| import pytest | ||
|
|
||
| from wpilib import AddressableLEDBuffer | ||
| from wpiutil import Color, Color8Bit | ||
|
|
||
| AddressableLEDBufferView = AddressableLEDBuffer.View | ||
|
|
||
|
|
||
| class TestAddressableLEDBuffer: | ||
| """Tests for AddressableLEDBuffer""" | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "h,s,v,r,g,b", | ||
| [ | ||
| (0, 0, 0, 0, 0, 0), # Black | ||
| (0, 0, 255, 255, 255, 255), # White | ||
| (0, 255, 255, 255, 0, 0), # Red | ||
| (60, 255, 255, 0, 255, 0), # Lime | ||
| (120, 255, 255, 0, 0, 255), # Blue | ||
| (30, 255, 255, 255, 255, 0), # Yellow | ||
| (90, 255, 255, 0, 255, 255), # Cyan | ||
| (150, 255, 255, 255, 0, 255), # Magenta | ||
| (0, 0, 191, 191, 191, 191), # Silver | ||
| (0, 0, 128, 128, 128, 128), # Gray | ||
| (0, 255, 128, 128, 0, 0), # Maroon | ||
| (30, 255, 128, 128, 128, 0), # Olive | ||
| (60, 255, 128, 0, 128, 0), # Green | ||
| (150, 255, 128, 128, 0, 128), # Purple | ||
| (90, 255, 128, 0, 128, 128), # Teal | ||
| (120, 255, 128, 0, 0, 128), # Navy | ||
| ], | ||
| ) | ||
| def test_hsv_convert(self, h, s, v, r, g, b): | ||
| """Test HSV to RGB conversion""" | ||
| buffer = AddressableLEDBuffer(length=1) | ||
| buffer.setHSV(0, h, s, v) | ||
| color = buffer.getLED8Bit(0) | ||
| assert color.red == r, "R value didn't match" | ||
| assert color.green == g, "G value didn't match" | ||
| assert color.blue == b, "B value didn't match" | ||
|
|
||
| def test_get_color(self): | ||
| """Test getting colors from buffer""" | ||
| buffer = AddressableLEDBuffer(4) | ||
| denim_color_8bit = Color8Bit(Color.DENIM) | ||
| first_blue_color_8bit = Color8Bit(Color.FIRST_BLUE) | ||
| first_red_color_8bit = Color8Bit(Color.FIRST_RED) | ||
|
|
||
| buffer.setLED(0, Color.FIRST_BLUE) | ||
| buffer.setLED(1, denim_color_8bit) | ||
| buffer.setLED(2, Color.FIRST_RED) | ||
| buffer.setLED(3, Color.FIRST_BLUE) | ||
|
|
||
| assert buffer.getLED(0) == Color.FIRST_BLUE | ||
| assert buffer.getLED(1) == Color.DENIM | ||
| assert buffer.getLED(2) == Color.FIRST_RED | ||
| assert buffer.getLED(3) == Color.FIRST_BLUE | ||
| assert buffer.getLED8Bit(0) == first_blue_color_8bit | ||
| assert buffer.getLED8Bit(1) == denim_color_8bit | ||
| assert buffer.getLED8Bit(2) == first_red_color_8bit | ||
| assert buffer.getLED8Bit(3) == first_blue_color_8bit | ||
|
|
||
| def test_get_red(self): | ||
| """Test getting red component""" | ||
| buffer = AddressableLEDBuffer(1) | ||
| buffer.setRGB(0, 127, 128, 129) | ||
| assert buffer.getRed(0) == 127 | ||
|
|
||
| def test_get_green(self): | ||
| """Test getting green component""" | ||
| buffer = AddressableLEDBuffer(1) | ||
| buffer.setRGB(0, 127, 128, 129) | ||
| assert buffer.getGreen(0) == 128 | ||
|
|
||
| def test_get_blue(self): | ||
| """Test getting blue component""" | ||
| buffer = AddressableLEDBuffer(1) | ||
| buffer.setRGB(0, 127, 128, 129) | ||
| assert buffer.getBlue(0) == 129 | ||
|
|
||
| def test_iteration(self): | ||
| buffer = AddressableLEDBuffer(3) | ||
| buffer.setRGB(0, 1, 2, 3) | ||
| buffer.setRGB(1, 4, 5, 6) | ||
| buffer.setRGB(2, 7, 8, 9) | ||
|
|
||
| results = [] | ||
|
|
||
| for led in buffer: | ||
| results.append((led.r, led.g, led.b)) | ||
|
|
||
| assert len(results) == 3 | ||
| assert results[0] == (1, 2, 3) | ||
| assert results[1] == (4, 5, 6) | ||
| assert results[2] == (7, 8, 9) | ||
|
|
||
| def test_iteration_on_empty_buffer(self): | ||
| buffer = AddressableLEDBuffer(0) | ||
|
|
||
| for led in buffer: | ||
| assert False, "Iterator should not return items on an empty buffer" | ||
|
|
||
|
|
||
| class TestAddressableLEDBufferView: | ||
| """Tests for AddressableLEDBufferView""" | ||
|
|
||
| def test_single_led(self): | ||
| """Test setting a single LED through a view""" | ||
| buffer = AddressableLEDBuffer(10) | ||
| view = buffer[5:6] | ||
| color = Color.AQUA | ||
| view.setLED(0, color) | ||
| assert buffer.getLED(5) == color | ||
| assert view.getLED(0) == color | ||
|
|
||
| def test_segment(self): | ||
| """Test segment view""" | ||
| buffer = AddressableLEDBuffer(10) | ||
| view = buffer[2:9] | ||
| view.setLED(0, Color.AQUA) | ||
| assert buffer.getLED(2) == Color.AQUA | ||
|
|
||
| view.setLED(6, Color.AZURE) | ||
| assert buffer.getLED(8) == Color.AZURE | ||
|
|
||
| @pytest.mark.skip("reversed views are not implemented") | ||
| def test_manual_reversed(self): | ||
| """Test manually reversed view""" | ||
| buffer = AddressableLEDBuffer(10) | ||
| view = buffer[8:1:-1] | ||
|
|
||
| # LED 0 in the view should write to LED 8 on the real buffer | ||
| view.setLED(0, Color.AQUA) | ||
| assert buffer.getLED(8) == Color.AQUA | ||
|
|
||
| # LED 6 in the view should write to LED 2 on the real buffer | ||
| view.setLED(6, Color.AZURE) | ||
| assert buffer.getLED(2) == Color.AZURE | ||
|
|
||
| @pytest.mark.skip("reversed views are not implemented") | ||
| def test_full_manual_reversed(self): | ||
| """Test full manual reversed view""" | ||
| buffer = AddressableLEDBuffer(10) | ||
| view = buffer[9::-1] | ||
| view.setLED(0, Color.WHITE) | ||
| assert buffer.getLED(9) == Color.WHITE | ||
|
|
||
| buffer.setLED(8, Color.RED) | ||
| assert view.getLED(1) == Color.RED | ||
|
|
||
| @pytest.mark.skip("reversed views are not implemented") | ||
| def test_reversed(self): | ||
| """Test reversed view""" | ||
| buffer = AddressableLEDBuffer(10) | ||
| view = buffer[:].reversed() | ||
| view.setLED(0, Color.WHITE) | ||
| assert buffer.getLED(9) == Color.WHITE | ||
|
|
||
| view.setLED(9, Color.RED) | ||
| assert buffer.getLED(0) == Color.RED |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.