Skip to content

Commit

Permalink
Option (setting/System) for Z+ = up-arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs123 committed Apr 15, 2024
1 parent 9542661 commit 3c25b5c
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 35 deletions.
6 changes: 5 additions & 1 deletion src/button_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "spdlog/spdlog.h"

ButtonContainer::ButtonContainer(lv_obj_t *parent,
const void *btn_img,
const void *btn_img, //If chabgeable, should be non-const
const char *text,
lv_event_cb_t cb,
void* user_data,
Expand Down 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
23 changes: 18 additions & 5 deletions src/finetune_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ FineTunePanel::FineTunePanel(KWebSocketClient &websocket_client, std::mutex &l)
, panel_cont(lv_obj_create(lv_scr_act()))
, values_cont(lv_obj_create(panel_cont))
, zreset_btn(panel_cont, &refresh_img, "Reset Z", &FineTunePanel::_handle_zoffset, this)
#ifdef Z_PLUS_UPARROW
, zup_btn(panel_cont, &z_farther, "Z+", &FineTunePanel::_handle_zoffset, this)
, zdown_btn(panel_cont, &z_closer, "Z-", &FineTunePanel::_handle_zoffset, this)
#else
, zup_btn(panel_cont, &z_closer, "Z+", &FineTunePanel::_handle_zoffset, this)
, zdown_btn(panel_cont, &z_farther, "Z-", &FineTunePanel::_handle_zoffset, this)
#endif
, pareset_btn(panel_cont, &refresh_img, "Reset PA", &FineTunePanel::_handle_pa, this)
, paup_btn(panel_cont, &pa_plus_img, "PA+", &FineTunePanel::_handle_pa, this)
, padown_btn(panel_cont, &pa_minus_img, "PA-", &FineTunePanel::_handle_pa, this)
Expand Down Expand Up @@ -93,6 +88,8 @@ FineTunePanel::FineTunePanel(KWebSocketClient &websocket_client, std::mutex &l)
lv_obj_set_grid_cell(back_btn.get_container(), LV_GRID_ALIGN_CENTER, 4, 1, LV_GRID_ALIGN_CENTER, 3, 1);

ws.register_notify_update(this);

conf = Config::get_instance();
}

FineTunePanel::~FineTunePanel() {
Expand Down Expand Up @@ -129,6 +126,22 @@ 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 = conf->get_json("/z_plus_uparrow");
bool uparrow = false;
if (!v.is_null()) {
uparrow = v.template get<bool>();
}
if (uparrow) {
// 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
3 changes: 3 additions & 0 deletions src/finetune_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "image_label.h"
#include "websocket_client.h"
#include "notify_consumer.h"
#include "sysinfo_panel.h"
#include "config.h"

#include <mutex>

Expand Down Expand Up @@ -71,6 +73,7 @@ class FineTunePanel : public NotifyConsumer {
ImageLabel pa;
ImageLabel speed_factor;
ImageLabel flow_factor;
Config *conf;
};

#endif // __FINETINE_PANEL_H__
26 changes: 21 additions & 5 deletions src/homing_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ HomingPanel::HomingPanel(KWebSocketClient &websocket_client, std::mutex &lock)
, y_down_btn(homing_cont, &arrow_down, "Y-", &HomingPanel::_handle_callback, this)
, x_up_btn(homing_cont, &arrow_right, "X+", &HomingPanel::_handle_callback, this)
, x_down_btn(homing_cont, &arrow_left, "X-", &HomingPanel::_handle_callback, this)
#ifdef Z_PLUS_UPARROW
, z_up_btn(homing_cont, &z_farther, "Z+", &HomingPanel::_handle_callback, this)
, z_down_btn(homing_cont, &z_closer, "Z-", &HomingPanel::_handle_callback, this)
#else
, z_up_btn(homing_cont, &z_closer, "Z+", &HomingPanel::_handle_callback, this)
, z_down_btn(homing_cont, &z_farther, "Z-", &HomingPanel::_handle_callback, this)
#endif
, emergency_btn(homing_cont, &emergency, "Stop", &HomingPanel::_handle_callback, this,
"Do you want to emergency stop?",
[&websocket_client]() {
Expand Down Expand Up @@ -134,6 +129,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 @@ -143,6 +142,23 @@ void HomingPanel::foreground() {
}
}

//Set the Z axis buttons
conf = Config::get_instance();
v = conf->get_json("/z_plus_uparrow");
bool uparrow = false;
if (!v.is_null()) {
uparrow = v.template get<bool>();
}
if (uparrow) {
// 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
3 changes: 3 additions & 0 deletions src/homing_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "websocket_client.h"
#include "selector.h"
#include "notify_consumer.h"
#include "config.h"

#include <mutex>

Expand Down Expand Up @@ -45,6 +46,8 @@ class HomingPanel : public NotifyConsumer {
ButtonContainer motoroff_btn;
ButtonContainer back_btn;
Selector distance_selector;
Config *conf;


// lv_obj_t *selector_label;
// lv_obj_t *btnm;
Expand Down
99 changes: 75 additions & 24 deletions src/sysinfo_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ static std::map<std::string, uint32_t> sleep_label_to_sec = {
{"5 Hours", 18000} // 5 hour
};

std::vector<std::string> SysInfoPanel::z_plus_types = {
"UP arrow",
"DOWN arrow"
};

SysInfoPanel::SysInfoPanel()
: cont(lv_obj_create(lv_scr_act()))
, left_cont(lv_obj_create(cont))
Expand All @@ -56,6 +61,11 @@ SysInfoPanel::SysInfoPanel()
, estop_toggle_cont(lv_obj_create(left_cont))
, prompt_estop_toggle(lv_switch_create(estop_toggle_cont))
, back_btn(cont, &back, "Back", &SysInfoPanel::_handle_callback, this)

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

{
lv_obj_move_background(cont);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
Expand Down Expand Up @@ -142,6 +152,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, "Z+ UP-arrow");
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("/z_plus_uparrow");
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 +201,62 @@ void SysInfoPanel::foreground() {
fmt::join(network_detail, "\n")).c_str());
}

void SysInfoPanel::handle_callback(lv_event_t *e) {
if (lv_event_get_code(e) == LV_EVENT_CLICKED) {
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();
if (obj == loglevel_dd) {
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 (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();
}
}
} 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 use_up = lv_obj_has_state(z_icon_toggle, LV_STATE_CHECKED);
conf->set<bool>("/z_plus_uparrow", use_up);
conf->save();
}
}
}


10 changes: 10 additions & 0 deletions src/sysinfo_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <vector>
#include <string>

const std::vector<std::string> z_plus_types = {
"UP arrow",
"DOWN arrow"
};

class SysInfoPanel {
public:
SysInfoPanel();
Expand Down Expand Up @@ -35,10 +40,15 @@ 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;

static std::vector<std::string> log_levels;

static std::vector<std::string> z_plus_types;

};

Expand Down

0 comments on commit 3c25b5c

Please sign in to comment.