Skip to content

Commit ff2dd5c

Browse files
committed
Make brightness range consistent
1 parent ebc4a53 commit ff2dd5c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/OrangeLED.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ OrangeLED::OrangeLED(uint8_t deviceAddress) : I2CDevice(deviceAddress) {}
77
uint8_t OrangeLED::brightness() {
88
// Read bits 0 - 5 from orange_led register
99
uint8_t data = readFromRegister<uint8_t>(ORANGE_LED_REGISTER_INFO);
10-
return data & 63;
10+
uint8_t brightness = data & 63;
11+
return map(brightness, 0, 63, 0, 255);
1112
}
1213

1314
void OrangeLED::setBrightness(uint8_t brightness) {
14-
if (brightness > 63) {
15+
if (brightness > 255) {
1516
return; // Invalid brightness value
1617
}
1718

19+
uint8_t mappedBrightness = map(brightness, 0, 255, 0, 63);
1820
uint8_t currentRegisterData = readFromRegister<uint8_t>(ORANGE_LED_REGISTER_INFO);
1921
// Overwrite bits 0 - 5 with the new value
20-
writeToRegister<uint8_t>(ORANGE_LED_REGISTER_INFO, (currentRegisterData & ~63) | brightness);
22+
writeToRegister<uint8_t>(ORANGE_LED_REGISTER_INFO, (currentRegisterData & ~63) | mappedBrightness);
2123
}
2224

2325
bool OrangeLED::errorStatusEnabled() {

src/OrangeLED.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class OrangeLED : public I2CDevice {
2626

2727
/**
2828
* Gets the brightness of the orange LED.
29-
* @return The brightness of the orange LED. Range is 0 to 63.
29+
* @return The brightness of the orange LED. Range is 0 to 255.
3030
*/
3131
uint8_t brightness();
3232

0 commit comments

Comments
 (0)