Skip to content

Commit

Permalink
Merge pull request #78 from ballaswag/invert_z
Browse files Browse the repository at this point in the history
* Z axis icons, flow precision
* Fix unreliable pulldown selection
* Option (setting/System) for Z+ = up-arrow
* Clean up after adding Z+ icon option
---------

Co-authored-by: ajs123 <[email protected]>
  • Loading branch information
ballaswag and ajs123 authored Apr 15, 2024
2 parents 6c7427c + d6e93ee commit 0ce2198
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ libhv.a:

libspdlog.a:
@mkdir -p $(SPDLOG_DIR)/build
@cmake -B $(SPDLOG_DIR)/build -S $(SPDLOG_DIR)/
@cmake -B $(SPDLOG_DIR)/build -S $(SPDLOG_DIR)/ -DCMAKE_CXX_COMPILER=$(CXX)
$(MAKE) -C $(SPDLOG_DIR)/build -j$(nproc)

wpaclient:
Expand Down
1 change: 0 additions & 1 deletion lv_touch_calibration/lv_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ lv_point_t lv_tc_transform_point(lv_point_t point) {
}

if (disp->driver->rotated == LV_DISP_ROT_180) {
lv_coord_t tmp = transformedPoint.y;
transformedPoint.y = lv_disp_get_ver_res(NULL) - transformedPoint.y;
transformedPoint.x = lv_disp_get_hor_res(NULL) - transformedPoint.x;
}
Expand Down
4 changes: 4 additions & 0 deletions src/button_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ void ButtonContainer::hide() {
lv_obj_add_flag(btn_cont, LV_OBJ_FLAG_HIDDEN);
}

void ButtonContainer::set_image(const void *img) {
lv_imgbtn_set_src(btn, LV_IMGBTN_STATE_RELEASED, NULL, img, NULL);
}

void ButtonContainer::handle_callback(lv_event_t *e) {
const lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_PRESSED) {
Expand Down
2 changes: 2 additions & 0 deletions src/button_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ButtonContainer {
void enable();
void hide();

void set_image(const void *img);

void handle_callback(lv_event_t *event);

void handle_prompt();
Expand Down
14 changes: 14 additions & 0 deletions src/finetune_panel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "finetune_panel.h"
#include "state.h"
#include "spdlog/spdlog.h"
#include "config.h"

#include <algorithm>

Expand Down Expand Up @@ -124,6 +125,19 @@ void FineTunePanel::foreground() {
flow_factor.update_label(fmt::format("{}%",
static_cast<int>(v.template get<double>() * 100)).c_str());
}

//Set the Z axis buttons
v = Config::get_instance()->get_json("/invert_z_icon");
bool inverted = !v.is_null() && v.template get<bool>();
if (inverted) {
// UP arrow
zup_btn.set_image(&z_farther);
zdown_btn.set_image(&z_closer);
} else {
// DOWN arrow
zup_btn.set_image(&z_closer);
zdown_btn.set_image(&z_farther);
}

lv_obj_move_foreground(panel_cont);
}
Expand Down
19 changes: 19 additions & 0 deletions src/homing_panel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "homing_panel.h"
#include "state.h"
#include "spdlog/spdlog.h"
#include "config.h"

static const float distances[] = {0.1, 0.5, 1, 5, 10, 25, 50};

Expand Down Expand Up @@ -129,6 +130,10 @@ void HomingPanel::foreground() {
y_down_btn.disable();
}

//Set the Z axis buttons
z_up_btn.set_image(&z_farther);
z_down_btn.set_image(&z_closer);

if (homed_axes.find("z") != std::string::npos) {
z_up_btn.enable();
z_down_btn.enable();
Expand All @@ -138,6 +143,20 @@ void HomingPanel::foreground() {
}
}

//Set the Z axis buttons

v = Config::get_instance()->get_json("/invert_z_icon");
bool inverted = !v.is_null() && v.template get<bool>();
if (inverted) {
// UP arrow
z_up_btn.set_image(&z_farther);
z_down_btn.set_image(&z_closer);
} else {
// DOWN arrow
z_up_btn.set_image(&z_closer);
z_down_btn.set_image(&z_farther);
}

lv_obj_move_foreground(homing_cont);
}

Expand Down
4 changes: 0 additions & 4 deletions src/homing_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ class HomingPanel : public NotifyConsumer {
ButtonContainer motoroff_btn;
ButtonContainer back_btn;
Selector distance_selector;

// lv_obj_t *selector_label;
// lv_obj_t *btnm;
// uint32_t selector_index;
};

#endif // __HOMING_PANEL_H__
6 changes: 5 additions & 1 deletion src/print_status_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ void PrintStatusPanel::update_flow_rate(double filament_used) {
flow = filament_xsection * filament_delta / delta;

spdlog::trace("caculated flow {}", flow);
flow_rate.update_label(fmt::format("{:.2f} mm3/s", flow).c_str());
#ifdef GUPPY_SMALL_SCREEN
flow_rate.update_label(fmt::format("{:.1f} mm3/s", flow).c_str());
#else
flow_rate.update_label(fmt::format("{:.2f} mm3/s", flow).c_str());
#endif
}

