Add version to settings

This commit is contained in:
suchmememanyskill
2024-02-09 21:06:23 +01:00
parent 452dbefbdb
commit 15209544d0
4 changed files with 40 additions and 5 deletions

View File

@@ -4,7 +4,7 @@ permissions:
pages: write
id-token: write
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
jobs:
build:
@@ -45,7 +45,7 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
steps:
- name: Print GitHub event name
run: |

View File

@@ -0,0 +1,23 @@
import subprocess
def extract_commit() -> tuple[str, str]: # Version, Commit
git_describe_output = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE, text=True, check=True).stdout.strip()
split_output = git_describe_output.split("-")
return split_output[0], split_output[2][1:]
try:
data = extract_commit()
version = f"{data[0]}\\ ({data[1]})"
except:
version = "Unknown"
flag = "-D REPO_VERSION=\\\"" + version + "\\\""
print(f"Version: {version}")
print(f"Flag: {flag}")
Import("env")
env.Append(
BUILD_FLAGS=[flag]
)

View File

@@ -20,6 +20,8 @@ lib_deps =
monitor_filters = esp32_exception_decoder
build_flags =
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
extra_scripts =
pre:extract_commit.py
[env:esp32-2432S028R]
board = esp32-2432S028R

View File

@@ -7,6 +7,10 @@
#include <Esp.h>
#include "../../core/lv_setup.h"
#ifndef REPO_VERSION
#define REPO_VERSION "Unknown"
#endif // REPO_VERSION
static void invert_color_switch(lv_event_t * e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
@@ -85,9 +89,7 @@ static void on_during_print_switch(lv_event_t* e){
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel){
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true){
lv_obj_t * panel = lv_create_empty_panel(root_panel);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
@@ -98,6 +100,9 @@ void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t*
lv_obj_set_parent(object, panel);
lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0);
if (set_height)
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * line = lv_line_create(root_panel);
lv_line_set_points(line, line_points, 2);
lv_obj_set_style_line_width(line, 1, 0);
@@ -204,4 +209,9 @@ void settings_panel_init(lv_obj_t* panel){
create_settings_widget("Screen On During Print", toggle, panel);
#endif
label = lv_label_create_ex(panel);
lv_label_set_text(label, REPO_VERSION " ");
create_settings_widget("Version", label, panel, false);
}