BatteryBig
Overview
The BatteryBig widget is a custom container component for TouchGFX designed to display a visual battery level indicator. It provides a graphical representation of battery charge levels using colored segments that change based on the input level value.
Purpose
The primary purpose of the BatteryBig widget is to offer an intuitive, visual way to communicate battery status in embedded GUI applications. It supports four distinct battery states: empty, low, medium, and full, each represented by different color combinations.
Components
The widget consists of the following visual components:
Base Images (Gray): Three gray images (
gray1,gray2,gray3) that form the base outline of the batteryColored Overlays:
red1: Red segment for low battery indicationgreen1,green2,green3: Green segments for medium to full battery indication
All images are positioned to create a cohesive battery icon with dimensions of 66x28 pixels.
Functionality
The widget’s core functionality is controlled through the setBatteryLevel(uint8_t level) method, which accepts a battery level value from 0-255. The visibility of different image segments is toggled based on predefined thresholds:
Full Battery (level ≥
kThresholdHi): All three green segments visibleMedium Battery (level ≥
kThresholdLo): Green segments 1 and 2 visible, gray segment 3 visibleLow Battery (level > 0): Red segment 1 visible, gray segments 2 and 3 visible
Empty Battery (level = 0): All gray segments visible
The thresholds kThresholdHi and kThresholdLo are defined in Gui::Config::Battery and can be customized for different applications.
Usage in TouchGFX Designer
Import the Custom Container Package:
Open TouchGFX Designer
Go to
Custom Containers→ImportSelect the BatteryBig package file (manifest.xml)
Add to Screen:
Drag the BatteryBig custom container from the Custom Containers panel onto your screen
Position and resize as needed (recommended size: 66x28 pixels)
Configure Properties:
The widget has no configurable properties in Designer beyond standard container properties
Battery level is controlled programmatically
Usage in C++ Code
Include the Header:
#include <gui/containers/BatteryBig.hpp>
Declare in View: In your View class (e.g.,
MainView.hpp):BatteryBig batteryWidget;
Initialize in Constructor/Setup:
add(batteryWidget); batteryWidget.setPosition(x, y, 66, 28);
Update Battery Level:
batteryWidget.setBatteryLevel(currentBatteryLevel); // 0-255
Example Integration:
void MainView::updateBatteryDisplay(uint8_t level) { batteryWidget.setBatteryLevel(level); batteryWidget.invalidate(); // Force redraw if needed }
Files Included
manifest.xml: Package manifestcontent/CustomContainerExport.touchgfx: Designer export definitioncontent/CustomContainerManifest.xml: Container manifestcontent/texts.xml: Text database (empty for this widget)files/gui/include/gui/containers/BatteryBig.hpp: Header filefiles/gui/src/containers/BatteryBig.cpp: Implementation filefiles/assets/images/: 7 PNG image assets (gray1-3, red1, green1-3)
Dependencies
TouchGFX Framework (minimum version 4.26.0)
Gui::Config::Batteryconfiguration (for thresholds)