Description
Sorry, I am trying to understand, how the code integration of these two classes is supposed to work.
Background, I am playing with an Image viewer sketch (BMP, PNG, JPEG), that I use as part of testing of different display libraries I work with... Including for the fun of it on the GIGA Display Shield. I was first using the Adafruit GFX which worked, but wondered about lower overhead version, so thought I would try this approach.
A version of it is up at: https://github.com/KurtE/Arduino_GIGA-stuff/tree/main/sketches/tft_picture_view_sd_giga_shield_24Bit
I am mainly trying to understand the expectations of calls to these two methods:
void Arduino_H7_Video::beginDraw() {
ArduinoGraphics::beginDraw();
dsi_lcdClear(0);
}
void Arduino_H7_Video::endDraw() {
ArduinoGraphics::endDraw();
dsi_drawCurrentFrameBuffer();
}
I understand:
If I call beginDraw() it sets the entire screen to black.
And if I call endDraw() - it sends the current frame buffer to display.
Now suppose at startup of the sketch I may want to write three lines of text on the screen as the sketch checks to see if
an SDCard or USB Drive are ready... This can take over several seconds, so how do I incrementally write the text to the screen?
Simpler sketch to demonstrate:
#include <elapsedMillis.h>
#include "Arduino_H7_Video.h"
#include "ArduinoGraphics.h"
REDIRECT_STDOUT_TO(Serial)
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
void fillScreen(uint8_t r, uint8_t g, uint8_t b, bool begin_end = true) {
if (begin_end) Display.beginDraw();
Display.background(r, g, b);
Display.clear();
if (begin_end) Display.endDraw();
}
//****************************************************************************
// Setup
//****************************************************************************
void setup(void) {
Serial.begin(115200);
while (!Serial && millis() < 3000)
Serial.println("*** start up display ***");
Display.begin();
//tft.setRotation(1);
fillScreen(0xff, 0, 0, true); // experiment going direct
//tft.fillScreen(RED);
delay(500);
fillScreen(0, 0xff, 0, true);
//tft.fillScreen(GREEN);
delay(500);
fillScreen(0, 0, 0xff, true);
//tft.fillScreen(BLUE);
delay(500);
Display.beginDraw();
fillScreen(0, 0, 0xff, false);
Display.textFont(Font_5x7);
//Display.textSize(5, 5);
Display.setTextSize(5);
Display.stroke(0xff, 0, 0);
Display.background(0, 0, 0xff);
Display.text("Waiting for SD or USB", 0, 0);
Display.endDraw();
delay(2000);
//Display.beginDraw();
Display.text("SD Started", 100, 100);
Display.endDraw();
delay(2000);
// Display.beginDraw();
Display.text("USB Started", 100, 200);
Display.endDraw();
delay(2000);
fillScreen(0xff, 0, 0, true);
Display.beginText(100, 300);
Display.print("Here is some Text");
Display.textScrollSpeed(100);
Display.endText(SCROLL_LEFT);
}
void loop() {
}
The first line comes out fine: Waiting for SD or USB
Now if it finds the SD and I display: SD Started
If first I call beginDraw
Only the new text is displayed and rest of the screen is black.
If I don't call beginDraw, the new text is the only text on screen, and the background is red.
Now if I then try to output the third line: USB Started
Again if I call beginDraw - it is the only thing on screen with background black.
If I don't call beginDraw: both the first line (Waiting...) and this line are displayed with Red bacground, but not 2nd line.
Pretty sure: double buffering (two buffers that alternate).
The last part of this test sketch tried the beginText, write, endText to see if an update to an enahancement to the ArduinoGraphics library to allow the font to be scaled works.
arduino-libraries/ArduinoGraphics#45
It appears to, however the code in endText for scrolling like the left that I tried:
if (scrollDirection == SCROLL_LEFT) {
int scrollLength = _textBuffer.length() * textFontWidth() + _textX;
for (int i = 0; i < scrollLength; i++) {
beginDraw();
int const text_x = _textX - i;
text(_textBuffer, text_x, _textY);
scaledBitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textsize_x, _textsize_y);
endDraw();
delay(_textScrollSpeed);
}
Appears like it maybe relies on screen being erased? Otherwise when the code draws it one pixel farther
to the left, it would leave a smear with the pixels that were on the right hand edge... Sort of like this
library assumes only one thing on it at a time.
So at a minimum I would think that if beginDraw is going to erase the screen it should do so to
the currently selected background color.
Sorry I hope this all makes sense.