From dfa1641ad63025daff52c476eca01a8973c4fbff Mon Sep 17 00:00:00 2001 From: asypost Date: Mon, 27 Apr 2026 20:59:06 +0800 Subject: [PATCH] first commit --- assets/battery.png | Bin 0 -> 707 bytes bike.c | 132 ++++++++++++++++++++++++++++++++++++++++++++ bike.h | 17 ++++++ generated/battery.c | 50 +++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 assets/battery.png create mode 100644 bike.c create mode 100644 bike.h create mode 100644 generated/battery.c diff --git a/assets/battery.png b/assets/battery.png new file mode 100644 index 0000000000000000000000000000000000000000..691f92a292b3509c353daa5ed28e6f190a4b3301 GIT binary patch literal 707 zcmV;!0zCbRP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0$52zK~zXf?Uyl6 z6hRcn-^|YJaB5ry@mQ)0f_72>(uqeWg<4>uR%$>nhYk1ZG86pg_BGs_3D#7N_u*_-8Zl2 zv9-080|1PVPZXza2zLaNOWUkqXGax2+;-xt_S8-Er~{>q__791pxTAy9=)C21XKT@3>gW ze*UBzh5=Gal^Amk= z?ChMZ&SK1q){F}r8XC3=g+krrY}>}k$tl^`)cnVAN|^62$uv#7v-2{)JvitHA!-t@ pl~O93&6eLSEk(Aszy9@=`3c{8-q8?w`yT)R002ovPDHLkV1l`DL&N|8 literal 0 HcmV?d00001 diff --git a/bike.c b/bike.c new file mode 100644 index 0000000..e5e3248 --- /dev/null +++ b/bike.c @@ -0,0 +1,132 @@ +#include "bike.h" + +static lv_obj_t* container = NULL; + +static lv_theme_t* theme_original; +static const uint32_t bg_color = 0x040507; +static int32_t battery_percent = 15; + +static lv_obj_t* battery_indicator = NULL; +static lv_obj_t* battery_label = NULL; + +static void update_battery_indicator() { + lv_label_set_text_fmt(battery_label, "%d%%", battery_percent); + lv_obj_set_width(battery_indicator, lv_pct(max(battery_percent, 10))); + if (battery_percent >= 60) { + lv_obj_set_style_bg_color(battery_indicator, lv_color_hex(0x00ff00), 0); + } + else if (battery_percent >= 20) { + lv_obj_set_style_bg_color(battery_indicator, lv_color_hex(0xffff00), 0); + } + else { + lv_obj_set_style_bg_color(battery_indicator, lv_color_hex(0xff0000), 0); + } +} + +static void battery_timer_cb(lv_timer_t* timer) { + battery_percent -= 1; + if (battery_percent < 0) + { + battery_percent = 100; + } + update_battery_indicator(); + +} + +static void create_header() { + //header + lv_obj_t* header = lv_obj_create(container); + lv_obj_set_size(header, lv_pct(100), 30); + lv_obj_set_style_bg_color(header, lv_color_hex(bg_color), 0); + lv_obj_set_style_border_side(header, LV_BORDER_SIDE_BOTTOM, 0); + lv_obj_set_flex_align(header, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + lv_obj_set_layout(header, LV_LAYOUT_FLEX); + lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW); + lv_obj_set_style_pad_all(header, 4, 0); + lv_obj_set_style_border_color(header, lv_color_hex(0x191B1D), 0); + lv_obj_set_style_border_width(header, 1, 0); + + //time + lv_obj_t* time_bar = lv_label_create(header); + lv_obj_set_style_bg_color(time_bar, lv_color_hex(bg_color), 0); + lv_label_set_text(time_bar, "12:35"); + lv_obj_set_style_text_color(time_bar, lv_color_hex(0xffffff), 0); + + //gap + lv_obj_t* gap_bar = lv_obj_create(header); + lv_obj_set_size(gap_bar, LV_SIZE_CONTENT, lv_pct(100)); + lv_obj_set_flex_grow(gap_bar, 1); + lv_obj_set_style_bg_color(gap_bar, lv_color_hex(bg_color), 0); + + //battery + //icon + LV_IMG_DECLARE(battery); + lv_obj_t* battery_container = lv_obj_create(header); + lv_obj_set_style_bg_img_src(battery_container, &battery, 0); + lv_obj_set_size(battery_container, 26, 16); + lv_obj_set_style_margin_right(battery_container, 4, 0); + + lv_obj_set_style_pad_all(battery_container, 2, 0); + lv_obj_set_style_pad_left(battery_container, 3, 0); + lv_obj_set_style_pad_right(battery_container, 6, 0); + + battery_indicator = lv_obj_create(battery_container); + lv_obj_set_size(battery_indicator, lv_pct(battery_percent), lv_pct(90)); + lv_obj_set_style_radius(battery_indicator, 2, 0); + lv_obj_set_align(battery_indicator, LV_ALIGN_LEFT_MID); + + + battery_label = lv_label_create(header); + lv_obj_set_style_bg_color(battery_label, lv_color_hex(bg_color), 0); + lv_obj_set_size(battery_label, 40, LV_SIZE_CONTENT); + lv_obj_set_style_text_color(battery_label, lv_color_hex(0xffffff), 0); + + update_battery_indicator(); + + lv_obj_t* timer = lv_timer_create(battery_timer_cb, 3 * 1000, NULL); +} + +void bike_init(lv_obj_t* parent) { + //assert(container == NULL); + + lv_display_t* display = lv_display_get_default(); + theme_original = lv_display_get_theme(display); + lv_theme_t* theme = lv_theme_simple_init(display); + lv_display_set_theme(display, theme); + + container = lv_obj_create(parent); + lv_obj_set_size(container, lv_pct(100), lv_pct(100)); + lv_obj_align(container, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_flex_flow(container, LV_FLEX_FLOW_COLUMN); + lv_obj_set_layout(container, LV_LAYOUT_FLEX); + lv_obj_set_style_bg_color(container, lv_color_hex(bg_color), 0); + + + create_header(); + + //内容 + lv_obj_t* content = lv_obj_create(container); + lv_obj_set_size(content, lv_pct(100), LV_SIZE_CONTENT); + + lv_obj_set_style_bg_color(content, lv_color_hex(bg_color), 0); + lv_obj_set_style_margin_top(content, 5, 0); + lv_obj_set_flex_grow(content, 1); + + + //底部 + lv_obj_t* footer = lv_obj_create(container); + lv_obj_set_size(footer, lv_pct(100), 30); + lv_obj_set_style_bg_color(footer, lv_color_hex(bg_color), 0); + lv_obj_set_style_margin_top(footer, 5, 0); + lv_obj_set_style_border_side(footer, LV_BORDER_SIDE_FULL, 0); + lv_obj_set_style_border_color(footer, lv_color_hex(0x191B1D), 0); + lv_obj_set_style_border_width(footer, 1, 0); + +} + +void bike_deinit() { + if (container) { + lv_obj_delete(container); + container = NULL; + } +} diff --git a/bike.h b/bike.h new file mode 100644 index 0000000..7a5422e --- /dev/null +++ b/bike.h @@ -0,0 +1,17 @@ +#pragma once + +#include "../lv_demos.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + + void bike_init(lv_obj_t* parent); + + void bike_deinit(); + + +#ifdef __cplusplus +} +#endif // __cplusplus + diff --git a/generated/battery.c b/generated/battery.c new file mode 100644 index 0000000..4fc1d59 --- /dev/null +++ b/generated/battery.c @@ -0,0 +1,50 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) + #include "lvgl.h" +#else + #include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMAGE_BATTERY +#define LV_ATTRIBUTE_IMAGE_BATTERY +#endif + +const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMAGE_BATTERY uint8_t battery_map[] = { + 0x21, 0x08, 0xe4, 0x20, 0x0c, 0x63, 0x55, 0xad, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0x38, 0xc6, 0xd7, 0xbd, 0xcf, 0x7b, 0x86, 0x31, 0x41, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, + 0xe4, 0x18, 0x38, 0xc6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1c, 0xe7, 0x29, 0x42, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, + 0xaf, 0x7b, 0xff, 0xff, 0xd7, 0xbd, 0x45, 0x29, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xa3, 0x10, 0xc3, 0x18, 0x31, 0x8c, 0xdf, 0xff, 0x18, 0xc6, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, + 0xd7, 0xbd, 0xff, 0xff, 0x25, 0x21, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x41, 0x08, 0x59, 0xce, 0x5d, 0xef, 0xe4, 0x18, 0x21, 0x08, 0x21, 0x08, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xb7, 0xbd, 0xff, 0xff, 0x25, 0x21, 0x21, 0x08, 0x21, 0x08, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xb7, 0xbd, 0xff, 0xff, 0xf4, 0x9c, 0x71, 0x8c, 0xc7, 0x39, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xb7, 0xbd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x76, 0xad, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xb7, 0xbd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb7, 0xbd, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xb7, 0xbd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb7, 0xbd, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xb7, 0xbd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf4, 0xa4, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xb7, 0xbd, 0xff, 0xff, 0x72, 0x8c, 0x0c, 0x63, 0xe4, 0x20, + 0x38, 0xc6, 0xff, 0xff, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0xd7, 0xbd, 0xff, 0xff, 0x25, 0x29, 0x41, 0x08, 0x21, 0x08, + 0x76, 0xb5, 0xff, 0xff, 0xa7, 0x31, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x82, 0x10, 0xfc, 0xe6, 0x5d, 0xef, 0xe4, 0x18, 0x21, 0x08, 0x21, 0x08, + 0x2d, 0x63, 0xff, 0xff, 0x9a, 0xd6, 0x49, 0x4a, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xc7, 0x39, 0xe8, 0x39, 0x14, 0xa5, 0xff, 0xff, 0x76, 0xad, 0x82, 0x10, 0x21, 0x08, 0x21, 0x08, + 0xa3, 0x18, 0xf4, 0xa4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0xc6, 0x86, 0x31, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, + 0x21, 0x08, 0x82, 0x10, 0x29, 0x4a, 0xf3, 0x9c, 0xb7, 0xb5, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0xb7, 0xbd, 0x76, 0xb5, 0x0c, 0x63, 0xc3, 0x18, 0x41, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, +}; + +const lv_image_dsc_t battery = { + .header.cf = LV_COLOR_FORMAT_RGB565, + .header.magic = LV_IMAGE_HEADER_MAGIC, + .header.w = 26, + .header.h = 16, + .data_size = 416 * 2, + .data = battery_map, +};