Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ballaswag/guppyscreen into …
Browse files Browse the repository at this point in the history
…power_devices
  • Loading branch information
kevdliu committed Apr 22, 2024
2 parents 1f7dcaf + 8b88d6a commit 364c33c
Show file tree
Hide file tree
Showing 20 changed files with 549 additions and 345 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/guppydroid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: guppydroid build

on:
push:
branches: [ "develop", "main", "android" ]
tags:
- "*"

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
with:
ref: android

- uses: actions/checkout@v3
with:
ref: main
submodules: true
path: ./app/src/main/cpp/guppyscreen

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Setup signing
env:
ENCODED_KS: ${{ secrets.KEYSTORE }}
run: |
echo $ENCODED_KS > ks.txt
base64 -d ks.txt > ks.jks
- name: Build APK
env:
KEYSTORE: ../ks.jks
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: ./gradlew assembleRelease

- name: nightly release
uses: softprops/action-gh-release@v2
with:
prerelease: true
name: nightly
tag_name: nightly
files: app/build/outputs/apk/release/app-release.apk
fail_on_unmatched_files: true

- name: stable release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: app/build/outputs/apk/release/app-release.apk
generate_release_notes: true
fail_on_unmatched_files: true

96 changes: 49 additions & 47 deletions src/config.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "config.h"
#include "platform.h"

#include <sys/stat.h>
#include <fstream>
Expand All @@ -19,7 +20,7 @@ Config *Config::get_instance() {
return instance;
}

void Config::init(std::string config_path) {
void Config::init(std::string config_path, const std::string thumbdir) {
path = config_path;
struct stat buffer;
json fans_conf = {
Expand Down Expand Up @@ -66,62 +67,63 @@ void Config::init(std::string config_path) {

if (stat(config_path.c_str(), &buffer) == 0) {
data = json::parse(std::fstream(config_path));

} else {
data = {
{"default_printer", "k1"},
{"log_path", "/usr/data/printer_data/logs/guppyscreen.log"},
{"thumbnail_path", "/usr/data/printer_data/thumbnails"},
{"wpa_supplicant", "/var/run/wpa_supplicant"},
{"display_sleep_sec", 600},
{"printers", {{
"k1", {
{"moonraker_api_key", false},
{"moonraker_host", "127.0.0.1"},
{"moonraker_port", 7125},
{"monitored_sensors", sensors_conf},
{"fans", fans_conf},
{"default_macros", default_macros_conf},
}
}}
}
{"log_path", "/usr/data/printer_data/logs/guppyscreen.log"},
{"thumbnail_path", thumbdir},
{"wpa_supplicant", "/var/run/wpa_supplicant"},
{"display_sleep_sec", 600}
#ifndef OS_ANDROID
, {"default_printer", "k1"},
{"printers", {{"k1", {
{"moonraker_api_key", false},
{"moonraker_host", "127.0.0.1"},
{"moonraker_port", 7125},
{"monitored_sensors", sensors_conf},
{"fans", fans_conf},
{"default_macros", default_macros_conf},
}}}
}
#endif
};

}

std::string df_name = data["/default_printer"_json_pointer];
default_printer = "/printers/" + df_name + "/";

auto &monitored_sensors = data[json::json_pointer(df() + "monitored_sensors")];
if (monitored_sensors.is_null()) {
data[json::json_pointer(df() + "monitored_sensors")] = sensors_conf;
}
data["config_path"] = config_path;

auto &fans = data[json::json_pointer(df() + "fans")];
if (fans.is_null()) {
data[json::json_pointer(df() + "fans")] = fans_conf;
}
auto df_name = data["/default_printer"_json_pointer];
if (!df_name.is_null()) {
default_printer = "/printers/" + df_name.template get<std::string>() + "/";

auto &default_macros = data[json::json_pointer(df() + "default_macros")];
if (default_macros.is_null()) {
default_macros_conf.merge_patch(cooldown_conf);
data[json::json_pointer(df() + "default_macros")] = default_macros_conf;
} else {
if (!default_macros.contains("cooldown")) {
default_macros.merge_patch(cooldown_conf);
auto &monitored_sensors = data[json::json_pointer(df() + "monitored_sensors")];
if (monitored_sensors.is_null()) {
data[json::json_pointer(df() + "monitored_sensors")] = sensors_conf;
}
}

auto &guppy_init = data["/guppy_init_script"_json_pointer];
if (guppy_init.is_null()) {
data["/guppy_init_script"_json_pointer] = "/etc/init.d/S99guppyscreen";
}

auto &ll = data[json::json_pointer(df() + "log_level")];
if (ll.is_null()) {
data[json::json_pointer(df() + "log_level")] = "debug";
}
auto &fans = data[json::json_pointer(df() + "fans")];
if (fans.is_null()) {
data[json::json_pointer(df() + "fans")] = fans_conf;
}

auto &default_macros = data[json::json_pointer(df() + "default_macros")];
if (default_macros.is_null()) {
default_macros_conf.merge_patch(cooldown_conf);
data[json::json_pointer(df() + "default_macros")] = default_macros_conf;
} else {
if (!default_macros.contains("cooldown")) {
default_macros.merge_patch(cooldown_conf);
}
}

auto &guppy_init = data["/guppy_init_script"_json_pointer];
if (guppy_init.is_null()) {
data["/guppy_init_script"_json_pointer] = "/etc/init.d/S99guppyscreen";
}

auto &ll = data[json::json_pointer(df() + "log_level")];
if (ll.is_null()) {
data[json::json_pointer(df() + "log_level")] = "debug";
}
}
auto &rotate = data["/display_rotate"_json_pointer];
if (rotate.is_null()) {
#ifdef GUPPY_ROTATE
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Config {
Config();
Config(Config &o) = delete;
void operator=(const Config &) = delete;
void init(std::string config_path);
void init(std::string config_path, const std::string thumbdir);

template<typename T> T get(const std::string &json_ptr) {
return data[json::json_pointer(json_ptr)].template get<T>();
Expand Down
25 changes: 14 additions & 11 deletions src/extruder_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ ExtruderPanel::ExtruderPanel(KWebSocketClient &websocket_client,
, cooldown_macro("SET_HEATER_TEMPERATURE HEATER=extruder TARGET=0")
{
Config *conf = Config::get_instance();
auto v = conf->get_json(conf->df() + "default_macros/load_filament");
if (!v.is_null()) {
load_filament_macro = v.template get<std::string>();
}
auto df = conf->get_json("/default_printer");
if (!df.empty()) {
auto v = conf->get_json(conf->df() + "default_macros/load_filament");
if (!v.is_null()) {
load_filament_macro = v.template get<std::string>();
}

v = conf->get_json(conf->df() + "default_macros/unload_filament");
if (!v.is_null()) {
unload_filament_macro = v.template get<std::string>();
}
v = conf->get_json(conf->df() + "default_macros/unload_filament");
if (!v.is_null()) {
unload_filament_macro = v.template get<std::string>();
}

v = conf->get_json(conf->df() + "default_macros/cooldown");
if (!v.is_null()) {
cooldown_macro = v.template get<std::string>();
v = conf->get_json(conf->df() + "default_macros/cooldown");
if (!v.is_null()) {
cooldown_macro = v.template get<std::string>();
}
}

lv_obj_move_background(panel_cont);
Expand Down
Loading

0 comments on commit 364c33c

Please sign in to comment.