New battery indicator

Announcements of new firmware versions, new features and new applications
Post Reply
mchavez
Site Admin
Posts: 43
Joined: Tue Nov 10, 2020 12:12 am

New battery indicator

Post by mchavez »

There a new way to show the battery level using images instead of text. To make a battery indicator there is two options:
  1. The first option is to use a set of images with the desired levels to display. First, you must upload the images as "assets" and then declare them:

    Code: Select all

    LV_IMG_DECLARE(lcars_bat_0);
    LV_IMG_DECLARE(lcars_bat_20);
    LV_IMG_DECLARE(lcars_bat_40);
    LV_IMG_DECLARE(lcars_bat_60);
    LV_IMG_DECLARE(lcars_bat_80);
    LV_IMG_DECLARE(lcars_bat_100);
    LV_IMG_DECLARE(lcars_bat_charge);
    
    Then, you must declare an array of the images, order by level (0 to 100) and one last image for the charging indicator

    Code: Select all

    const void* __images_bat[] = {&lcars_bat_0, &lcars_bat_20, &lcars_bat_40, &lcars_bat_60, &lcars_bat_80, &lcars_bat_100, &lcars_bat_charge};
    
    Finally, you must add the sprite indicating its alignment and its position on the watch.

    Code: Select all

    __clock.add_clock_sprite(TIME_RES_BATTERY, LV_COLOR_TRANSP, LV_ALIGN_IN_BOTTOM_RIGHT, __images_bat, ARRAY_SIZE(__images_bat), { -146, -28});
    
  2. The second option is to use the built-in font images named LV_SYMBOL_* and use them as images in the same way as before. In this case a color is needed for the text.

    Code: Select all

    const void* __images_bat[] = {LV_SYMBOL_BATTERY_EMPTY, LV_SYMBOL_BATTERY_1, LV_SYMBOL_BATTERY_2, LV_SYMBOL_BATTERY_3, LV_SYMBOL_BATTERY_FULL, LV_SYMBOL_CHARGE};
    __clock.add_clock_sprite(TIME_RES_BATTERY, LV_COLOR_WHITE, LV_ALIGN_IN_TOP_LEFT, __images_bat, ARRAY_SIZE(__images_bat), { 15, 15 });
    
With this code the firmware calculate the precise image to show the current battery level.

If you like to see some examples, please see the new versions of the "Hogwarts" and "Startrek" watches at the store.

We hope you like it.

The TWatchBuilder Team
Post Reply