Demo: Touch_GUI¶
Definitions¶
Creates a Screen object according to the EPD size and the EVK used
// Define variables and constants
Pervasive_Touch_Small myDriver(eScreen_EPD_370_KS_0C_Touch, boardRaspberryPiPico_RP2040);
//Pervasive_Touch_Small myDriver(eScreen_EPD_271_KS_09_Touch, boardRaspberryPiPico_RP2040);
Main Arduino Functions¶
Requires setting up the Screen library
setup() initializes a Screen object named myScreen and sets up the text and fonts
Also calls displayGUI()
// Add setup code
void setup()
{
// hV_HAL_Serial = Serial by default, otherwise edit hV_HAL_Peripherals.h
hV_HAL_begin(); // with Serial at 115200
hV_HAL_Serial_crlf();
hV_HAL_log(LEVEL_INFO, __FILE__);
hV_HAL_log(LEVEL_INFO, __DATE__ " " __TIME__);
hV_HAL_Serial_crlf();
// Screen
myScreen.begin();
myScreen.regenerate();
// Fonts
#if (FONT_MODE == USE_FONT_TERMINAL)
fontSmall = Font_Terminal6x8;
fontMedium = Font_Terminal8x12;
fontLarge = Font_Terminal12x16;
fontVery = Font_Terminal16x24;
#else // FONT_MODE
fontSmall = myScreen.addFont(Font_DejaVuSans12);
fontSmall -= ((fontSmall > 0) ? 1 : 0);
fontMedium = myScreen.addFont(Font_DejaVuSans16);
fontMedium -= ((fontMedium > 0) ? 1 : 0);
fontLarge = myScreen.addFont(Font_DejaVuSans24);
fontLarge -= ((fontLarge > 0) ? 1 : 0);
fontVery = myScreen.addFont(Font_DejaVuMono48);
fontVery -= ((fontVery > 0) ? 1 : 0);
#endif // FONT_MODE
// Example
#if (DISPLAY_GUI == 1)
hV_HAL_log(LEVEL_INFO, "DISPLAY_GUI");
myScreen.clear();
displayGUI();
wait(8);
#endif // DISPLAY_GUI
hV_HAL_log(LEVEL_INFO, "Regenerate");
myScreen.regenerate();
hV_HAL_exit(0);
}
///
/// @brief Loop, empty
///
void loop()
{
hV_HAL_delayMilliseconds(1000);
}
Utilities¶
displayGUI()¶
This sets up the GUI display, including the elements, fonts, orientation, and program behavior. Among the elements, it includes buttons and text.
This is also where the Touch functionality is called.
if (DISPLAY_GUI == 1)
GUI myGUI(&myScreen);
void displayGUI()
{
myScreen.setOrientation(ORIENTATION_LANDSCAPE);
myScreen.selectFont(fontMedium);
myScreen.clear();
myGUI.begin();
Button myButtonNormal(&myGUI);
Button myButtonInstant(&myGUI);
Text myText(&myGUI);
uint16_t x = myScreen.screenSizeX();
uint16_t y = myScreen.screenSizeY();
uint16_t dx = x / 7;
uint16_t dy = y / 5;
myGUI.delegate(false);
myButtonNormal.dStringDefine(dx * 1, dy * 3, dx * 2, dy, "Normal", fontMedium);
myButtonInstant.dStringDefine(dx * 4, dy * 3, dx * 2, dy, "Instant", fontMedium);
myText.dDefine(0, dy, x, dy, fontMedium);
myButtonNormal.draw();
myButtonInstant.draw();
myText.draw("Empty");
myScreen.flush();
myGUI.delegate(true);
uint8_t k = 8;
uint32_t chrono32;
while (k > 0)
{
if (myScreen.getTouchInterrupt())
{
chrono32 = hV_HAL_getMilliseconds();
if (myButtonNormal.check(checkNormal))
{
k -= 1;
chrono32 = hV_HAL_getMilliseconds() - chrono32;
myText.draw(formatString("%s in %i ms (%i left)", "Normal", chrono32, k));
hV_HAL_log(LEVEL_INFO, "%3i: %s in %i ms", k, "Normal", chrono32);
}
chrono32 = hV_HAL_getMilliseconds();
if (myButtonInstant.check(checkInstant))
{
k -= 1;
chrono32 = hV_HAL_getMilliseconds() - chrono32;
myText.draw(formatString("%s in %i ms (%i left)", "Instant", chrono32, k));
hV_HAL_log(LEVEL_INFO, "%3i: %s in %i ms", k, "Instant", chrono32);
}
} // getTouchInterrupt
hV_HAL_delayMilliseconds(100);
}
myScreen.clear();
}
#endif // DISPLAY_GUI
wait()¶
Delay function with Serial output
void wait(uint8_t second)
{
for (uint8_t i = second; i > 0; i--)
{
mySerial.print(formatString(" > %i \r", i));
hV_HAL_delayMilliseconds(1000);
}
mySerial.print(" \r");
}