Initial commit - sync AliceRC to Gitea

This commit is contained in:
2026-08-03 15:54:25 +08:00
commit 493b7d81d7
1510 changed files with 185319 additions and 0 deletions
@@ -0,0 +1,6 @@
idf_component_register(
SRCS "menu.c" "display.c"
INCLUDE_DIRS "."
REQUIRES oled driver
PRIV_REQUIRES main
)
+99
View File
@@ -0,0 +1,99 @@
/**
* @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));
}
+44
View File
@@ -0,0 +1,44 @@
/**
* @file display.h
* @brief Display manager header
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Forward declaration - actual struct defined in app_main.h */
struct adc_data_s;
typedef struct adc_data_s adc_data_t;
/* Display modes */
typedef enum {
DISPLAY_MODE_CHANNELS, /* Show channel values */
DISPLAY_MODE_TELEMETRY, /* Show telemetry data */
DISPLAY_MODE_MENU, /* Menu system */
} display_mode_t;
/* Initialize display subsystem */
void display_init(void);
/* Set display mode */
void display_set_mode(display_mode_t mode);
/* Update display with ADC data */
void display_update(adc_data_t *adc_data);
/* Draw channel data on display */
void display_draw_channels(adc_data_t *adc_data);
/* Draw telemetry data on display */
void display_draw_telemetry(adc_data_t *adc_data);
/* Show a temporary message */
void display_show_message(const char *msg, uint16_t duration_ms);
#ifdef __cplusplus
}
#endif
+115
View File
@@ -0,0 +1,115 @@
/**
* @file menu.c
* @brief Menu system implementation
*/
#include <string.h>
#include "menu.h"
/* Menu item callbacks - forward declarations */
static void menu_cb_model(void);
static void menu_cb_rf(void);
static void menu_cb_channel(void);
static void menu_cb_mixer(void);
static void menu_cb_usb(void);
static void menu_cb_audio(void);
static void menu_cb_other(void);
/* Sub-menu definitions */
static const menu_item_t menu_items_main[] = {
{"模型选择", menu_cb_model, NULL},
{"高频头配置", menu_cb_rf, NULL},
{"通道映射", menu_cb_channel, NULL},
{"混控设置", menu_cb_mixer, NULL},
{"USB设置", menu_cb_usb, NULL},
{"音频配置", menu_cb_audio, NULL},
{"其他", menu_cb_other, NULL},
{"返回", menu_back, NULL},
};
static menu_t menu_main = {
.title = "主菜单",
.items = menu_items_main,
.item_count = 8,
.current = 0,
};
/* Menu stack for navigation */
#define MENU_STACK_DEPTH 8
static menu_t *menu_stack[MENU_STACK_DEPTH];
static uint8_t menu_stack_depth = 0;
static menu_t *current_menu = &menu_main;
void menu_init(void)
{
current_menu = &menu_main;
current_menu->current = 0;
menu_stack_depth = 0;
}
void menu_up(void)
{
if (current_menu->current > 0) {
current_menu->current--;
}
}
void menu_down(void)
{
if (current_menu->current < current_menu->item_count - 1) {
current_menu->current++;
}
}
void menu_select(void)
{
const menu_item_t *item = &current_menu->items[current_menu->current];
if (item->submenu) {
/* Push to sub-menu */
if (menu_stack_depth < MENU_STACK_DEPTH) {
menu_stack[menu_stack_depth++] = current_menu;
}
current_menu = item->submenu;
current_menu->current = 0;
} else if (item->callback) {
item->callback();
}
}
void menu_back(void)
{
if (menu_stack_depth > 0) {
current_menu = menu_stack[--menu_stack_depth];
}
}
const menu_t* menu_get_current(void)
{
return current_menu;
}
const char* menu_get_current_item_name(void)
{
return current_menu->items[current_menu->current].name;
}
void menu_draw(void)
{
/* TODO: Implement OLED drawing */
/* Will display:
- Top bar: menu title
- Up to 5 visible items with cursor indicator
- Scroll indicator if more items
*/
}
/* Callback stubs */
static void menu_cb_model(void) { }
static void menu_cb_rf(void) { }
static void menu_cb_channel(void) { }
static void menu_cb_mixer(void) { }
static void menu_cb_usb(void) { }
static void menu_cb_audio(void) { }
static void menu_cb_other(void) { }
+57
View File
@@ -0,0 +1,57 @@
/**
* @file menu.h
* @brief Menu system for OLED display
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Menu item callback */
typedef void (*menu_callback_t)(void);
/* Menu item structure */
typedef struct {
const char *name; /* Display name (max 16 chars visible) */
menu_callback_t callback; /* Callback when selected */
struct menu_t *submenu; /* Sub-menu (NULL if leaf) */
} menu_item_t;
/* Menu structure */
typedef struct menu_t {
const char *title; /* Menu title */
const menu_item_t *items; /* Array of menu items */
uint8_t item_count; /* Number of items */
uint8_t current; /* Current selection index */
} menu_t;
/* Initialize menu system */
void menu_init(void);
/* Navigate up */
void menu_up(void);
/* Navigate down */
void menu_down(void);
/* Select current item */
void menu_select(void);
/* Go back to parent menu */
void menu_back(void);
/* Get current menu for display */
const menu_t* menu_get_current(void);
/* Draw current menu on OLED */
void menu_draw(void);
/* Get current menu item name */
const char* menu_get_current_item_name(void);
#ifdef __cplusplus
}
#endif