Skip to content

Commit

Permalink
DispInterface: Refactor displayEnabled handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shezik committed Jul 16, 2023
1 parent 4efa55e commit 6900d8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/DispInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,18 @@ void DispInterface::drawSegments(segment_bitmap_t *ds, bool lowBat) {
u8g2.drawXBM(0, 0, asterisk_width, asterisk_height, asterisk_bits);
}

// Also kicks display out of power save mode
void DispInterface::updateDisplay(nut_reg_t *nv, bool force) {
static segment_bitmap_t lastSegments[VOYAGER_DISPLAY_DIGITS] = {0};
bool lowBat = lowBatAnnOverride || blinkTick();
static bool lastLowBat = false;
bool doUpdate = (lastLowBat != lowBat) ? true : memcmp(lastSegments, nv->display_segments, sizeof(lastSegments));
static bool lastLowBat = !lowBat;
bool displayEnabled = nv->display_chip->enable;
static bool lastDisplayEnabled = !displayEnabled;
bool doUpdate = (lastLowBat != lowBat) || (lastDisplayEnabled != displayEnabled) || memcmp(lastSegments, nv->display_segments, sizeof(lastSegments));
memcpy(lastSegments, nv->display_segments, sizeof(lastSegments));

if (doUpdate || force) {
lastLowBat = lowBat;
lastDisplayEnabled = displayEnabled;
drawSegments(nv->display_segments, lowBat);
u8g2.sendBuffer();
}
Expand Down
9 changes: 1 addition & 8 deletions src/NutEmuInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,7 @@ char *NutEmuInterface::getRomFilePath() {

void NutEmuInterface::updateDisplayCallback() {
displayEnabled = nv->display_chip->enable; // The value is the most reliable FOR NOW
static bool lastState = !displayEnabled;

if (displayEnabled) {
disp.updateDisplay(nv, !lastState);
} else if (/*!unlockSpeed && */lastState) // For the sake of accuracy
disp.getU8g2()->clear(); // !! What about the low bat annunciator?

lastState = displayEnabled;
disp.updateDisplay(nv);
}

void NutEmuInterface::setEnablePowerMgmt(bool enablePowerMgmt_) {
Expand Down

0 comments on commit 6900d8a

Please sign in to comment.