Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wallpaper #424

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "core/settings.h"
#include "core/sleep_mode.h"
#include "core/thread.h"
#include "core/wallpaper.h"
#include "driver/TP2825.h"
#include "driver/beep.h"
#include "driver/dm5680.h"
Expand Down Expand Up @@ -135,6 +136,12 @@ void lvgl_init() {
false, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(64, 64, 64), 0);

load_wallpaper(WALLPAPER_PATH);
if (wallpaper_is_used()) {
lv_obj_t *img_obj = lv_img_create(lv_scr_act());
lv_img_set_src(img_obj, &img_menu_bg);
}
}

int main(int argc, char *argv[]) {
Expand Down
7 changes: 6 additions & 1 deletion src/core/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ extern "C" {
#define OSD_BOUNDRY_0 0
#define OSD_BOUNDRY_1 6

#ifdef EMULATOR_BUILD
#define WALLPAPER_PATH "wallpaper.bmp"
#else
#define WALLPAPER_PATH "/mnt/extsd/resource/OSD/GOGGLE/wallpaper.bmp"
#endif

typedef enum {
OSD_RESOURCE_720 = 0,
OSD_RESOURCE_1080,
Expand Down Expand Up @@ -101,7 +107,6 @@ void load_fc_osd_font(uint8_t);
void *thread_osd(void *ptr);
void osd_resource_path(char *buf, const char *fmt, osd_resource_t osd_resource_type, ...);
void osd_toggle();

#ifdef __cplusplus
}
#endif
90 changes: 90 additions & 0 deletions src/core/wallpaper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

#include <log/log.h>
#include <lvgl/lvgl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

#include "core/common.hh"
#include "osd.h"
#include "wallpaper.h"

static uint32_t img_menu_bg_data[1920 * 1080]; // 0x00BBGGRR
lv_img_dsc_t img_menu_bg;
static uint8_t wallpaper_state = 0;

int load_bmp_image(const char *file, uint32_t *obuf, int width, int height) {
char *buf;
struct stat stFile;
FILE *fd;
int size, rd;
int line_size;

fd = fopen(file, "rb");
if (fd == NULL) {
LOGE("%s cannot open", file);
return 0;
}

// get file size
fseek(fd, 0, SEEK_END);
size = ftell(fd);
fseek(fd, 0, SEEK_SET);

buf = (unsigned char *)malloc(size);
if (buf == NULL) {
LOGE("%s error 1", file);
return 0;
}

rd = fread(buf, 1, size, fd);
if (rd != size) {
LOGE("%s error 2", file);
free(buf);
return 0;
}

fclose(fd);

// check image size
bmpFileHead *bmp = (bmpFileHead *)buf;
char *pb = buf + sizeof(bmpFileHead) + bmp->info.biClrUsed;
if (bmp->info.biWidth != width || bmp->info.biHeight != height) {
LOGE("%s error 3", file);
free(buf);
return 0;
}

line_size = (width * 3 + 3) & 0xFFFC; // 4bytes align

int x, y;
uint32_t addr;

for (y = 0; y < height; y++) {
addr = y * line_size;
for (x = 0; x < width; x++)
obuf[(height - y - 1) * width + x] = (0xff << 24) + ((pb[addr + x * 3] & 0xff)) + ((pb[addr + x * 3 + 1] & 0xff) << 8) + ((pb[addr + x * 3 + 2] & 0xff) << 16);
}

free(buf);
return 1;
}

void load_wallpaper(char *file_path) {
if (load_bmp_image(file_path, img_menu_bg_data, 1920, 1080)) {
img_menu_bg.header.cf = LV_IMG_CF_TRUE_COLOR;
img_menu_bg.header.always_zero = 0;
img_menu_bg.header.reserved = 0;
img_menu_bg.header.w = 1920;
img_menu_bg.header.h = 1080;
img_menu_bg.data_size = 1920 * 1080 * LV_COLOR_SIZE / 8;
img_menu_bg.data = (uint8_t *)img_menu_bg_data;
wallpaper_state = 1;
}
}

uint8_t wallpaper_is_used() {
return wallpaper_state;
}
14 changes: 14 additions & 0 deletions src/core/wallpaper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void load_wallpaper(char *file_path);
uint8_t wallpaper_is_used();

extern lv_img_dsc_t img_menu_bg;

#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions src/ui/page_autoscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <minIni.h>

#include "core/settings.h"
#include "core/wallpaper.h"
#include "ui/ui_style.h"

static lv_coord_t col_dsc[] = {160, 150, 180, 220, 180, 160, LV_GRID_TEMPLATE_LAST};
Expand All @@ -21,6 +22,8 @@ static lv_obj_t *page_autoscan_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 1053, 894);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(section, LV_OPA_TRANSP, 0);

create_text(NULL, section, false, "Auto Scan:", LV_MENU_ITEM_BUILDER_VARIANT_2);

Expand All @@ -30,6 +33,8 @@ static lv_obj_t *page_autoscan_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_style(cont, &style_context, LV_PART_MAIN);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(cont, LV_OPA_50, 0);

lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/ui/page_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "core/common.hh"
#include "core/settings.h"
#include "core/wallpaper.h"
#include "driver/rtc.h"
#include "ui/page_common.h"
#include "ui/ui_attribute.h"
Expand Down Expand Up @@ -353,6 +354,8 @@ static lv_obj_t *page_clock_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 1053, 894);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(section, LV_OPA_TRANSP, 0);

