Skip to content

Commit d0ed30e

Browse files
committed
Split display checksum out
1 parent bbb0cfe commit d0ed30e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

source/Core/Drivers/OLED.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ void OLED::setRotation(bool leftHanded) {
372372
const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2);
373373
I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, len);
374374
osDelay(TICKS_10MS);
375+
checkDisplayBufferChecksum();
375376
}
376377

377378
void OLED::setBrightness(uint8_t contrast) {

source/Core/Drivers/OLED.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ class OLED {
5151
static bool isInitDone();
5252
// Draw the buffer out to the LCD if any content has changed.
5353
static void refresh() {
54-
uint32_t hash = 0;
55-
const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2);
56-
for (int i = 0; i < len; i++) {
57-
hash += (i * screenBuffer[i]);
58-
}
59-
if (hash != displayChecksum) {
60-
displayChecksum = hash;
54+
55+
if (checkDisplayBufferChecksum()) {
56+
const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2);
6157
I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, len);
6258
// DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
6359
// or we need to goto double buffering
@@ -118,6 +114,17 @@ class OLED {
118114
static void transitionScrollDown();
119115

120116
private:
117+
static bool checkDisplayBufferChecksum(){
118+
uint32_t hash = 0;
119+
const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2);
120+
for (int i = 0; i < len; i++) {
121+
hash += (i * screenBuffer[i]);
122+
}
123+
124+
bool result = hash!=displayChecksum;
125+
displayChecksum= hash;
126+
return result;
127+
}
121128
static void drawChar(uint16_t charCode, FontStyle fontStyle); // Draw a character to the current cursor location
122129
static void setFramebuffer(uint8_t *buffer);
123130
static uint8_t *firstStripPtr; // Pointers to the strips to allow for buffer having extra content

0 commit comments

Comments
 (0)