Skip to content

Commit 431228c

Browse files
committed
LEDOutput cleanup
1 parent 4a43391 commit 431228c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/AudioLibs/LEDOutput.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,33 @@ LEDOutput *selfLEDOutput=nullptr;
1010
// default callback function which implements led update
1111
void updateLEDOutput(LEDOutputConfig*cfg, LEDOutput *matrix, int max_y);
1212
// default color
13-
CHSV get_color(int x, int y, int magnitude){
14-
return CHSV( 224, 187, 255);
13+
CHSV getColor(int x, int y, int magnitude){
14+
return CHSV( 224, 187, 100);
1515
}
1616

1717
/**
1818
* LED Matrix Configuration. Provide the number of leds in x and y direction and
1919
* the data pin.
20+
* @author Phil Schatzmann
2021
*/
2122
struct LEDOutputConfig {
2223
/// Number of leds in x direction
2324
int x = 0;
2425
/// Number of leds in y direction
2526
int y = 0;
26-
/// optinal custom logic to select color
27-
CHSV (*get_color)(int x, int y, int magnitude) = get_color;
27+
/// optinal custom logic to provide CHSV color: Prividing a 'rainbow' color with hue 0-255, saturating 0-255, and brightness (value) 0-255 (v2)
28+
CHSV (*color_callback)(int x, int y, int magnitude) = getColor;
2829
/// Custom callback logic to update the LEDs - by default we use updateLEDOutput()
29-
void (*update)(LEDOutputConfig*cfg, LEDOutput *matrix, int max_y) = updateLEDOutput;
30+
void (*update_callback)(LEDOutputConfig*cfg, LEDOutput *matrix, int max_y) = updateLEDOutput;
3031
/// Update the leds only ever nth call
3132
int update_frequency = 1; // update every call
3233
};
3334

3435
/**
3536
* LEDOutput using the FastLED library. You write the data to the FFT Stream.
3637
* This displays the result of the FFT to a LED matrix.
38+
* @ingroup io
39+
* @author Phil Schatzmann
3740
*/
3841
class LEDOutput {
3942
public:
@@ -75,14 +78,13 @@ class LEDOutput {
7578
return true;
7679
}
7780

78-
// Provides the number of LEDs: call begin() first!
81+
/// Provides the number of LEDs: call begin() first!
7982
int ledCount(){
8083
int num_leds = cfg.x * cfg.y;
8184
return num_leds;
8285
}
8386

84-
/// @brief Provides the address fo the CRGB array: call begin() first!
85-
/// @return
87+
/// Provides the address fo the CRGB array: call begin() first!
8688
CRGB* ledData() {
8789
if (ledCount() == 0) {
8890
LOGE("x or y == 0");
@@ -94,9 +96,9 @@ class LEDOutput {
9496

9597
/// Updates the display: call this method in your loop
9698
virtual void update() {
97-
if (count++ % cfg.update_frequency == 0) {
99+
if (cfg.update_callback!=nullptr && count++ % cfg.update_frequency == 0) {
98100
// use custom update logic defined in config
99-
cfg.update(&cfg, this, max_y);
101+
cfg.update_callback(&cfg, this, max_y);
100102
}
101103
}
102104

@@ -163,7 +165,7 @@ void updateLEDOutput(LEDOutputConfig*cfg, LEDOutput *matrix, int max_y){
163165
// update horizontal bar
164166
for (int y = 0; y < maxY; y++) {
165167
// determine color
166-
CHSV color = cfg->get_color(x, y, maxY);
168+
CHSV color = cfg->color_callback(x, y, maxY);
167169
// update LED
168170
matrix->xyLed(x, y) = color;
169171
}

0 commit comments

Comments
 (0)