last_filament_used = filament_used;
Expand Down
80 changes: 59 additions & 21 deletions src/sysinfo_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ SysInfoPanel::SysInfoPanel()
// estop prompt
, estop_toggle_cont(lv_obj_create(left_cont))
, prompt_estop_toggle(lv_switch_create(estop_toggle_cont))

// Z axis icons
, z_icon_toggle_cont(lv_obj_create(left_cont))
, z_icon_toggle(lv_switch_create(z_icon_toggle_cont))

, back_btn(cont, &back, "Back", &SysInfoPanel::_handle_callback, this)
{
lv_obj_move_background(cont);
Expand Down Expand Up @@ -142,6 +147,30 @@ SysInfoPanel::SysInfoPanel()
lv_obj_add_event_cb(prompt_estop_toggle, &SysInfoPanel::_handle_callback,
LV_EVENT_VALUE_CHANGED, this);

/* Z icon selection */
lv_obj_set_size(z_icon_toggle_cont, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(z_icon_toggle_cont, 0, 0);

l = lv_label_create(z_icon_toggle_cont);
lv_label_set_text(l, "Invert Z Icon");
lv_obj_align(l, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_align(z_icon_toggle, LV_ALIGN_RIGHT_MID, 0, 0);

v = conf->get_json("/invert_z_icon");
if (!v.is_null()) {
if (v.template get<bool>()) {
lv_obj_add_state(z_icon_toggle, LV_STATE_CHECKED);
} else {
lv_obj_clear_state(z_icon_toggle, LV_STATE_CHECKED);
}
} else {
// Default is cleared
lv_obj_clear_state(z_icon_toggle, LV_STATE_CHECKED);
}

lv_obj_add_event_cb(z_icon_toggle, &SysInfoPanel::_handle_callback,
LV_EVENT_VALUE_CHANGED, this);

lv_obj_add_flag(back_btn.get_container(), LV_OBJ_FLAG_FLOATING);
lv_obj_align(back_btn.get_container(), LV_ALIGN_BOTTOM_RIGHT, 0, 0);
}
Expand All @@ -167,45 +196,54 @@ void SysInfoPanel::foreground() {
fmt::join(network_detail, "\n")).c_str());
}

void SysInfoPanel::handle_callback(lv_event_t *e) {
void SysInfoPanel::handle_callback(lv_event_t *e)
{
if (lv_event_get_code(e) == LV_EVENT_CLICKED) {
lv_obj_t *btn = lv_event_get_current_target(e);

if (btn == back_btn.get_container()) {
if (btn == back_btn.get_container())
{
lv_obj_move_background(cont);
}
} else if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
}
else if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
lv_obj_t *obj = lv_event_get_target(e);
Config *conf = Config::get_instance();
Config *conf = Config::get_instance();
if (obj == loglevel_dd) {
auto idx = lv_dropdown_get_selected(loglevel_dd);
if (idx != loglevel) {
if (loglevel < log_levels.size()) {
loglevel = idx;
auto ll = spdlog::level::from_str(log_levels[loglevel]);

spdlog::set_level(ll);
spdlog::flush_on(ll);
spdlog::debug("setting log_level to {}", log_levels[loglevel]);
conf->set<std::string>(conf->df() + "log_level", log_levels[loglevel]);
conf->save();
}
if (loglevel < log_levels.size()) {
loglevel = idx;
auto ll = spdlog::level::from_str(log_levels[loglevel]);

spdlog::set_level(ll);
spdlog::flush_on(ll);
spdlog::debug("setting log_level to {}", log_levels[loglevel]);
conf->set<std::string>(conf->df() + "log_level", log_levels[loglevel]);
conf->save();
}
}
} else if (obj == prompt_estop_toggle) {
}
else if (obj == prompt_estop_toggle) {
bool should_prompt = lv_obj_has_state(prompt_estop_toggle, LV_STATE_CHECKED);
conf->set<bool>("/prompt_emergency_stop", should_prompt);
conf->save();
} else if (obj == display_sleep_dd) {
}
else if (obj == display_sleep_dd) {
char buf[64];
lv_dropdown_get_selected_str(display_sleep_dd, buf, sizeof(buf));
std::string sleep_label = std::string(buf);
const auto &el = sleep_label_to_sec.find(sleep_label);
if (el != sleep_label_to_sec.end()) {
conf->set<int32_t>("/display_sleep_sec", el->second);
conf->save();
if (el != sleep_label_to_sec.end())
{
conf->set<int32_t>("/display_sleep_sec", el->second);
conf->save();
}
}
else if (obj == z_icon_toggle) {
bool inverted = lv_obj_has_state(z_icon_toggle, LV_STATE_CHECKED);
conf->set<bool>("/invert_z_icon", inverted);
conf->save();
}
}
}


3 changes: 3 additions & 0 deletions src/sysinfo_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class SysInfoPanel {

lv_obj_t *estop_toggle_cont;
lv_obj_t *prompt_estop_toggle;

lv_obj_t *z_icon_toggle_cont;
lv_obj_t *z_icon_toggle;

ButtonContainer back_btn;

Expand Down

0 comments on commit 0ce2198

Please sign in to comment.