Skip to content

Pixmap file on SD-card

The portable pixmap file on SD-card library saves the screen as a portable pixmap file on the SD-card and loads a portable pixmap file into the frame-buffer, ready to be displayed. Everything is performed at run-time. It is much faster than BMP, as it reads and writes the frame-buffer directly.

Tip

This method is not recommended for MCUs, as the management of the SD-card is rather slow and prone to interferences.

The portable pixmap file on SD-card library is available on the Commercial edition. The file is PBM coded.

Configure

Warning

Ensure the screen is declared and initialised according to the configuration procedure.

#include "hV_File_P4.h"

The pre-processor statement includes the file library.

Danger

This library requires the external SD library to manage the SD-card.

Ensure the external SD library is installed and properly configured.

File_P4 myFile(&myScreen);

The constructor File_P4() sets the link to the screen.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
bool result = myFile.beginFileSystem(pinCS,
    portSPI,
    pinDetect,
    pinLevel);

if (result == false)
{
    hV_HAL_printf("=== SD-card error");
    hV_HAL_crlf();
}

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.

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.

beginFileSystem() returns TRUE is successful.

Use

Save

myFile.saveScreen("File_P4");

saveScreen() saves the screen on the SD-card as a portable pixmap file. The file is PBM coded.

The required parameter is

  • The first line provides the name of the file without the .P4 extension.

Read

myFile.readScreen("File_P4");

readScreen() displays a portable pixmap 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 .P4 extension.

The function checks the size or the multiplier of the image.

End

myFile.endFileSystem();

endFileSystem() closes the SD-card.

Example

This is the core of the code from example File_P4.ino.

void fileWriteReadP4()
{
    // Initialise
    bool result = myFile.beginFileSystem(5);
    if (result == false)
    {
        hV_HAL_printf("=== SD-card error");
        hV_HAL_crlf();
        return;
    }

    myScreen.setOrientation(myOrientation);
    myScreen.selectFont(fontLarge);

    myScreen.clear();
    myScreen.gText(8, 8, "File P4");
    myScreen.flushFast();

    // Write to SD-card
    myFileP4.saveScreen("File_P4");
    wait(4);

    myScreen.clear();
    myScreen.gText(4, 4, "Reading the file back...");
    myScreen.flush();
    wait(4);

    // Read from SD-card
    myScreen.clear();
    myFile.readScreen("File_P4");
    myScreen.flush();
}