100 lines
2.5 KiB
C
100 lines
2.5 KiB
C
/**
|
|
* @file display.c
|
|
* @brief Display manager - main screen and OLED rendering
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_log.h"
|
|
#include "oled.h"
|
|
#include "display.h"
|
|
#include "app_main.h"
|
|
|
|
static const char *TAG = "display";
|
|
|
|
/* Display state */
|
|
static display_mode_t current_mode = DISPLAY_MODE_CHANNELS;
|
|
|
|
/* Format buffer (unused currently) */
|
|
//static char line_buf[24];
|
|
|
|
void display_init(void)
|
|
{
|
|
oled_init(OLED_SDA_GPIO, OLED_SCL_GPIO);
|
|
ESP_LOGI(TAG, "Display initialized");
|
|
}
|
|
|
|
void display_set_mode(display_mode_t mode)
|
|
{
|
|
current_mode = mode;
|
|
}
|
|
|
|
void display_update(adc_data_t *adc_data)
|
|
{
|
|
oled_clear();
|
|
|
|
/* Draw top bar (yellow area - first 16px) */
|
|
/* Signal strength, flight battery, TX battery */
|
|
oled_draw_string(0, 0, "ALICERC v1.0", OLED_COLOR_WHITE);
|
|
|
|
/* Draw horizontal separator */
|
|
oled_draw_hline(0, 16, OLED_WIDTH, OLED_COLOR_WHITE);
|
|
|
|
/* Draw main content based on mode */
|
|
switch (current_mode) {
|
|
case DISPLAY_MODE_CHANNELS:
|
|
display_draw_channels(adc_data);
|
|
break;
|
|
case DISPLAY_MODE_TELEMETRY:
|
|
display_draw_telemetry(adc_data);
|
|
break;
|
|
case DISPLAY_MODE_MENU:
|
|
/* Menu drawing handled by menu system */
|
|
break;
|
|
}
|
|
|
|
oled_update();
|
|
}
|
|
|
|
void display_draw_channels(adc_data_t *adc_data)
|
|
{
|
|
char buf[32];
|
|
uint8_t y = 20;
|
|
|
|
/* Draw 8 channel values in 4 rows of 2 */
|
|
for (int i = 0; i < 8; i += 2) {
|
|
snprintf(buf, sizeof(buf), "CH%d:%4d CH%d:%4d",
|
|
i + 1, adc_data->channels[i],
|
|
i + 2, adc_data->channels[i + 1]);
|
|
oled_draw_string(0, y, buf, OLED_COLOR_WHITE);
|
|
y += 10;
|
|
}
|
|
|
|
/* Draw battery voltage */
|
|
snprintf(buf, sizeof(buf), "BAT:%4dmV %3d%%",
|
|
adc_data->battery_mv,
|
|
battery_get_percent(adc_data->battery_mv));
|
|
oled_draw_string(0, y, buf, OLED_COLOR_WHITE);
|
|
}
|
|
|
|
void display_draw_telemetry(adc_data_t *adc_data)
|
|
{
|
|
char buf[32];
|
|
|
|
/* Placeholder for telemetry display */
|
|
snprintf(buf, sizeof(buf), "RSSI: -- Link: --");
|
|
oled_draw_string(0, 20, buf, OLED_COLOR_WHITE);
|
|
|
|
snprintf(buf, sizeof(buf), "RX Batt: -- mV");
|
|
oled_draw_string(0, 30, buf, OLED_COLOR_WHITE);
|
|
}
|
|
|
|
void display_show_message(const char *msg, uint16_t duration_ms)
|
|
{
|
|
oled_clear();
|
|
oled_draw_string(0, 28, msg, OLED_COLOR_WHITE);
|
|
oled_update();
|
|
vTaskDelay(pdMS_TO_TICKS(duration_ms));
|
|
}
|