OreBolt-OS/include/h2_ui.h

174 lines
5.4 KiB
C
Executable File

/*
* h2_ui.h -- OreBolt OS shared UI header
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* Modules compiled as standalone .mod binaries call
* init_h2_graphics_runtime() in their main(). The launcher (h2_test)
* uses the module metadata table to build the menu and fork/exec each
* selected module.
*
* Display: 320x240 RGB565 via /dev/fb0 (fbdev driver)
* Input: Rotary encoder via /dev/input/event0 (evdev driver, encoder type)
*/
#ifndef H2_UI_H
#define H2_UI_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ================================================================== */
/* Module Registration API (used by launcher main.c) */
/* ================================================================== */
typedef enum {
H2_MOD_VAULT = 0,
H2_MOD_NETTAP,
H2_MOD_SCALPEL,
H2_MOD_DEPLOY,
H2_MOD_STUDIO,
H2_MOD_PROBE,
H2_MOD_VTERM,
H2_MOD_PAUTO,
H2_MOD_EXTRACT,
H2_MOD_NOISE,
H2_MOD_RESET,
H2_MOD_RETRO,
H2_MOD_RETRO_INPUT_MAPPER,
H2_MOD_RFID,
H2_MOD_GLITCH,
H2_MOD_PWDB,
H2_MOD_PROXALARM,
H2_MOD_BITCHAT,
H2_MOD_COUNT
} H2_MODULE_ID;
typedef struct {
H2_MODULE_ID id;
const char *name;
const char *version;
const char *license;
const char *mod_binary; /* filename in /apps/ for fork/exec */
} h2_module_t;
int h2_ui_register_module(const h2_module_t *mod);
void h2_ui_unregister_module(H2_MODULE_ID id);
const h2_module_t *h2_ui_lookup_module(const char *name);
/* ================================================================== */
/* LCD Constants */
/* ================================================================== */
#define H2_LCD_WIDTH 320
#define H2_LCD_HEIGHT 240
#define H2_LCD_BPP 16
/* ================================================================== */
/* Color Palette (RGB565 raw + LVGL lv_color_make for modules) */
/* ================================================================== */
/* Raw RGB565 for use in styles */
#define H2_COLOR_BG 0x0000
#define H2_COLOR_FG 0xFFFF
#define H2_COLOR_ACCENT 0xFD20
#define H2_COLOR_WARN 0xFFE0
#define H2_COLOR_DANGER 0xF800
#define H2_COLOR_OK 0x07E0
/* The graphics init function below defines LVGL color objects:
* COLOR_BG = near-black lv_color_make(14, 18, 24)
* COLOR_PRIMARY = red-orange accent lv_color_make(253, 32, 0)
* COLOR_ACCENT = green status lv_color_make(0, 220, 110)
* COLOR_TEXT = near-white text lv_color_make(240, 244, 250)
* COLOR_MUTED = gray secondary lv_color_make(90, 105, 120)
* These are only available after calling init_h2_graphics_runtime().
*/
/* ================================================================== */
/* Graphics Runtime Initializer (v1.3, used by standalone modules) */
/* ================================================================== */
/*
* Include LVGL and driver headers only when building module .mod
* binaries (which call init_h2_graphics_runtime). The launcher
* also calls this for its menu, so it always needs them.
*
* Standalone daemons (e.g. retro_input_mapper) do NOT use LVGL
* and should not include this header.
*/
#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/input.h>
/* 5-color dark theme palette used across all modules */
#define COLOR_BG lv_color_make(14, 18, 24)
#define COLOR_PRIMARY lv_color_make(253, 32, 0)
#define COLOR_ACCENT lv_color_make(0, 220, 110)
#define COLOR_TEXT lv_color_make(240, 244, 250)
#define COLOR_MUTED lv_color_make(90, 105, 120)
/*
* Initialize LVGL, the Linux framebuffer display driver, and the
* rotary encoder input driver. Call once at module startup.
*
* The draw buffer is 320*16 lines (10,240 pixels = 20,480 bytes at
* RGB565). This is the partial-flush buffer -- LVGL redraws 16
* scanlines at a time to minimize tearing and memory usage.
*
* The 'module_name' parameter is reserved for future log integration
* and is currently unused.
*/
static inline void init_h2_graphics_runtime(const char *module_name) {
(void)module_name;
lv_init();
fbdev_init();
static lv_disp_draw_buf_t disp_buf;
static lv_color_t buf[320 * 16];
lv_disp_draw_buf_init(&disp_buf, buf, NULL, 320 * 16);
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &disp_buf;
disp_drv.flush_cb = fbdev_flush;
disp_drv.horizontal_res = 320;
disp_drv.vertical_res = 240;
lv_disp_drv_register(&disp_drv);
evdev_init();
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_ENCODER;
indev_drv.read_cb = evdev_read;
lv_indev_register(&indev_drv);
lv_obj_t *scr = lv_scr_act();
lv_obj_set_style_bg_color(scr, COLOR_BG, LV_PART_MAIN);
}
/* ================================================================== */
/* H2 Input Event Codes */
/* ================================================================== */
#define H2_KEY_PLAY 164
#define H2_KEY_BACK 158
#define H2_KEY_PREV 165
#define H2_KEY_NEXT 163
#define H2_ROTARY_REL 0
#define H2_ROTARY_PRESS 115
#ifdef __cplusplus
}
#endif
#endif /* H2_UI_H */