Skip to content

Commit

Permalink
Add version to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Feb 9, 2024
1 parent 452dbef commit 1520954
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ permissions:
pages: write
id-token: write

on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]

jobs:
build:
Expand Down Expand Up @@ -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: |
Expand Down
23 changes: 23 additions & 0 deletions CYD-Klipper/extract_commit.py
Original file line number Diff line number Diff line change
@@ -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]
)
2 changes: 2 additions & 0 deletions CYD-Klipper/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions CYD-Klipper/src/ui/panels/settings_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

0 comments on commit 1520954

Please sign in to comment.