-
Notifications
You must be signed in to change notification settings - Fork 31
add optional support for WS2812 RGB LED, fixes #106 #178
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
Draft
ThomasWaldmann
wants to merge
3
commits into
ecocurious2:master
Choose a base branch
from
ThomasWaldmann:ws2812
base: master
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.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // show status indication via WS2812 RGB LED | ||
|
|
||
| #include "userdefines.h" | ||
|
|
||
| #include <NeoPixelBus.h> | ||
|
|
||
| #include "log.h" | ||
| #include "status_led.h" | ||
|
|
||
| #define PIXEL_COUNT 1 | ||
| #define PIXEL_PIN 25 | ||
|
|
||
| RgbColor red(255, 0, 0); | ||
| RgbColor green(0, 255, 0); | ||
| RgbColor blue(0, 0, 255); | ||
| RgbColor yellow(255, 255, 0); | ||
| RgbColor white(255, 255, 255); | ||
| RgbColor black(0, 0, 0); | ||
|
|
||
| static NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod> LEDs(PIXEL_COUNT, PIXEL_PIN); | ||
|
|
||
| static RgbColor last_col; | ||
|
|
||
| static void set_LED(RgbColor col) { | ||
| if (col == last_col) | ||
| return; // nothing to change | ||
|
|
||
| LEDs.SetPixelColor(0, col); // only 1 LED at index 0 | ||
| LEDs.Show(); | ||
| last_col = col; | ||
| } | ||
|
|
||
| void setup_status_LED(void) { | ||
| LEDs.Begin(); // all LEDs off | ||
| LEDs.Show(); | ||
| last_col = black; // consistency sw state == hw state | ||
| } | ||
|
|
||
| static void compute_color(unsigned int indication, | ||
| unsigned int mask_r, unsigned int mask_g, unsigned int mask_b, | ||
| RgbColor *color) { | ||
| // assign to *color depending on whether the r/g/b masked bits are set in the indication value | ||
| *color = RgbColor((indication & mask_r) ? 255 : 0, | ||
| (indication & mask_g) ? 255 : 0, | ||
| (indication & mask_b) ? 255 : 0); | ||
| } | ||
|
|
||
| #define IDX_W 2 | ||
| #define CSL 30 | ||
|
|
||
| void indicate(float radiation, unsigned int indication) { | ||
| // radiation [uSv/h] given to set the primary color R that is shown most of the time | ||
| // indication: 32 bit flags to indicate additional stuff, see status_led.h. | ||
| // | ||
| // this code will generate a time sequence of LED colors: | ||
| // index color | ||
| // ------------------------------------------------------ | ||
| // 0 dark (LED init) | ||
| // 1 indication color 1 | ||
| // ... reserved for more indications | ||
| // IDX_W white (LED test) | ||
| // ...+1 radiation color | ||
| // ... radiation color | ||
| // CSL-1 radiation color | ||
|
|
||
| RgbColor col; | ||
| static int index = 0; // index counting modulo COLOR_SEQUENCE_LENGTH | ||
|
|
||
| log(INFO, "LED index: %d, radiation: %f", index, radiation); | ||
|
|
||
| switch (index) { | ||
| case 0: // show a fixed dark separator after LED init | ||
| col = black; | ||
| break; | ||
| case 1: | ||
| // indication color 1: R G B | ||
| compute_color(indication, I_CONN_ERROR, I_TEST, I_HV_ERROR, &col); | ||
| break; | ||
| case IDX_W: // show a fixed white separator and LED test | ||
| col = white; | ||
| break; | ||
| default: // show radiation color | ||
| if (radiation > 1.0) { | ||
| col = red; | ||
| } else if (radiation > 0.2) { | ||
| col = yellow; | ||
| } else if (radiation > 0.01) { | ||
| col = green; | ||
| } else { | ||
| col = black; | ||
| } | ||
| } | ||
|
|
||
| set_LED(col); | ||
|
|
||
| if (++index == CSL) | ||
| index = 0; | ||
| } |
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,17 @@ | ||
| // show status indication via WS2812 RGB LED | ||
|
|
||
| // indication value used to reset indications to "all off" | ||
| #define I_RESET 0 | ||
| // indication value used to mask no bit, e.g. in compute_color | ||
| #define I_NONE 0 | ||
|
|
||
| // indications, values are 32bit bit masks, valid values are 2^N | ||
| #define I_TEST 1 // reserved to test the indication code | ||
| #define I_HV_ERROR 2 // there is a problem with high voltage generation | ||
| #define I_CONN_ERROR 4 // there is a problem with the network connection | ||
|
|
||
| // indicate radiation and special indications via a color time sequence. | ||
| // you should call this in regular time intervals [e.g. 1s]. | ||
| void indicate(float radiation, unsigned int indication); | ||
|
|
||
| void setup_status_LED(void); |
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 |
|---|---|---|
|
|
@@ -31,3 +31,4 @@ lib_deps= | |
| IotWebConf | ||
| MCCI LoRaWAN LMIC library | ||
| h2zero/NimBLE-Arduino | ||
| NeoPixelBus@>=2.6.0,!=2.6.2,<3.0.0 | ||
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.