227 lines
5.5 KiB
Markdown
227 lines
5.5 KiB
Markdown
# SquareLine Studio UI Integration Guide
|
||
|
||
## ✅ Current Status
|
||
|
||
Your SquareLine Studio UI is now **fully integrated and displaying** on the ESP32-S3-LCD-1.3!
|
||
|
||
### What's Showing Now
|
||
|
||
The display shows your **ui_Home_Screen** with:
|
||
- **ui_Home_LBL** label showing "Home Screen" (default text from SquareLine)
|
||
- 240×240 pixel layout
|
||
- Centered flex container
|
||
|
||
## UI Structure
|
||
|
||
From your SquareLine Studio export (`include/ui/screens/ui_Home_Screen.c`):
|
||
|
||
```
|
||
ui_Home_Screen (screen)
|
||
└── ui_Main_Container (240×240 container, centered)
|
||
└── ui_Home_LBL (label, centered)
|
||
```
|
||
|
||
### Available UI Objects
|
||
|
||
You can access these objects in your code:
|
||
|
||
```cpp
|
||
extern lv_obj_t * ui_Home_Screen; // Main screen
|
||
extern lv_obj_t * ui_Main_Container; // 240×240 container
|
||
extern lv_obj_t * ui_Home_LBL; // Label widget
|
||
|
||
// Alternative pointers (same objects)
|
||
extern lv_obj_t * uic_Home_Screen;
|
||
extern lv_obj_t * uic_Main_Container;
|
||
extern lv_obj_t * uic_Home_LBL;
|
||
```
|
||
|
||
## How to Update UI Dynamically
|
||
|
||
### Update the Label Text
|
||
|
||
In `src/main.cpp`, add to the `loop()` function:
|
||
|
||
```cpp
|
||
void loop() {
|
||
static uint32_t last_update = 0;
|
||
|
||
if (millis() - last_update > 1000) {
|
||
last_update = millis();
|
||
|
||
// Update label with dynamic content
|
||
if (uic_Home_LBL != NULL) {
|
||
char text[64];
|
||
snprintf(text, sizeof(text),
|
||
"Uptime: %lus\nHeap: %d",
|
||
millis() / 1000,
|
||
ESP.getFreeHeap());
|
||
lv_label_set_text(uic_Home_LBL, text);
|
||
}
|
||
}
|
||
|
||
delay(10);
|
||
}
|
||
```
|
||
|
||
### Change Label Color
|
||
|
||
```cpp
|
||
lv_obj_set_style_text_color(uic_Home_LBL, lv_color_hex(0x00FF00), 0); // Green
|
||
```
|
||
|
||
### Change Label Font Size
|
||
|
||
```cpp
|
||
lv_obj_set_style_text_font(uic_Home_LBL, &lv_font_montserrat_24, 0);
|
||
```
|
||
|
||
## Adding More Widgets in SquareLine Studio
|
||
|
||
1. **Edit in SquareLine Studio**
|
||
- Open your ESP32-S3-LCD-1.3 project
|
||
- Add widgets (buttons, labels, arcs, meters, etc.)
|
||
- Configure properties and events
|
||
|
||
2. **Export UI Files**
|
||
- File → Export → Create Template Project
|
||
- Export to: `include/ui/`
|
||
|
||
3. **Rebuild**
|
||
```bash
|
||
pio run --target upload
|
||
```
|
||
|
||
## Example: Automotive Dashboard UI
|
||
|
||
For your Phase 3 automotive dashboard, you could add in SquareLine:
|
||
|
||
### Widgets to Add
|
||
|
||
1. **Large Label** for gear position (P/R/N/D)
|
||
2. **Arc Meters** for temperatures (3 arcs)
|
||
3. **Small Label** for battery voltage
|
||
4. **Panel/Label** for fault codes
|
||
|
||
### Update Strategy
|
||
|
||
```cpp
|
||
void updateAutomotiveUI(const automotive_data_t* data) {
|
||
// Update gear position
|
||
lv_label_set_text(ui_GearLabel, gear_to_string(data->gear_position));
|
||
|
||
// Update gearbox temp arc
|
||
lv_arc_set_value(ui_GearboxTempArc, (int)data->gearbox_temp_c);
|
||
|
||
// Update battery voltage
|
||
char voltage[16];
|
||
snprintf(voltage, sizeof(voltage), "%.2fV", data->battery_voltage_v);
|
||
lv_label_set_text(ui_BatteryLabel, voltage);
|
||
}
|
||
```
|
||
|
||
## Current UI File Locations
|
||
|
||
```
|
||
include/ui/
|
||
├── ui.h # Main UI header
|
||
├── ui.c # UI initialization
|
||
├── ui_helpers.h/.c # Helper functions
|
||
├── ui_events.h # Event handlers
|
||
├── screens/
|
||
│ ├── ui_Home_Screen.h # Home screen header
|
||
│ └── ui_Home_Screen.c # Home screen implementation
|
||
├── components/ # Custom components
|
||
└── fonts/ # Custom fonts (if any)
|
||
```
|
||
|
||
## Modifying SquareLine UI
|
||
|
||
### Option 1: Edit in SquareLine Studio (Recommended)
|
||
|
||
1. Open SquareLine Studio
|
||
2. Load your ESP32-S3-LCD-1.3 project
|
||
3. Make changes visually
|
||
4. Export and replace files in `include/ui/`
|
||
|
||
### Option 2: Edit Code Directly
|
||
|
||
You can manually edit `include/ui/screens/ui_Home_Screen.c`:
|
||
|
||
```cpp
|
||
void ui_Home_Screen_screen_init(void)
|
||
{
|
||
ui_Home_Screen = lv_obj_create(NULL);
|
||
|
||
// Add more widgets here
|
||
lv_obj_t * my_new_label = lv_label_create(ui_Main_Container);
|
||
lv_label_set_text(my_new_label, "Custom Label");
|
||
lv_obj_align(my_new_label, LV_ALIGN_BOTTOM_MID, 0, -10);
|
||
}
|
||
```
|
||
|
||
**Warning**: Manual changes will be lost if you re-export from SquareLine Studio!
|
||
|
||
## Screen Transitions (Multi-Screen Apps)
|
||
|
||
If you add multiple screens in SquareLine:
|
||
|
||
```cpp
|
||
// Load different screen
|
||
lv_scr_load(ui_SettingsScreen);
|
||
|
||
// Load with animation
|
||
lv_scr_load_anim(ui_SettingsScreen, LV_SCR_LOAD_ANIM_FADE_IN, 300, 0, false);
|
||
```
|
||
|
||
## Troubleshooting
|
||
|
||
### UI Not Showing / Blank Screen
|
||
|
||
Check initialization order in `main.cpp`:
|
||
1. `DisplayInit::init()` ← Must be first
|
||
2. `ui_init()` ← Loads SquareLine UI
|
||
3. Start LVGL task
|
||
4. Don't overwrite label text in loop unless intended
|
||
|
||
### Label Text Not Updating
|
||
|
||
Ensure you're using the correct pointer:
|
||
```cpp
|
||
if (uic_Home_LBL != NULL) { // ✅ Good
|
||
lv_label_set_text(uic_Home_LBL, "New text");
|
||
}
|
||
```
|
||
|
||
### Colors Look Wrong
|
||
|
||
Check color depth in `lv_conf.h`:
|
||
```cpp
|
||
#define LV_COLOR_DEPTH 16 // RGB565
|
||
```
|
||
|
||
SquareLine Studio exports for 16-bit color.
|
||
|
||
## Resources
|
||
|
||
- **SquareLine Studio Docs**: https://docs.squareline.io/
|
||
- **LVGL Documentation**: https://docs.lvgl.io/8.4/
|
||
- **LVGL Widgets**: https://docs.lvgl.io/8.4/widgets/index.html
|
||
|
||
## Next Steps for Phase 2 & 3
|
||
|
||
1. **Phase 2**: Add UART receiver module
|
||
2. **Phase 3**: Design automotive dashboard in SquareLine:
|
||
- Add gear position label (large font)
|
||
- Add 3 arc meters for temperatures
|
||
- Add battery voltage label
|
||
- Add fault code panel
|
||
3. Export and integrate
|
||
4. Update UI in `loop()` with UART data
|
||
|
||
---
|
||
|
||
**Current UI**: Showing "Home Screen" label
|
||
**Status**: ✅ SquareLine Studio UI fully integrated
|
||
**Last Updated**: 2025-11-08
|