Skip to content

Commit 964cf5e

Browse files
committed
G/S/C Unicorn: Fix get_brightness to use correct max value.
Add a comment noting that 256 is the correct maximum brightness.
1 parent 6eb0f90 commit 964cf5e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

libraries/cosmic_unicorn/cosmic_unicorn.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,14 @@ namespace pimoroni {
494494
void CosmicUnicorn::set_brightness(float value) {
495495
value = value < 0.0f ? 0.0f : value;
496496
value = value > 1.0f ? 1.0f : value;
497+
// Max brightness is - in fact - 256 since it's applied with:
498+
// result = (channel * brightness) >> 8
499+
// eg: (255 * 256) >> 8 == 255
497500
this->brightness = floor(value * 256.0f);
498501
}
499502

500503
float CosmicUnicorn::get_brightness() {
501-
return this->brightness / 255.0f;
504+
return this->brightness / 256.0f;
502505
}
503506

504507
void CosmicUnicorn::adjust_brightness(float delta) {

libraries/galactic_unicorn/galactic_unicorn.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,14 @@ namespace pimoroni {
488488
void GalacticUnicorn::set_brightness(float value) {
489489
value = value < 0.0f ? 0.0f : value;
490490
value = value > 1.0f ? 1.0f : value;
491+
// Max brightness is - in fact - 256 since it's applied with:
492+
// result = (channel * brightness) >> 8
493+
// eg: (255 * 256) >> 8 == 255
491494
this->brightness = floor(value * 256.0f);
492495
}
493496

494497
float GalacticUnicorn::get_brightness() {
495-
return this->brightness / 255.0f;
498+
return this->brightness / 256.0f;
496499
}
497500

498501
void GalacticUnicorn::adjust_brightness(float delta) {

libraries/stellar_unicorn/stellar_unicorn.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,14 @@ namespace pimoroni {
485485
void StellarUnicorn::set_brightness(float value) {
486486
value = value < 0.0f ? 0.0f : value;
487487
value = value > 1.0f ? 1.0f : value;
488+
// Max brightness is - in fact - 256 since it's applied with:
489+
// result = (channel * brightness) >> 8
490+
// eg: (255 * 256) >> 8 == 255
488491
this->brightness = floor(value * 256.0f);
489492
}
490493

491494
float StellarUnicorn::get_brightness() {
492-
return this->brightness / 255.0f;
495+
return this->brightness / 256.0f;
493496
}
494497

495498
void StellarUnicorn::adjust_brightness(float delta) {

0 commit comments

Comments
 (0)