TrackFace2ο
Overviewο
The TrackFace2 widget is a custom container component for TouchGFX designed to display lap-specific fitness tracking data in a watch-face style layout. It presents heart rate with a visual indicator bar, lap pace, lap distance, and lap elapsed time in a vertically stacked arrangement with clear labels and separators, optimized for wearable device interfaces during interval training or lap-based activities.
Purposeο
The primary purpose of the TrackFace2 widget is to provide a comprehensive, at-a-glance view of lap-based activity metrics in embedded fitness applications. It displays heart rate with threshold-based visual feedback, lap pace (time per unit distance), lap distance traveled, and lap elapsed time, with support for both metric and imperial units, making it ideal for sports watches, fitness trackers, and interval training screens.
Componentsο
The widget consists of the following visual components arranged in a layout optimized for wearable displays:
Heart Rate Section (top):
hrText: Label displaying βHRβhrValue: Numeric heart rate value in BPMhrBar: Visual heart rate indicator with 5 heart icons (HR_1.png to HR_5.png) based on thresholds
Lap Pace Section:
lapPaceText: Label displaying βLap PaceβlapPaceValue: Displays lap pace in MM:SS format (minutes:seconds per unit)
Lap Distance Section:
lapDistText: Label displaying βLap Dist.βlapDistValue: Numeric lap distance valuelapDistUnits: Unit indicator (βkmβ or βmi.β)
Lap Timer Section (bottom):
timerText: Label displaying βLap TimeβtimerValue: Lap elapsed time in H:MM:SS or MM:SS format
Separators:
Horizontal lines between sections for visual organization
All text elements use Poppins fonts in various weights and sizes for optimal readability on small screens.
Functionalityο
The widgetβs core functionality centers on data display, unit management, and threshold-based heart rate visualization:
Heart Rate Display: Accepts heart rate value and four threshold values to determine which of 5 heart icons to display (very low to very high intensity zones)
Lap Pace Display: Accepts lap pace as seconds per kilometer, automatically converts to MM:SS format (e.g., 387 seconds = β6:27β)
Lap Distance Display: Accepts lap distance in meters, converts and displays in kilometers or miles with appropriate precision (1-2 decimal places)
Lap Timer Display: Accepts lap elapsed time in seconds, formats as H:MM:SS or MM:SS (e.g., β0:05:49β or β5:49β)
Unit System Support: Automatic conversion between metric (km) and imperial (mi.) units
GPS Fix Handling: Shows βββ placeholders when GPS signal is unavailable or data is invalid
Automatic Formatting: Intelligent precision adjustment for distance values based on magnitude
Threshold-Based HR Visualization: Heart rate bar shows one of 5 heart icons based on configurable intensity zones
The widget automatically invalidates and redraws text areas and heart rate icons when data changes, ensuring immediate visual updates.
Usage in TouchGFX Designerο
Import the Custom Container Package:
Open TouchGFX Designer
Go to
Custom ContainersβImportSelect the TrackFace2 package file (manifest.xml)
Add to Screen:
Drag the TrackFace2 custom container from the Custom Containers panel onto your screen
Position as needed (recommended size for optimal layout)
The widget includes both TrackFace2 and HrBar custom containers
Configure Properties:
The widget has no configurable properties in Designer beyond standard container properties
All data, unit settings, and heart rate thresholds are controlled programmatically
Usage in C++ Codeο
Include the Header:
#include <gui/containers/TrackFace2.hpp>
Declare in View: In your View class (e.g.,
MainView.hpp):TrackFace2 trackFace;
Initialize in Constructor/Setup:
add(trackFace); trackFace.setPosition(x, y, width, height);
Update Data:
// Set heart rate with thresholds (fat burn: 120, cardio: 140, threshold: 160, maximum: 180) std::array<uint8_t, 4> thresholds = {120, 140, 160, 180}; trackFace.setHR(155.0f, 0.0f, thresholds); // 155 BPM, shows hr4 icon // Set lap pace (seconds per kilometer) trackFace.setLapPace(387.0f, false, true); // 6:27 min/km, metric, GPS fix OK // Set lap distance (meters) trackFace.setLapDistance(5000.0f, false, true); // 5.00 km, metric, GPS fix OK // Set lap timer (seconds) trackFace.setLapTimer(349); // 0:05:49
Handle Unit System:
// Imperial units example trackFace.setLapPace(623.0f, true, true); // 10:23 min/mi (equivalent to 6:27 min/km) trackFace.setLapDistance(3218.0f, true, true); // 2.00 mi
GPS Fix Handling:
// No GPS fix - shows "---" trackFace.setLapPace(0.0f, false, false); trackFace.setLapDistance(0.0f, false, false);
Heart Rate Thresholds:
// Define training zones std::array<uint8_t, 4> zones = {110, 130, 150, 170}; // Warm-up, Fat burn, Cardio, Threshold trackFace.setHR(145.0f, 0.0f, zones); // Shows hr3 (cardio zone)
Files Includedο
manifest.xml: Package manifestcontent/CustomContainerExport.touchgfx: Designer export definitioncontent/CustomContainerManifest.xml: Container manifest with TrackFace2 and HrBarcontent/texts.xml: Text database with labels and templatesfiles/gui/include/gui/containers/TrackFace2.hpp: Header filefiles/gui/src/containers/TrackFace2.cpp: Implementation filefiles/gui/include/gui/containers/HrBar.hpp: HrBar header filefiles/gui/src/containers/HrBar.cpp: HrBar implementation filefiles/assets/fonts/: 3 Poppins font variants (Italic, Regular, SemiBold)files/assets/images/: 6 HR images (HR_group.png, HR_1.png to HR_5.png)
Dependenciesο
TouchGFX Framework (minimum version 4.26.0)
App::Utils utility functions for unit conversions and time formatting
Standard TouchGFX container and text components
C++11 or later for std::array support