Skip to content

16-bit image header file on serial console

The 16-bit image header file on serial console library prints the screen as a header file on the serial console.

The header file is added to the source code and included in the project of the application statically at build-time. Once the application is built, it loads the image into the frame-buffer, ready to be displayed dynamically at run-time.

This option supports all the screens, monochrome and colour.

Info

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

The image on serial console library is available on the Evaluation and Commercial editions.

Configure

Warning

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

#include "hV_Serial_Image16.h"

The pre-processor statement includes the serial library. It should be mentioned after the statement for the screen library.

No external SD library is required, as the header file is sent to the serial console.

Serial_Image16 myFile(&myScreen);

The constructor Serial_Image16() sets the link to the screen. It should be mentioned after the constructor of the screen.

As the header file is printed on the serial console, the SD-card doesn’t need to be initialised.

Use

Generate

myFile.saveScreen("Image16");

saveScreen() prints the screen as a header file on the serial console.

The required parameter is

  • The first line provides the name of the file without the .h extension.
1
2
myFile.saveWindow("Image16",
    40, 71, 100, 50) // x y dx dy

The function returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise.

saveWindow() save a window on a header file on the SD-card as an image.

The required parameters are

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

  • The second line defines the window with vector coordinates.

The coordinates are rounded as multiple of 8.

For example, the vector coordinates (70, 44, 155, 64) are changed to (70, 40, 155, 72).

The printed header file contains the structure Image_MyHeader.

Capture the content of the serial console and copy it into a header file, for example HEAD_IMA.h.

The function returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise.

Display

#include "Image16.h"

uint8_t result;
result = myFile.readScreen(Image16_Image16);
if (result == RESULT_SUCCESS)
{
    myScreen.flush();
    wait(4);
}

The application needs to include the header file previously generated.

readScreen() loads the image into the frame-buffer, ready to be displayed.

The function returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise.

Example

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

void displayPrintSerial()
{
    // No SD-card
    uint8_t result;

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

    myScreen.clear();
    myScreen.gText(8, 8, "Header Image16");
    myScreen.flushFast();

    // Print to serial console
    result = mySerialImage.saveScreen("Image16");
    wait(4);
}

The generated header file contains the image as a structure.

// Image as header file generated by hV_Serial_Image16

// SDK
#include "hV_HAL_Peripherals.h"

// Release
#ifndef SERIAL_IMAGE16_RELEASE
#define SERIAL_IMAGE16_RELEASE

#include "hV_Image16.h"

static const uint16_t Table_Image16[] =
{
    0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, 0xffe0, // v= 152
    // ...
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // v= 1
};

const image16_s Image16_Image16 =
{
    .minWindowH = 0,
    .minWindowV = 0,
    .maxWindowH = 151,
    .maxWindowV = 151,
    .depth = 2,
    .size = 23104,
    .table = Table_Image16
};

#endif // SERIAL_IMAGE16_RELEASE

The window uses rectangular coordinates.

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

#include "Image16.h"

void displayReadHeader()
{
    uint8_t result;

    myScreen.setOrientation(myOrientation);
    myScreen.clear();

    myScreen.selectFont(fontLarge);
    myScreen.gText(4, 4, "Reading the header back...");
    myScreen.flushFast();
    wait(4);

    result = myHeader.readScreen(Image16_Image16);
    if (result == RESULT_SUCCESS)
    {
        myScreen.flush();
        wait(4);
    }
}