Frame-buffer binary file on SD-card¶
The frame-buffer binary file on SD-card library saves the screen as a binary file on the SD-card and loads it back into the frame-buffer, ready to be displayed. Everything is performed dynamically at run-time. It is much faster than BMP, as it reads and writes the frame-buffer directly.
This option supports all the screens, monochrome and colour.
Info
This method is not recommended for MCUs, as the management of the SD-card is rather slow and prone to interferences.
The frame-buffer binary file on SD-card library library is available on the Commercial edition.
Configure¶
Warning
Ensure the screen is declared and initialised according to the configuration procedure.
#include "hV_File_Buffer.h"
The pre-processor statement includes the file library. It should be mentioned after the statement for the screen library.
Danger
This library requires the external SD library to manage the SD-card.
Ensure the external SD library is installed and configured properly.
File_Buffer myFile(&myScreen);
The constructor File_Buffer()
sets the link to the screen. It should be mentioned after the constructor of the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
beginFileSystem()
checks an SD-card is available and initialises it.
The required parameter is
- The first line sets the pin for selecting the SD-card.
It is easily provided with myScreen.getBoardPins().cardCS
.
The optional parameters are
-
The second line sets the number of the SPI port,
0
by default; -
The third line sets the pin for the detect signal,
NOT_CONNECTED
or-1
par default; -
The fourth line sets the level of detect signal,
LOW
by default.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
To obtain the pin for selecting the SD-card, use
uint8_t pinCardCS = myScreen.getBoardPins().cardCS;
uint8_t result = myFile.beginFileSystem(pinCardCS);
setFolder()
sets the name of the folder for the files, and creates it if it does not exists.
By default, the files are located under the folder img
.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
Use¶
Save¶
uint8_t result = myFile.saveScreen("File_Buffer");
saveScreen()
saves the screen on the SD-card as a frame-buffer binary file.
The required parameter is
- The first line provides the name of the file without the
.FB
extension.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
Read¶
uint8_t result = myFile.readScreen("File_Buffer");
readScreen()
loads a binary file from the SD-card on the frame-buffer, to be displayed with flush()
.
The required parameter is
- The first line provides the name of the file without the
.FB
extension.
The function checks the size or the multiplier of the image.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
Terminate¶
uint8_t result = myFile.endFileSystem();
endFileSystem()
closes the SD-card.
The function returns RESULT_SUCCESS
if successful, RESULT_ERROR
otherwise.
Example¶
This is the core of the code from example File_Frame.ino
.
void fileWriteFrame()
{
// Initialise
uint8_t result;
result = myFile.beginFileSystem(5);
if (result != RESULT_SUCCESS)
{
hV_HAL_log(LEVEL_ERROR, "SD-card error");
hV_HAL_Serial_crlf();
return;
}
myScreen.setOrientation(myOrientation);
myScreen.selectFont(fontLarge);
myScreen.clear();
myScreen.gText(8, 8, "File Buffer");
myScreen.flushFast();
// Write to SD-card
result = myFile.saveScreen("File_PBM");
wait(4);
myScreen.clear();
myScreen.gText(4, 4, "Reading the file back...");
myScreen.flushFast();
wait(4);
// Read from SD-card
myScreen.clear();
result = myFile.readScreen("File_PBM");
if (result == RESULT_SUCCESS)
{
myScreen.flush();
wait(4);
}
}