Skip to content

Commit

Permalink
Supports screen brightness adjustment 0~100%
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyu-Zhao committed Jul 27, 2022
1 parent cd957ce commit 78d2a99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
35 changes: 16 additions & 19 deletions src/AXP192.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,23 @@ void AXP192::ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff) {
}
}

void AXP192::ScreenBreath(uint8_t brightness) {
if (brightness > 12) {
brightness = 12;
} else if (brightness < 7) {
brightness = 7;
}
void AXP192::ScreenBreath(int brightness) {
if (brightness > 100 || brightness < 0) return;
int vol = map(brightness, 0, 100, 2500, 3200);
// Serial.printf("brightness:%d\n", brightness);
// Serial.printf("vol:%d\n", vol);
vol = (vol < 1800) ? 0 : (vol - 1800) / 100;
// Serial.printf("vol:%d\n", vol);

// Serial.printf("vol:%x\n\n", (uint16_t)vol);
uint8_t buf = Read8bit(0x28);
// uint8_t buf = (uint8_t)11;
Serial.printf("brightness:%hhu\n", brightness);
Serial.printf("brightness:%d\n", brightness);
Serial.printf("brightness:%x\n", brightness);

Serial.printf("buf:%hhu\n", buf);
Serial.printf("buf:%d\n", buf);
Serial.printf("buf:%x\n", buf);

Serial.printf("result:%hhu\n", ((buf & 0x0f) | (brightness << 4)));
Serial.printf("result:%d\n", ((buf & 0x0f) | (brightness << 4)));
Serial.printf("result:%x\n", ((buf & 0x0f) | (brightness << 4)));
Write1Byte(0x28, ((buf & 0x0f) | (brightness << 4)));

// Serial.printf("buf:%hhu\n", buf);
// Serial.printf("buf:%d\n", buf);
// Serial.printf("buf:%x\n", buf);

// Serial.printf("result:%x\n---\n", ((buf & 0x0f) | ((uint16_t)vol << 4)));
Write1Byte(0x28, ((buf & 0x0f) | ((uint16_t)vol << 4)));
}

void AXP192::ScreenSwitch(bool state) {
Expand Down
2 changes: 1 addition & 1 deletion src/AXP192.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AXP192 {
void begin(bool disableLDO2 = false, bool disableLDO3 = false,
bool disableRTC = false, bool disableDCDC1 = false,
bool disableDCDC3 = false, bool disableLDO0 = false);
void ScreenBreath(uint8_t brightness);
void ScreenBreath(int brightness);
void ScreenSwitch(bool state);
bool GetBatState();

Expand Down

0 comments on commit 78d2a99

Please sign in to comment.