Skip to content

Commit

Permalink
Make brightness range consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
sebromero committed Jun 12, 2024
1 parent ebc4a53 commit ff2dd5c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/OrangeLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ OrangeLED::OrangeLED(uint8_t deviceAddress) : I2CDevice(deviceAddress) {}
uint8_t OrangeLED::brightness() {
// Read bits 0 - 5 from orange_led register
uint8_t data = readFromRegister<uint8_t>(ORANGE_LED_REGISTER_INFO);
return data & 63;
uint8_t brightness = data & 63;
return map(brightness, 0, 63, 0, 255);
}

void OrangeLED::setBrightness(uint8_t brightness) {
if (brightness > 63) {
if (brightness > 255) {
return; // Invalid brightness value
}

uint8_t mappedBrightness = map(brightness, 0, 255, 0, 63);
uint8_t currentRegisterData = readFromRegister<uint8_t>(ORANGE_LED_REGISTER_INFO);
// Overwrite bits 0 - 5 with the new value
writeToRegister<uint8_t>(ORANGE_LED_REGISTER_INFO, (currentRegisterData & ~63) | brightness);
writeToRegister<uint8_t>(ORANGE_LED_REGISTER_INFO, (currentRegisterData & ~63) | mappedBrightness);
}

bool OrangeLED::errorStatusEnabled() {
Expand Down
2 changes: 1 addition & 1 deletion src/OrangeLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OrangeLED : public I2CDevice {

/**
* Gets the brightness of the orange LED.
* @return The brightness of the orange LED. Range is 0 to 63.
* @return The brightness of the orange LED. Range is 0 to 255.
*/
uint8_t brightness();

Expand Down

0 comments on commit ff2dd5c

Please sign in to comment.