Hello again!
I posted about this problem in the programming topic area, but I feel my technical ability is just not good enough implement their advice specifically regarding the GxEPD2 library, I think the answer will have to come from people who have a more deep understanding of GxEPD2.
I have written a very stripped down version of my program that isolates my issue very nicely.
I have copied the code from my .ino file, .cpp file, and .h files below.
My goal is to move the function named page1Update() from the .ino file to the .cpp file.
In the copied .ino file code below the function is still there, but commented out. It is not commented out in the.cpp file. So if you copy all my code and compile, it should throw for you the same errors I'm seeing.
That error in question is...
In function 'void page1Update()': methods.cpp:10:3: error: 'display' was not declared in this scope
display.setPartialWindow(165, 15, 80, 20);
methods.cpp:13:24: error: 'GxEPD_WHITE' was not declared in this scope
display.fillScreen(GxEPD_WHITE);
methods.cpp:14:39: error: 'GxEPD_BLACK' was not declared in this scope
display.drawRect(165, 15, 80, 20, GxEPD_BLACK);
In my other post someone responded saying that
" You can add an extern declaration to let the .cpp file know that display exists and that it can find it later during linking.
Add this to the .cpp file
extern GxEPD2_BW<GxEPD2_213_B74, MAX_HEIGHT(GxEPD2_213_B74)> display; "
However when I added that line to my .cpp file it threw all kinds of errors about it. Clearly it's not written correctly to work for GxEPD2. I believe something needs to be added in order to declare the objects/functions/variables of GxEPD2 within my .cpp file, but I do not know or have the expertise to create that content.
So I'm hoping that either @ZinggJM or someone else can tell me very specifically what that code is to make this page1Update() work within the .cpp file without throwing these errors.
I have looked closely through the GxEPD2 library .cpp files and .h files and I can not seem to understand or find something that appears to be a copy/paste solution for me at my level of understanding.
Thankyou all again in advance. It is such a blessing to have this forum resource!
the .ino code...
//filename backstep2_code.ino
#include <Adafruit_GFX.h> // Core graphics library
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include "methods.h"
#if defined(__AVR)
#define MAX_DISPLAY_BUFFER_SIZE 800
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
GxEPD2_BW<GxEPD2_213_B74, MAX_HEIGHT(GxEPD2_213_B74)> display(GxEPD2_213_B74(/*CS=*/ 9, /*DC=*/ 10, /*RST=8*/ -1, /*BUSY=7*/7)); // GDEM0213B74 122x250, SSD1680
#endif
//int timeRemain;
void setup() {
display.init(); // disable diagnostics to avoid delay and catch most rotary pulses
//Serial.begin(9600);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b);
display.setRotation(3);
display.setFullWindow();
display.firstPage();//This sets up the screen for the non-changing/updating graphics
do {
display.fillScreen(GxEPD_WHITE);
display.setCursor(20, 30);
display.println("Next vote in ");
} while (display.nextPage());
}//END SETUP----------------------------------------------------------------------------------------------
void loop() {
eventSlotTiming();
timeRemain = (vTime - millis()) / 1000; //as millis increases, this takes the difference between millis and vTime and converts it to seconds
page1Update();
}//END LOOP-----------------------------------------------------------------------------------------------
/*
void page1Update() {
display.setPartialWindow(165, 15, 80, 20);
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.drawRect(165, 15, 80, 20, GxEPD_BLACK);
display.setCursor(175, 30);
display.print(timeRemain);
display.setCursor (200, 30);
display.print("sec");
} while (display.nextPage());
}//END page1Update---------------------------------------------------------------------------------------
*/
the .cpp code...
//filename method.cpp
#include "arduino.h"
#include "methods.h"
#include <Adafruit_GFX.h> // Core graphics library
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
long vTime = 60000;//vTime starts at a value of 1 minute in milliseconds
void page1Update() {
int timeRemain;
display.setPartialWindow(165, 15, 80, 20);
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.drawRect(165, 15, 80, 20, GxEPD_BLACK);
display.setCursor(175, 30);
display.print(timeRemain);
display.setCursor (200, 30);
display.print("sec");
} while (display.nextPage());
}//END page1Update---------------------------------------------------------------------------------------
void eventSlotTiming() {
if (millis() >= vTime) {
vTime = millis() + 60000;//Every minute, this resets vTime variable to one minute into the future
}
}//END eventSlotTiming------------------------------------------------------------------------------------
the .h code...
//filename method.h
#ifndef methods_h
#define methods_h
#include "arduino.h"
extern long vTime;
extern int timeRemain;
void page1Update();
void eventSlotTiming();
#endif