Hi there, i am trying to figure out the way how i would use a paper display module and buttons at the same time. I have to say that i am fairly new to C and ESP/Arduinos at all, so please dont be too harsh
the issue i am having is, that i do not quite understand the logic of "parallel" or non blocking things at the same time (i dont have the correct wording here...). I have a main thread which looks like this (as well as some other logic, but this is i guess the important stuff):
void setup(void)
{
//...
// Initialize graphic library
initializeDisplay();
// Draw splash screen
drawSplashScreen();
//...
}
void loop(void)
{
drawScreen(state.currentScreen);
checkButtons();
}
initializing the display looks like this:
void initializeDisplay()
{
display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
initDisplayRotation();
}
then i have a function wich basically gets called every loop. (i used to use a non-ePaper display before, there it worked just fine)
void updateText(const String &text, int16_t x, int16_t y)
{
int16_t tbx, tby;
uint16_t tbw, tbh;
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
display.getTextBounds(text.c_str(), 0, 0, &tbx, &tby, &tbw, &tbh);
display.setPartialWindow(x, y - tbh, tbw, tbh * 2);
display.firstPage();
do
{
display.fillRect(x, y - tbh, tbw, tbh * 2, GxEPD_WHITE);
display.setCursor(x, y);
display.print(text);
} while (display.nextPage());
}
void drawOdometerLayout()
{
String partial = String(memory.config.tripPartial);
String total = String(memory.config.tripTotal);
String heading = String(state.currentHeading);
if (memory.config.precision == 1)
{
// Remove last digit
partial.remove(partial.length() - 1);
total.remove(total.length() - 1);
}
// Calculate positions and bounding boxes
int16_t tbx, tby;
uint16_t tbw, tbh;
// Set up the display
display.setFullWindow();
display.firstPage();
// Clear the display
display.fillScreen(GxEPD_WHITE);
// Draw status bar
drawStatusBar();
// Draw title (total distance)
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
display.getTextBounds(total.c_str(), 0, 0, &tbx, &tby, &tbw, &tbh);
int16_t title_x = (display.width() - tbw) / 2;
display.setCursor(title_x, 28);
display.print(total);
// Draw heading
display.getTextBounds(heading.c_str(), 0, 0, &tbx, &tby, &tbw, &tbh);
int16_t heading_x = display.width() - tbw - 5;
display.setCursor(heading_x, 28);
display.print(heading);
display.drawCircle(display.width() - 20, 12, 3, GxEPD_BLACK);
// Draw partial distance
display.getTextBounds(partial.c_str(), 0, 0, &tbx, &tby, &tbw, &tbh);
int16_t partial_x = (display.width() - tbw) / 2;
display.setCursor(partial_x, 63);
display.print(partial);
// Perform partial update on the relevant text areas only
updateText(partial, partial_x, 63);
updateText(total, title_x, 28);
updateText(heading, heading_x, 28);
}
fot the buttons i use PushButton library:
here is the issue now where i dont know what the correct way is to fix it:
i assume the while ... do loop prevents the main loop to function properly and blocks the whole thing. so whenever i press a button, it only recognizes the press when i accidently hit one loop cycle and the buttons get read.
what is the way to go here and how would i update my code to have responsive buttons and a responsive (as much as possible with epaper) display?
And as a second question:
looking at this first attempt of drawing something to the epaper display, what would be the strategy to make it draw faster? Currently it feels like it needs a second or so to to each of these function calls: updateText(partial, partial_x, 63);
Any Help would be great!
thanks a lot!