Skip to content

BMP file on SD-card

The BMP file on SD-card library saves the screen as a BMP file on the SD-card and loads a BMP file into the frame-buffer, ready to be displayed. Everything is performed dynamically at run-time.

Info

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

The BMP file on SD-card library is available on the Commercial edition. The file is RGB 5-5-5 coded.

Configure

Warning

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

#include "hV_File_BMP.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 properly configured.

File_BMP myFile(&myScreen);

The constructor File_BMP() 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
bool result = myFile.beginFileSystem(pinCS,
    portSPI,
    pinDetect,
    pinLevel);

if (result != RESULT_SUCCESS)
{
    hV_HAL_Serial_crlf();
    hV_HAL_log(LEVEL_CRITICAL, "SD-card error");
    hV_HAL_exit(0x01);
}

myFile.setFolder("Image");

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.

beginFileSystem() returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise.

Legacy version 5

beginFileSystem() returned a boolean value, now replaced by clear constants.

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.

Use

Save

1
2
myFile.saveScreen("File_BMP",
    1);

saveScreen() saves the screen on the SD-card as a BMP file. The file is RGB 5-5-5 coded.

The required parameter is

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

The optional parameter is

  • The second line sets the multiplier, 1 by default.

The default value of 1 is recommended for medium and large screens, and 2 for small screens.

saveWindow() save a window on a BMP file.

Read

1
2
myFile.readScreen("File_BMP",
    1);

readScreen() displays a BMP 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 .BMP extension.

The optional parameter is

  • The second line sets the multiplier, 1 by default.

The function doesn’t check 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_BMP.ino.

void fileWriteReadBMP()
{
    // Initialise
    bool 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 BMP");
    myScreen.flushFast();

    // Write to SD-card
    myFile.saveScreen("File_BMP");
    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_BMP");
    myScreen.flush();
}