Objective: Develop a visually appealing graphical user interface (GUI) using the LVGL library on the Waveshare ESP32-C6-LCD-1.47 board, featuring a 1.47-inch LCD (172x320 resolution, ST7789V3 driver), programmed via Arduino IDE on Ubuntu 24.04. The GUI will display real-time HF radio propagation and solar data critical for amateur radio operators, including Sunspot Number (SN), Solar Flux Index (SFI), A-index, K-index, X-ray flux, solar wind conditions, HF band conditions (80m–10m), and recent PSKReporter spots. The design must be uncluttered, modern, and highly readable on the small display, optimized for a user new to Arduino IDE. Focus solely on implementing the GUI and data display, avoiding troubleshooting details unless essential for functionality.
Project Context:
Purpose: Provide amateur radio operators with a clear, concise display of HF propagation and solar data to assess communication conditions, supplemented by recent PSKReporter spots showing active HF contacts. The interface should aid in deciding optimal bands and times for radio operation.Data to Display:
Sunspot Number (SN): Indicates solar activity level (0–250, higher values improve HF propagation).Solar Flux Index (SFI): Measures 10.7cm solar radio flux (50–300, >150 indicates good HF conditions).A-index: Linear geomagnetic activity index (1–6 optimal, >11 disruptive to HF).K-index: Logarithmic geomagnetic activity index (0–1 ideal, >3 impacts HF, >5 severe).X-ray Flux: Ionospheric X-ray intensity (classes A, B, C, M, X; A/B best, M/X disrupt HF).Solar Wind (SW): Speed in km/s (0–1000, <400 better) and proton/electron density (affects E-layer ionization).HF Band Conditions: Status for 80m, 40m, 20m, 15m, 10m bands (e.g., Poor, Fair, Good), derived from SN, SFI, A, K, and X-ray data.PSKReporter Spots: Recent HF contacts (e.g., callsign, band, time, location) from PSKReporter API, showing active stations.Data Source: Use mock data in the sketch for simplicity (e.g., SN=120, SFI=150, A=5, K=2, X-ray=C, SW=400 km/s, HF bands=Good/Fair, sample PSKReporter spots). For future enhancement, real data can be fetched via Wi-Fi from NOAA (www.swpc.noaa.gov) (www.swpc.noaa.gov), HamQSL (www.hamqsl.com) (www.hamqsl.com), or PSKReporter API (pskreporter.info).Design Goals: Create a minimalist, modern GUI with a dark background, light text, and color-coded indicators for clarity. Ensure readability on the 172x320 display with intuitive layout, avoiding visual clutter. Use LVGL widgets (e.g., labels, tables, gauges) to present data effectively.Hardware Context:
Board: Waveshare ESP32-C6-LCD-1.47.Microcontroller: ESP32-C6, 32-bit RISC-V single-core, 160 MHz, 512KB SRAM, 4MB Flash.Display: 1.47-inch LCD (LBS147TC-IF15), 172x320 resolution, 262K colors, ST7789V3 driver, SPI interface.
SPI Pins: CS=14, DC=15, RST=21, MOSI=6, SCLK=7.Backlight: GPIO 22 (TFT_LIGHT, set HIGH to enable).Note: Non-standard 172x320 resolution requires centering within the ST7789’s 240x320 frame using a 34-pixel horizontal offset ((240-172)/2).Additional Features: RGB LED (GPIO 8), MicroSD slot, USB-C for power and programming, 2.4 GHz Wi-Fi 6, Bluetooth 5.0 (BLE) for potential data fetching.Assumption: Non-touch variant, no touch input required.Software Context:
Operating System: Ubuntu 24.04.IDE: Arduino IDE 1.8.19.Board Package: ESP32 by Espressif Systems, version 3.1.3, configured for ESP32C6 Dev Module.
Settings: CPUFreq=160, FlashMode=qio, FlashFreq=80, FlashSize=4M, UploadSpeed=921600, USB CDC On Boot=Enabled.
Configures LVGL (version 8.x) for the ST7789 driver, 172x320 resolution, and rotation 3.Creates a visually appealing GUI featuring:
Labels for SN, SFI, A-index, K-index, X-ray flux, and solar wind speed.A table or gauge for HF band conditions (80m–10m).A scrolling list or table for PSKReporter spots (mock data: callsign, band, time, location).A clean, dark-themed layout with light text, color-coded indicators, and readable fonts.Uses mock data for all displayed metrics and spots.
Assistant
Okay, this is a fantastic project! Let's outline the steps and then put together the Arduino sketch.
Assumptions & Setup (Recap):
Arduino IDE Setup:
ESP32 Board Package installed (version 3.0.0 or newer for ESP32-C6 support, your 3.1.3 is fine).
LVGL library (v8.x, typically v8.3.x) installed via Library Manager.
TFT_eSPI library installed via Library Manager (this will drive the ST7789).
TFT_eSPI Configuration (User_Setup.h or User_Setup_Select.h):
You'll need to configure TFT_eSPI. The easiest way is to find User_Setup_Select.h in the TFT_eSPI library folder and uncomment #include <User_Setups/Setup25_TTGO_T_Display.h>. Then, open User_Setups/Setup25_TTGO_T_Display.h (or create a new custom setup file) and modify it for your Waveshare board:
c
// Example for a custom User_Setup.h for Waveshare ESP32-C6-LCD-1.47
#define ST7789_DRIVER // Chip ST7789
// Waveshare ESP32-C6-LCD-1.47 SPI Pins
#define TFT_MOSI 6 // SDA
#define TFT_SCLK 7 // SCL
#define TFT_CS 14 // Chip select
#define TFT_DC 15 // Data/Command
#define TFT_RST 21 // Reset
// #define TFT_BL 22 // LED back-light (TFT_eSPI can control it if not driven by a PWM)
// We will control GPIO22 manually for backlight
// For ST7789, define display dimensions FOR THE DRIVER (before rotation)
// The display is 172x320 physically.
// The ST7789 is often on a 240x320 frame.
// The offset is crucial for the 172-pixel width.
#define TFT_WIDTH 172
#define TFT_HEIGHT 320
// Offset for the 172-pixel display within a 240-pixel wide controller frame
#define TFT_OFFSET_X 34 // (240 - 172) / 2
#define TFT_OFFSET_Y 0 // No vertical offset needed for this orientation
// Define the SPI clock frequency
#define SPI_FREQUENCY 40000000 // 40MHz is a good start
// #define SPI_FREQUENCY 80000000 // Try 80MHz if 40MHz is stable
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters "01234567890:-." METAR
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters "01234567890:-."
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters "01234567890:-."
//#define LOAD_FONT8N // Font 8. Alternative Number only version
#define LOAD_GFXFF // FreeFonts. Include access to the GFX FreeFonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
// Optional: Enable DMA for faster transfers if available and stable
// #define TFT_SPI_PORT VSPI_HOST // ESP32 specific
// #define SPI_HAS_TRANSACTION
// #define USE_HSPI_PORT // Use HSPI if VSPI is used by other peripherals
// #define ESP32_DMA // For ESP32 DMA
Important: After saving User_Setup.h, close and reopen the Arduino IDE if it was open, to ensure it picks up the changes. GPIO22 for backlight will be handled manually in the sketch.
LVGL Configuration (lv_conf.h):
Copy lv_conf_template.h from the LVGL library folder, rename it to lv_conf.h, and place it in your Arduino libraries folder alongside the lvgl library folder (e.g., ~/Arduino/libraries/lv_conf.h) OR within your sketch directory. The latter is often easier for project-specific settings.
#define LV_THEME_DEFAULT_DARK 1 // Enable dark mode for default theme
#define LV_THEME_DEFAULT_FONT &lv_font_montserrat_14 // Or 12 for more space
#define LV_MEM_SIZE (32U * 1024U) // Start with 32KB, adjust if needed
#define LV_TICK_CUSTOM 1
Arduino Sketch:
cpp
#include <lvgl.h>
#include <TFT_eSPI.h>
/* LVGL Defines and Variables */
#define TFT_HOR_RES 320 // LVGL horizontal resolution after rotation
#define TFT_VER_RES 172 // LVGL vertical resolution after rotation
#define TFT_LIGHT_PIN 22
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf_1[TFT_HOR_RES * 20]; // 20 lines of buffer
// static lv_color_t buf_2[TFT_HOR_RES * 10]; // Optional second buffer
TFT_eSPI tft = TFT_eSPI();
/* Display flushing function for LVGL */
void my_disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p) {
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.pushColors((uint16_t *)color_p, w * h, true);
tft.endWrite();
lv_disp_flush_ready(disp_drv);
}
/* Mock Data Structures and Variables */
typedef struct {
int sn;
int sfi;
int a_index;
int k_index;
char x_ray[5]; // e.g., "B7.3"
int solar_wind_speed;
} SolarData_t;
typedef struct {
char band[5]; // e.g., "80m"
char status[10]; // e.g., "Good"
} BandCondition_t;
typedef struct {
char callsign[10];
char band[5];
char time_utc[6]; // "HH:MM"
char grid[7]; // "FN31"
} PSKSpot_t;
SolarData_t solar_data = {120, 150, 5, 2, "C1.2", 400};
BandCondition_t band_conditions[] = {
{"80m", "Fair"}, {"40m", "Good"}, {"20m", "Good"},
{"17m", "Good"}, {"15m", "Fair"}, {"12m", "Poor"}, {"10m", "Poor"}
};
int num_band_conditions = sizeof(band_conditions) / sizeof(BandCondition_t);
PSKSpot_t psk_spots[] = {
{"K1ABC", "20m", "10:35", "FN31"},
{"W2DEF", "40m", "10:33", "EM15"},
{"G3GHI", "15m", "10:30", "IO91"},
{"JA4JKL", "20m", "10:28", "PM65"},
{"VK5MNO", "40m", "10:25", "PF95"}
};
int num_psk_spots = sizeof(psk_spots) / sizeof(PSKSpot_t);
/* LVGL GUI Element Pointers */
// Solar Data Labels
lv_obj_t *label_sn_val;
lv_obj_t *label_sfi_val;
lv_obj_t *label_a_val;
lv_obj_t *label_k_val;
lv_obj_t *label_xray_val;
lv_obj_t *label_sw_val;
// Band Conditions Table
lv_obj_t *table_band_conditions;
// PSK Reporter Table
lv_obj_t *table_psk_spots;
// Styles
static lv_style_t style_section_title;
static lv_style_t style_label_key;
static lv_style_t style_label_value;
static lv_style_t style_table_cell_good;
static lv_style_t style_table_cell_fair;
static lv_style_t style_table_cell_poor;
static lv_style_t style_table_cell_band;
static lv_style_t style_table_cell_header;
/* Helper function to get color for propagation status */
lv_color_t get_status_color(const char* status) {
if (strcmp(status, "Good") == 0) return lv_palette_main(LV_PALETTE_GREEN);
if (strcmp(status, "Fair") == 0) return lv_palette_main(LV_PALETTE_YELLOW);
if (strcmp(status, "Poor") == 0) return lv_palette_main(LV_PALETTE_RED);
return lv_color_white(); // Default
}
/* Helper function to get color for K-index */
lv_color_t get_k_index_color(int k) {
if (k <= 1) return lv_palette_main(LV_PALETTE_GREEN);
if (k <= 3) return lv_palette_main(LV_PALETTE_LIGHT_GREEN); // A slightly different green or yellow
if (k == 4) return lv_palette_main(LV_PALETTE_YELLOW);
return lv_palette_main(LV_PALETTE_RED);
}
/* Helper function to get color for A-index */
lv_color_t get_a_index_color(int a) {
if (a <= 6) return lv_palette_main(LV_PALETTE_GREEN);
if (a <= 11) return lv_palette_main(LV_PALETTE_YELLOW);
return lv_palette_main(LV_PALETTE_RED);
}
/* Helper function to get color for X-Ray flux */
lv_color_t get_xray_color(const char* xray) {
if (xray[0] == 'A' || xray[0] == 'B') return lv_palette_main(LV_PALETTE_GREEN);
if (xray[0] == 'C') return lv_palette_main(LV_PALETTE_YELLOW);
if (xray[0] == 'M') return lv_palette_main(LV_PALETTE_ORANGE);
if (xray[0] == 'X') return lv_palette_main(LV_PALETTE_RED);
return lv_color_white();
}
void create_gui_styles() {
// Section Title Style
lv_style_init(&style_section_title);
lv_style_set_text_font(&style_section_title, &lv_font_montserrat_16);
lv_style_set_text_color(&style_section_title, lv_palette_main(LV_PALETTE_LIGHT_BLUE)); // A light blue for titles
// Label Key Style (e.g., "SN:")
lv_style_init(&style_label_key);
lv_style_set_text_font(&style_label_key, &lv_font_montserrat_12);
lv_style_set_text_color(&style_label_key, lv_palette_lighten(LV_PALETTE_GREY, 2)); // Lighter grey
// Label Value Style (e.g., "120")
lv_style_init(&style_label_value);
lv_style_set_text_font(&style_label_value, &lv_font_montserrat_12);
lv_style_set_text_color(&style_label_value, lv_color_white());
// Table Cell Styles for Band Conditions
lv_style_init(&style_table_cell_good);
lv_style_set_text_color(&style_table_cell_good, lv_palette_main(LV_PALETTE_GREEN));
lv_style_set_text_font(&style_table_cell_good, &lv_font_montserrat_12);
lv_style_init(&style_table_cell_fair);
lv_style_set_text_color(&style_table_cell_fair, lv_palette_main(LV_PALETTE_YELLOW));
lv_style_set_text_font(&style_table_cell_fair, &lv_font_montserrat_12);
lv_style_init(&style_table_cell_poor);
lv_style_set_text_color(&style_table_cell_poor, lv_palette_main(LV_PALETTE_RED));
lv_style_set_text_font(&style_table_cell_poor, &lv_font_montserrat_12);
lv_style_init(&style_table_cell_band);
lv_style_set_text_color(&style_table_cell_band, lv_color_white());
lv_style_set_text_font(&style_table_cell_band, &lv_font_montserrat_12);
// Table Header Style
lv_style_init(&style_table_cell_header);
lv_style_set_text_color(&style_table_cell_header, lv_palette_main(LV_PALETTE_CYAN));
lv_style_set_text_font(&style_table_cell_header, &lv_font_montserrat_12);
lv_style_set_bg_opa(&style_table_cell_header, LV_OPA_TRANSP); // Transparent background
lv_style_set_border_width(&style_table_cell_header, 0);
}
void create_gui() {
lv_obj_t *scr = lv_scr_act();
lv_obj_set_style_bg_color(scr, lv_color_black(), LV_PART_MAIN); // Set screen background to black
create_gui_styles(); // Initialize styles
// --- Solar Data Section ---
lv_obj_t *solar_panel = lv_obj_create(scr);
lv_obj_set_size(solar_panel, TFT_HOR_RES - 10, 75); // Adjust height as needed
lv_obj_align(solar_panel, LV_ALIGN_TOP_MID, 0, 5);
lv_obj_set_style_bg_color(solar_panel, lv_color_hex(0x101010), LV_PART_MAIN); // Darker grey panel
lv_obj_set_style_border_width(solar_panel, 0, LV_PART_MAIN);
lv_obj_set_flex_flow(solar_panel, LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_flex_align(solar_panel, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_all(solar_panel, 2, LV_PART_MAIN);
// SN
lv_obj_t *sn_cont = lv_obj_create(solar_panel);
lv_obj_set_size(sn_cont, LV_PCT(30), LV_PCT(45)); // % of parent
lv_obj_remove_style_all(sn_cont); // Remove default container style
lv_obj_set_flex_flow(sn_cont, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(sn_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t *label_sn_key = lv_label_create(sn_cont);
lv_label_set_text(label_sn_key, "SN:");
lv_obj_add_style(label_sn_key, &style_label_key, 0);
label_sn_val = lv_label_create(sn_cont);
lv_obj_add_style(label_sn_val, &style_label_value, 0);
lv_obj_set_style_pad_left(label_sn_val, 3, 0);
// SFI
lv_obj_t *sfi_cont = lv_obj_create(solar_panel);
lv_obj_set_size(sfi_cont, LV_PCT(30), LV_PCT(45));
lv_obj_remove_style_all(sfi_cont);
lv_obj_set_flex_flow(sfi_cont, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(sfi_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t *label_sfi_key = lv_label_create(sfi_cont);
lv_label_set_text(label_sfi_key, "SFI:");
lv_obj_add_style(label_sfi_key, &style_label_key, 0);
label_sfi_val = lv_label_create(sfi_cont);
lv_obj_add_style(label_sfi_val, &style_label_value, 0);
lv_obj_set_style_pad_left(label_sfi_val, 3, 0);
// A-Index
lv_obj_t *a_cont = lv_obj_create(solar_panel);
lv_obj_set_size(a_cont, LV_PCT(30), LV_PCT(45));
lv_obj_remove_style_all(a_cont);
lv_obj_set_flex_flow(a_cont, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(a_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t *label_a_key = lv_label_create(a_cont);
lv_label_set_text(label_a_key, "A:");
lv_obj_add_style(label_a_key, &style_label_key, 0);
label_a_val = lv_label_create(a_cont);
lv_obj_add_style(label_a_val, &style_label_value, 0); // Base style
lv_obj_set_style_pad_left(label_a_val, 3, 0);
// K-Index
lv_obj_t *k_cont = lv_obj_create(solar_panel);
lv_obj_set_size(k_cont, LV_PCT(30), LV_PCT(45));
lv_obj_remove_style_all(k_cont);
lv_obj_set_flex_flow(k_cont, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(k_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t *label_k_key = lv_label_create(k_cont);
lv_label_set_text(label_k_key, "K:");
lv_obj_add_style(label_k_key, &style_label_key, 0);
label_k_val = lv_label_create(k_cont);
lv_obj_add_style(label_k_val, &style_label_value, 0); // Base style
lv_obj_set_style_pad_left(label_k_val, 3, 0);
// X-Ray Flux
lv_obj_t *xray_cont = lv_obj_create(solar_panel);
lv_obj_set_size(xray_cont, LV_PCT(30), LV_PCT(45));
lv_obj_remove_style_all(xray_cont);
lv_obj_set_flex_flow(xray_cont, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(xray_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t *label_xray_key = lv_label_create(xray_cont);
lv_label_set_text(label_xray_key, "XRay:");
lv_obj_add_style(label_xray_key, &style_label_key, 0);
label_xray_val = lv_label_create(xray_cont);
lv_obj_add_style(label_xray_val, &style_label_value, 0); // Base style
lv_obj_set_style_pad_left(label_xray_val, 3, 0);
// Solar Wind
lv_obj_t *sw_cont = lv_obj_create(solar_panel);
lv_obj_set_size(sw_cont, LV_PCT(30), LV_PCT(45));
lv_obj_remove_style_all(sw_cont);
lv_obj_set_flex_flow(sw_cont, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(sw_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t *label_sw_key = lv_label_create(sw_cont);
lv_label_set_text(label_sw_key, "SW:");
lv_obj_add_style(label_sw_key, &style_label_key, 0);
label_sw_val = lv_label_create(sw_cont);
lv_obj_add_style(label_sw_val, &style_label_value, 0);
lv_obj_set_style_pad_left(label_sw_val, 3, 0);
// --- HF Band Conditions Section ---
lv_obj_t *band_panel = lv_obj_create(scr);
lv_obj_set_size(band_panel, TFT_HOR_RES - 10, 65); // Adjust height
lv_obj_align_to(band_panel, solar_panel, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
lv_obj_set_style_bg_color(band_panel, lv_color_hex(0x101010), LV_PART_MAIN);
lv_obj_set_style_border_width(band_panel, 0, LV_PART_MAIN);
lv_obj_set_style_pad_all(band_panel, 3, LV_PART_MAIN);
lv_obj_t *band_title = lv_label_create(band_panel);
lv_label_set_text(band_title, "HF Band Conditions");
lv_obj_add_style(band_title, &style_section_title, 0);
lv_obj_align(band_title, LV_ALIGN_TOP_LEFT, 0, 0);
table_band_conditions = lv_table_create(band_panel);
lv_obj_align_to(table_band_conditions, band_title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 2);
lv_obj_set_width(table_band_conditions, LV_PCT(100));
lv_obj_set_style_bg_opa(table_band_conditions, LV_OPA_TRANSP, LV_PART_MAIN); // Transparent table background
lv_obj_set_style_border_width(table_band_conditions, 0, LV_PART_MAIN);
lv_obj_set_style_pad_all(table_band_conditions, 0, LV_PART_MAIN); // No padding for the table itself
lv_table_set_col_cnt(table_band_conditions, 4); // Band | Status | Band | Status (2 columns of band-status pairs)
lv_table_set_col_width(table_band_conditions, 0, 45); // Band name
lv_table_set_col_width(table_band_conditions, 1, 65); // Status
lv_table_set_col_width(table_band_conditions, 2, 45); // Band name
lv_table_set_col_width(table_band_conditions, 3, 65); // Status
// --- PSK Reporter Spots Section ---
lv_obj_t *psk_panel = lv_obj_create(scr);
// Calculate remaining height, considering small margins
int psk_panel_height = TFT_VER_RES - lv_obj_get_y(band_panel) - lv_obj_get_height(band_panel) - 10;
lv_obj_set_size(psk_panel, TFT_HOR_RES - 10, psk_panel_height > 30 ? psk_panel_height : 30);
lv_obj_align_to(psk_panel, band_panel, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
lv_obj_set_style_bg_color(psk_panel, lv_color_hex(0x101010), LV_PART_MAIN);
lv_obj_set_style_border_width(psk_panel, 0, LV_PART_MAIN);
lv_obj_set_style_pad_all(psk_panel, 3, LV_PART_MAIN);
lv_obj_t *psk_title = lv_label_create(psk_panel);
lv_label_set_text(psk_title, "Recent PSK Spots");
lv_obj_add_style(psk_title, &style_section_title, 0);
lv_obj_align(psk_title, LV_ALIGN_TOP_LEFT, 0, 0);
table_psk_spots = lv_table_create(psk_panel);
lv_obj_align_to(table_psk_spots, psk_title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 2);
lv_obj_set_width(table_psk_spots, LV_PCT(100));
lv_obj_set_height(table_psk_spots, LV_SIZE_CONTENT); // Expand or use lv_obj_get_height(psk_panel) - lv_obj_get_y(psk_title) - lv_obj_get_height(psk_title) - some_padding
lv_obj_set_style_bg_opa(table_psk_spots, LV_OPA_TRANSP, LV_PART_MAIN);
lv_obj_set_style_border_width(table_psk_spots, 0, LV_PART_MAIN);
lv_obj_set_style_pad_all(table_psk_spots, 0, LV_PART_MAIN);
lv_table_set_col_cnt(table_psk_spots, 4);
lv_table_set_col_width(table_psk_spots, 0, 75); // Callsign
lv_table_set_col_width(table_psk_spots, 1, 45); // Band
lv_table_set_col_width(table_psk_spots, 2, 55); // Time
lv_table_set_col_width(table_psk_spots, 3, 55); // Grid
// Add header row to PSK table
lv_table_set_cell_value(table_psk_spots, 0, 0, "Call");
lv_table_set_cell_value(table_psk_spots, 0, 1, "Band");
lv_table_set_cell_value(table_psk_spots, 0, 2, "UTC");
lv_table_set_cell_value(table_psk_spots, 0, 3, "Grid");
for(int i=0; i<4; ++i) {
lv_obj_add_style(lv_table_get_cell_user_data(table_psk_spots, 0, i), &style_table_cell_header, LV_PART_ITEMS | LV_STATE_DEFAULT);
}
}
void update_gui_data() {
char buf[20];
// Solar Data
sprintf(buf, "%d", solar_data.sn);
lv_label_set_text(label_sn_val, buf);
sprintf(buf, "%d", solar_data.sfi);
lv_label_set_text(label_sfi_val, buf);
sprintf(buf, "%d", solar_data.a_index);
lv_label_set_text(label_a_val, buf);
lv_obj_set_style_text_color(label_a_val, get_a_index_color(solar_data.a_index), 0);
sprintf(buf, "%d", solar_data.k_index);
lv_label_set_text(label_k_val, buf);
lv_obj_set_style_text_color(label_k_val, get_k_index_color(solar_data.k_index), 0);
lv_label_set_text(label_xray_val, solar_data.x_ray);
lv_obj_set_style_text_color(label_xray_val, get_xray_color(solar_data.x_ray), 0);
sprintf(buf, "%d km/s", solar_data.solar_wind_speed);
lv_label_set_text(label_sw_val, buf);
// Band Conditions Table
lv_table_set_row_cnt(table_band_conditions, (num_band_conditions + 1) / 2); // Number of rows needed
for (int i = 0; i < num_band_conditions; i++) {
int row = i / 2;
int col_band = (i % 2) * 2;
int col_status = col_band + 1;
lv_table_set_cell_value(table_band_conditions, row, col_band, band_conditions[i].band);
lv_obj_add_style(lv_table_get_cell_user_data(table_band_conditions, row, col_band), &style_table_cell_band, LV_PART_ITEMS | LV_STATE_DEFAULT);
lv_table_set_cell_value(table_band_conditions, row, col_status, band_conditions[i].status);
if (strcmp(band_conditions[i].status, "Good") == 0) {
lv_obj_add_style(lv_table_get_cell_user_data(table_band_conditions, row, col_status), &style_table_cell_good, LV_PART_ITEMS | LV_STATE_DEFAULT);
} else if (strcmp(band_conditions[i].status, "Fair") == 0) {
lv_obj_add_style(lv_table_get_cell_user_data(table_band_conditions, row, col_status), &style_table_cell_fair, LV_PART_ITEMS | LV_STATE_DEFAULT);
} else {
lv_obj_add_style(lv_table_get_cell_user_data(table_band_conditions, row, col_status), &style_table_cell_poor, LV_PART_ITEMS | LV_STATE_DEFAULT);
}
}
// PSK Reporter Spots Table (start from row 1, row 0 is header)
lv_table_set_row_cnt(table_psk_spots, num_psk_spots + 1); // +1 for header
for (int i = 0; i < num_psk_spots; i++) {
lv_table_set_cell_value(table_psk_spots, i + 1, 0, psk_spots[i].callsign);
lv_table_set_cell_value(table_psk_spots, i + 1, 1, psk_spots[i].band);
lv_table_set_cell_value(table_psk_spots, i + 1, 2, psk_spots[i].time_utc);
lv_table_set_cell_value(table_psk_spots, i + 1, 3, psk_spots[i].grid);
// Apply default text style to data rows (white text)
for(int c=0; c<4; ++c) {
lv_obj_add_style(lv_table_get_cell_user_data(table_psk_spots, i + 1, c), &style_label_value, LV_PART_ITEMS | LV_STATE_DEFAULT);
}
}
}
void setup() {
Serial.begin(115200);
Serial.println("Radio Propagation Display Starting...");
// Backlight ON
pinMode(TFT_LIGHT_PIN, OUTPUT);
digitalWrite(TFT_LIGHT_PIN, HIGH);
// LVGL and TFT_eSPI Initialization
lv_init();
tft.begin();
tft.setRotation(3); // Landscape, USB connector on the right for Waveshare 1.47"
// Rotation 1 would be USB connector on the left.
// Check physical orientation. Rotation 3 matches your request.
lv_disp_draw_buf_init(&draw_buf, buf_1, NULL, TFT_HOR_RES * 20);
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = TFT_HOR_RES;
disp_drv.ver_res = TFT_VER_RES;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
// Initialize the default theme to dark
lv_theme_t * th = lv_theme_default_init(lv_disp_get_default(), /*Use the DPI, font and theme of the Micropython build.*/
lv_palette_main(LV_PALETTE_BLUE), /*Primary accent color.*/
lv_palette_main(LV_PALETTE_RED), /*Secondary accent color.*/
true, /*Dark theme.*/
&lv_font_montserrat_12); /*Default font.*/
lv_disp_set_theme(lv_disp_get_default(), th); /*Assign the theme to the default display*/
create_gui();
update_gui_data();
Serial.println("Setup Complete. GUI should be visible.");
}
void loop() {
lv_timer_handler(); /* let the GUI do its work */
delay(5);
}
Key Changes and Explanations:
TFT_eSPI Configuration:
TFT_WIDTH and TFT_HEIGHT in User_Setup.h are set to 172 and 320 respectively.
TFT_OFFSET_X = 34 is crucial for centering the 172px wide display within the typical 240px ST7789 frame.
tft.setRotation(3) is used. This means the 320px dimension becomes the width, and 172px becomes the height for LVGL.
LVGL's TFT_HOR_RES is 320, TFT_VER_RES is 172.
LVGL Setup:
lv_conf.h needs LV_HOR_RES_MAX 320 and LV_VER_RES_MAX 172.
LV_TICK_CUSTOM 1 is enabled.
LV_THEME_DEFAULT_DARK 1 is set in lv_conf.h for an easier dark theme start. The code then further customizes it.
Backlight pin TFT_LIGHT_PIN (GPIO 22) is turned on in setup().
GUI Structure (create_gui):
Dark Theme: The screen background is explicitly set to lv_color_black(). Panels are a very dark grey lv_color_hex(0x101010).
Styles (create_gui_styles): Centralized style definitions for section titles, labels (key/value), and table cells (for color-coding status). This makes the code cleaner.
Solar Data Panel: Uses LV_FLEX_FLOW_ROW_WRAP for a responsive layout of the solar indices. Each index is in its own small container for better alignment.
Band Conditions Panel: Displays bands and their status in a compact table (2 columns of band-status pairs to save vertical space).
PSK Reporter Panel: Uses an lv_table for a structured list of spots. A header row is added.
Layout: Uses lv_obj_align and lv_obj_align_to for positioning panels. Flexbox is used within the solar panel. LV_PCT (percentage) is used for some sizing to make it more adaptable.
Fonts:lv_font_montserrat_12, _14, and _16 are used for different elements. Ensure these are enabled in lv_conf.h.
Data Display (update_gui_data):
Populates the labels and tables with mock data.
Color Coding:
A-Index, K-Index, X-Ray values are color-coded directly on their labels.
Band conditions in the table are color-coded based on their status string ("Good", "Fair", "Poor").
Helper functions (get_k_index_color, get_a_index_color, etc.) are used for clarity in color selection.
PSK Reporter Table:
Includes a header row for clarity.
Data rows are styled with default white text.
Readability:
The dark theme with light text is inherently readable.
Font sizes are chosen to be legible on the small screen.
Sufficient padding and spacing are attempted, but on a 172px high screen, things will be compact.
To Compile and Run:
Ensure Arduino IDE is set up for ESP32-C6 (Board: "ESP32C6 Dev Module" or similar).
Ensure TFT_eSPI is configured correctly in its User_Setup.h.
Ensure lv_conf.h is present (either in libraries or sketch folder) and configured.
Install LVGL library.
Connect the Waveshare board.
Select the correct port in Arduino IDE.
Upload the sketch.
This sketch provides a solid foundation. You might need to tweak font sizes, padding, and element dimensions slightly to achieve the perfect look on the actual hardware, as screen rendering can sometimes have minor variations from pure simulation.