From d0ed30ecb6c069b059cdfa0e035431121dffba13 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 20 Nov 2022 21:16:38 +1100 Subject: [PATCH] Split display checksum out --- source/Core/Drivers/OLED.cpp | 1 + source/Core/Drivers/OLED.hpp | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp index 9210da51..af1ec479 100644 --- a/source/Core/Drivers/OLED.cpp +++ b/source/Core/Drivers/OLED.cpp @@ -372,6 +372,7 @@ void OLED::setRotation(bool leftHanded) { const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2); I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, len); osDelay(TICKS_10MS); + checkDisplayBufferChecksum(); } void OLED::setBrightness(uint8_t contrast) { diff --git a/source/Core/Drivers/OLED.hpp b/source/Core/Drivers/OLED.hpp index 9912c5df..e51b3c8a 100644 --- a/source/Core/Drivers/OLED.hpp +++ b/source/Core/Drivers/OLED.hpp @@ -51,13 +51,9 @@ public: static bool isInitDone(); // Draw the buffer out to the LCD if any content has changed. static void refresh() { - uint32_t hash = 0; - const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2); - for (int i = 0; i < len; i++) { - hash += (i * screenBuffer[i]); - } - if (hash != displayChecksum) { - displayChecksum = hash; + + if (checkDisplayBufferChecksum()) { + const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2); I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, len); // DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms // or we need to goto double buffering @@ -118,6 +114,17 @@ public: static void transitionScrollDown(); private: +static bool checkDisplayBufferChecksum(){ + uint32_t hash = 0; + const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2); + for (int i = 0; i < len; i++) { + hash += (i * screenBuffer[i]); + } + + bool result = hash!=displayChecksum; + displayChecksum= hash; + return result; +} static void drawChar(uint16_t charCode, FontStyle fontStyle); // Draw a character to the current cursor location static void setFramebuffer(uint8_t *buffer); static uint8_t *firstStripPtr; // Pointers to the strips to allow for buffer having extra content