create_text(NULL, section, false, "Clock:", LV_MENU_ITEM_BUILDER_VARIANT_2);

Expand All @@ -362,6 +365,8 @@ static lv_obj_t *page_clock_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_style(cont, &style_context, LV_PART_MAIN);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(cont, LV_OPA_50, 0);

lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/ui/page_elrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "core/common.hh"
#include "core/elrs.h"
#include "core/settings.h"
#include "core/wallpaper.h"
#include "driver/esp32.h"
#include "page_version.h"
#include "ui/ui_style.h"
Expand Down Expand Up @@ -79,6 +80,8 @@ static lv_obj_t *page_elrs_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 1053, 894);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(section, LV_OPA_TRANSP, 0);

create_text(NULL, section, false, "ELRS:", LV_MENU_ITEM_BUILDER_VARIANT_2);

Expand All @@ -88,6 +91,8 @@ static lv_obj_t *page_elrs_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_style(cont, &style_context, LV_PART_MAIN);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(cont, LV_OPA_50, 0);

lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/ui/page_fans.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "core/app_state.h"
#include "core/common.hh"
#include "core/settings.h"
#include "core/wallpaper.h"
#include "driver/fans.h"
#include "driver/nct75.h"
#include "ui/page_common.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ static lv_obj_t *page_fans_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 1053, 894);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(section, LV_OPA_TRANSP, 0);

create_text(NULL, section, false, "Fans:", LV_MENU_ITEM_BUILDER_VARIANT_2);

Expand All @@ -59,6 +62,8 @@ static lv_obj_t *page_fans_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_style(cont, &style_context, LV_PART_MAIN);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(cont, LV_OPA_50, 0);

lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);
Expand Down
3 changes: 3 additions & 0 deletions src/ui/page_focus_chart.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "core/osd.h"
#include "core/settings.h"
#include "core/wallpaper.h"
#include "ui/ui_porting.h"

static lv_obj_t *focus_chart_img;
Expand All @@ -18,6 +19,8 @@ lv_obj_t *page_focus_chart_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 1053, 894);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(section, LV_OPA_TRANSP, 0);

create_text(NULL, section, false, "Focus Chart:", LV_MENU_ITEM_BUILDER_VARIANT_2);

Expand Down
5 changes: 5 additions & 0 deletions src/ui/page_headtracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common.hh"
#include "core/app_state.h"
#include "core/settings.h"
#include "core/wallpaper.h"
#include "ht.h"
#include "page_common.h"
#include "ui/ui_style.h"
Expand Down Expand Up @@ -140,6 +141,8 @@ static lv_obj_t *page_headtracker_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 1053, 894);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(section, LV_OPA_TRANSP, 0);

create_text(NULL, section, false, "Head Tracker:", LV_MENU_ITEM_BUILDER_VARIANT_2);

Expand All @@ -149,6 +152,8 @@ static lv_obj_t *page_headtracker_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_style(cont, &style_context, LV_PART_MAIN);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(cont, LV_OPA_50, 0);

lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/ui/page_imagesettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "core/app_state.h"
#include "core/common.hh"
#include "core/settings.h"
#include "core/wallpaper.h"
#include "driver/hardware.h"
#include "driver/oled.h"
#include "ui/page_common.h"
Expand Down Expand Up @@ -35,6 +36,8 @@ static lv_obj_t *page_imagesettings_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 1053, 894);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(section, LV_OPA_TRANSP, 0);

create_text(NULL, section, false, "Image Setting:", LV_MENU_ITEM_BUILDER_VARIANT_2);

Expand All @@ -44,6 +47,8 @@ static lv_obj_t *page_imagesettings_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_style(cont, &style_context, LV_PART_MAIN);
if (wallpaper_is_used())
lv_obj_set_style_bg_opa(cont, LV_OPA_50, 0);

lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);
Expand Down
Loading