Skip to content

Commit

Permalink
fixed belt calibrate freq range. fixed mini print status/progress bar…
Browse files Browse the repository at this point in the history
…/various scaling for smaller screens. wifi save_config (still need to fix ip refresh after switching networks). add prompt for emergency stop/print cancel (can be disabled via system panel). adjustable display sleep time (never is an option now). extruder now has a target temp to reflect heating. prepare tmc tuning panel.
  • Loading branch information
ballaswag committed Jan 17, 2024
1 parent 168b992 commit 6d71018
Show file tree
Hide file tree
Showing 28 changed files with 1,318 additions and 87 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.18
0.0.19
302 changes: 302 additions & 0 deletions assets/material/motor_img.c

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions assets/material_46/motor_img.c

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions assets/material_svg/motor_img.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions src/belts_calibration_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ BeltsCalibrationPanel::BeltsCalibrationPanel(KWebSocketClient &c, std::mutex &l)
, button_cont(lv_obj_create(cont))
, calibrate_btn(button_cont, &resume, "Shake Belts", &BeltsCalibrationPanel::_handle_callback, this)
, excite_btn(button_cont, &inputshaper_img, "Excitate", &BeltsCalibrationPanel::_handle_callback, this)
, emergency_btn(button_cont, &emergency, "Stop", &BeltsCalibrationPanel::_handle_callback, this)
, emergency_btn(button_cont, &emergency, "Stop", &BeltsCalibrationPanel::_handle_callback, this,
"Do you want to emergency stop?",
[&c]() {
spdlog::debug("emergency stop pressed");
c.send_jsonrpc("printer.emergency_stop");
})
, back_btn(button_cont, &back, "Back", &BeltsCalibrationPanel::_handle_callback, this)
, image_fullsized(false)
{
Expand Down Expand Up @@ -122,11 +127,11 @@ void BeltsCalibrationPanel::handle_callback(lv_event_t *event) {

auto screen_width = (double)lv_disp_get_physical_hor_res(NULL) / 100.0;
auto screen_height = (double)lv_disp_get_physical_ver_res(NULL) / 100.0;
// ws.gcode_script(fmt::format("GUPPY_BELTS_SHAPER_CALIBRATION PNG_OUT_PATH={} PNG_WIDTH={} PNG_HEIGHT={}",
// png_path, screen_width, screen_height));

ws.gcode_script(fmt::format("GUPPY_BELTS_SHAPER_CALIBRATION PNG_OUT_PATH={} PNG_WIDTH={} PNG_HEIGHT={} FREQ_START=5 FREQ_END=10",
ws.gcode_script(fmt::format("GUPPY_BELTS_SHAPER_CALIBRATION PNG_OUT_PATH={} PNG_WIDTH={} PNG_HEIGHT={}",
png_path, screen_width, screen_height));

// ws.gcode_script(fmt::format("GUPPY_BELTS_SHAPER_CALIBRATION PNG_OUT_PATH={} PNG_WIDTH={} PNG_HEIGHT={} FREQ_START=5 FREQ_END=10",
// png_path, screen_width, screen_height));


lv_obj_add_flag(graph, LV_OBJ_FLAG_HIDDEN);
Expand Down
70 changes: 64 additions & 6 deletions src/button_container.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#include "button_container.h"
#include "config.h"
#include "spdlog/spdlog.h"
#include <string>

ButtonContainer::ButtonContainer(lv_obj_t *parent,
const void *btn_img,
const char *text,
lv_event_cb_t cb,
void* user_data)
void* user_data,
const std::string &prompt,
const std::function<void()> &pcb)
: btn_cont(lv_obj_create(parent))
, btn(lv_imgbtn_create(btn_cont))
, label(lv_label_create(btn_cont))
, prompt_text(prompt)
, prompt_callback(pcb)
{

lv_obj_set_style_pad_all(btn_cont, 0, 0);
auto width_scale = (double)lv_disp_get_physical_hor_res(NULL) / 800.0;
lv_obj_set_size(btn_cont, 150 * width_scale, LV_SIZE_CONTENT);
Expand All @@ -26,12 +29,30 @@ ButtonContainer::ButtonContainer(lv_obj_t *parent,
lv_obj_add_flag(btn, LV_OBJ_FLAG_EVENT_BUBBLE);
// lv_obj_add_flag(btn_cont, LV_OBJ_FLAG_EVENT_BUBBLE);

if (cb != NULL) {
Config *conf = Config::get_instance();
auto estop = conf->get_json("/prompt_emergency_stop");
auto prompt_estop = estop.is_null() ? false : estop.template get<bool>();

if (cb != NULL && !pcb) {
lv_obj_add_event_cb(btn_cont, &ButtonContainer::_handle_callback, LV_EVENT_PRESSED, this);
lv_obj_add_event_cb(btn_cont, &ButtonContainer::_handle_callback, LV_EVENT_RELEASED, this);

lv_obj_add_event_cb(btn_cont, cb, LV_EVENT_CLICKED, user_data);
// lv_obj_add_event_cb(btn, cb, LV_EVENT_CLICKED, user_data);
}
else if (cb != NULL && pcb) {
if (prompt_estop) {
lv_obj_add_event_cb(btn_cont, [](lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
((ButtonContainer*)e->user_data)->handle_prompt();
}
}, LV_EVENT_CLICKED, this);
} else {
lv_obj_add_event_cb(btn_cont, &ButtonContainer::_handle_callback, LV_EVENT_PRESSED, this);
lv_obj_add_event_cb(btn_cont, &ButtonContainer::_handle_callback, LV_EVENT_RELEASED, this);

lv_obj_add_event_cb(btn_cont, cb, LV_EVENT_CLICKED, user_data);
}
}

lv_label_set_text(label, text);
Expand Down Expand Up @@ -80,3 +101,40 @@ void ButtonContainer::handle_callback(lv_event_t *e) {
lv_imgbtn_set_state(btn, LV_IMGBTN_STATE_RELEASED);
}
}

void ButtonContainer::handle_prompt() {
static const char * btns[] = {"Confirm", "Cancel", ""};

lv_obj_t *mbox1 = lv_msgbox_create(NULL, NULL, prompt_text.c_str(), btns, false);
lv_obj_t *msg = ((lv_msgbox_t*)mbox1)->text;
lv_obj_set_width(msg, LV_SIZE_CONTENT);
lv_obj_center(msg);

lv_obj_t *btnm = lv_msgbox_get_btns(mbox1);
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED);
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED);
lv_obj_add_flag(btnm, LV_OBJ_FLAG_FLOATING);
lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, 0);

auto hscale = (double)lv_disp_get_physical_ver_res(NULL) / 480.0;

lv_obj_set_size(btnm, LV_PCT(90), 50 *hscale);
lv_obj_set_size(mbox1, LV_PCT(50), LV_PCT(30));

lv_obj_add_event_cb(mbox1, [](lv_event_t *e) {
lv_obj_t *obj = lv_obj_get_parent(lv_event_get_target(e));
uint32_t clicked_btn = lv_msgbox_get_active_btn(obj);
if(clicked_btn == 0) {
((ButtonContainer*)e->user_data)->run_callback();
}

lv_msgbox_close(obj);

}, LV_EVENT_VALUE_CHANGED, this);

lv_obj_center(mbox1);
}

void ButtonContainer::run_callback() {
prompt_callback();
}
12 changes: 11 additions & 1 deletion src/button_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

#include "lvgl/lvgl.h"

#include <string>
#include <functional>

class ButtonContainer {
public:
ButtonContainer(lv_obj_t *parent,
const void *btn_img,
const char *text,
lv_event_cb_t cb,
void *user_data);
void *user_data,
const std::string &prompt_text = {},
const std::function<void()> &prompt_callback = {});
~ButtonContainer();

lv_obj_t *get_container();
Expand All @@ -20,6 +25,9 @@ class ButtonContainer {

void handle_callback(lv_event_t *event);

void handle_prompt();
void run_callback();

static void _handle_callback(lv_event_t *event) {
ButtonContainer *button_container = (ButtonContainer*)event->user_data;
button_container->handle_callback(event);
Expand All @@ -29,6 +37,8 @@ class ButtonContainer {
lv_obj_t *btn_cont;
lv_obj_t *btn;
lv_obj_t *label;
std::string prompt_text;
std::function<void()> prompt_callback;
};

#endif // __BUTTON_CONTAINER_H__
5 changes: 5 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ void Config::init(std::string config_path) {
data["/touch_calibrated"_json_pointer] = false; // EVDEV_CALIBRATE
#endif
}

auto &estop = data["/prompt_emergency_stop"_json_pointer];
if (estop.is_null()) {
data["/prompt_emergency_stop"_json_pointer] = true;
}

std::ofstream o(config_path);
o << std::setw(2) << data << std::endl;
Expand Down
1 change: 1 addition & 0 deletions src/console_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ConsolePanel::ConsolePanel(KWebSocketClient &websocket_client, std::mutex &lock,
lv_obj_set_flex_grow(input, 1);
lv_obj_set_width(input, LV_PCT(100));
lv_textarea_set_one_line(input, true);
lv_textarea_set_cursor_click_pos(output, false);

lv_obj_set_flex_flow(input_cont, LV_FLEX_FLOW_ROW);
lv_obj_set_style_pad_all(input_cont, 0, 0);
Expand Down
10 changes: 8 additions & 2 deletions src/extruder_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ExtruderPanel::ExtruderPanel(KWebSocketClient &websocket_client,
, panel_cont(lv_obj_create(lv_scr_act()))
, spoolman_panel(sm)
, extruder_temp(ws, panel_cont, &extruder, 150,
"Extruder", lv_palette_main(LV_PALETTE_RED), false, numpad, "extruder", NULL, NULL)
"Extruder", lv_palette_main(LV_PALETTE_RED), false, true, numpad, "extruder", NULL, NULL)
, temp_selector(panel_cont, "Extruder Temperature (C)",
{"180", "190", "200", "210", "220", "230", "240", ""}, 6, &ExtruderPanel::_handle_callback, this)
, length_selector(panel_cont, "Extrude Length (mm)",
Expand Down Expand Up @@ -134,8 +134,14 @@ void ExtruderPanel::enable_spoolman() {

void ExtruderPanel::consume(json& j) {
std::lock_guard<std::mutex> lock(lv_lock);
auto target_value = j["/params/0/extruder/target"_json_pointer];
if (!target_value.is_null()) {
int target = target_value.template get<int>();
extruder_temp.update_target(target);
}

auto temp_value = j["/params/0/extruder/temperature"_json_pointer];
if (!temp_value.is_null()) {
if (!temp_value.is_null()) {
int value = temp_value.template get<int>();
extruder_temp.update_value(value);
}
Expand Down
13 changes: 10 additions & 3 deletions src/homing_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ HomingPanel::HomingPanel(KWebSocketClient &websocket_client, std::mutex &lock)
, x_down_btn(homing_cont, &arrow_left, "X-", &HomingPanel::_handle_callback, this)
, z_up_btn(homing_cont, &z_closer, "Z+", &HomingPanel::_handle_callback, this)
, z_down_btn(homing_cont, &z_farther, "Z-", &HomingPanel::_handle_callback, this)
, emergency_btn(homing_cont, &emergency, "Stop", &HomingPanel::_handle_callback, this)
, emergency_btn(homing_cont, &emergency, "Stop", &HomingPanel::_handle_callback, this,
"Do you want to emergency stop?",
[&websocket_client]() {
spdlog::debug("emergency stop pressed");
websocket_client.send_jsonrpc("printer.emergency_stop");
})
, motoroff_btn(homing_cont, &motor_off_img, "Motor Off", &HomingPanel::_handle_callback, this)
, back_btn(homing_cont, &back, "Back", &HomingPanel::_handle_callback, this)
, distance_selector(homing_cont, "Move Distance (mm)",
Expand Down Expand Up @@ -181,11 +186,13 @@ void HomingPanel::handle_callback(lv_event_t *event) {
spdlog::debug("z down pressed");
move_op = fmt::format("G0 Z-{} F1200", distance);

} else if (btn == emergency_btn.get_container()) {
}
else if (btn == emergency_btn.get_container()) {
spdlog::debug("emergency stop pressed");
ws.send_jsonrpc("printer.emergency_stop");

} else if (btn == motoroff_btn.get_container()) {
}
else if (btn == motoroff_btn.get_container()) {
spdlog::debug("motor off pressed");
ws.gcode_script("M84");

Expand Down
5 changes: 4 additions & 1 deletion src/init_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ void InitPanel::connected(KWebSocketClient &ws) {

ws.send_jsonrpc("server.files.roots",
[](json& j) { State::get_instance()->set_data("roots", j, "/result"); });


ws.send_jsonrpc("printer.info",
[](json& j) { State::get_instance()->set_data("printer_info", j, "/result"); });

json h = {
{ "namespace", "fluidd" },
{ "key", "console" }
Expand Down
7 changes: 6 additions & 1 deletion src/inputshaper_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ InputShaperPanel::InputShaperPanel(KWebSocketClient &c, std::mutex &l)
, graph_switch(lv_switch_create(switch_cont))
, calibrate_btn(button_cont, &resume, "Calibrate", &InputShaperPanel::_handle_callback, this)
, save_btn(button_cont, &sd_img, "Save", &InputShaperPanel::_handle_callback, this)
, emergency_btn(button_cont, &emergency, "Stop", &InputShaperPanel::_handle_callback, this)
, emergency_btn(button_cont, &emergency, "Stop", &InputShaperPanel::_handle_callback, this,
"Do you want to emergency stop?",
[&c]() {
spdlog::debug("emergency stop pressed");
c.send_jsonrpc("printer.emergency_stop");
})
, back_btn(cont, &back, "Back", &InputShaperPanel::_handle_callback, this)
, ximage_fullsized(false)
, yimage_fullsized(false)
Expand Down
39 changes: 20 additions & 19 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@ int main(void)
conf->get<std::string>(conf->df() + "moonraker_host"),
conf->get<uint32_t>(conf->df() + "moonraker_port"));

spdlog::info("connecting to printer at {}", ws_url);

uint32_t display_sleep = conf->get<uint32_t>(conf->df() + "display_sleep_sec") * 1000;
spdlog::info("connecting to printer at {}", ws_url);
int32_t display_sleep = conf->get<int32_t>(conf->df() + "display_sleep_sec") * 1000;

ws.connect(ws_url.c_str(),
[&init_panel, &ws]() { init_panel.connected(ws); },
[&init_panel, &ws]() { init_panel.disconnected(ws); });

screen_saver = lv_obj_create(lv_scr_act());
lv_obj_set_size(screen_saver, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_bg_opa(screen_saver, LV_OPA_100, 0);
Expand All @@ -176,21 +175,23 @@ int main(void)
lv_timer_handler();
lv_lock.unlock();

#ifndef SIMULATOR
if (lv_disp_get_inactive_time(NULL) > display_sleep) {
if (!is_sleeping.load()) {
spdlog::debug("putting display to sleeping");
fbdev_blank();
lv_obj_move_foreground(screen_saver);
// spdlog::debug("screen saver foreground");
is_sleeping = true;
}
} else {
if (is_sleeping.load()) {
spdlog::debug("waking up display");
fbdev_unblank();
lv_obj_move_background(screen_saver);
is_sleeping = false;
#ifndef SIMULATOR
if (display_sleep != -1) {
if (lv_disp_get_inactive_time(NULL) > display_sleep) {
if (!is_sleeping.load()) {
spdlog::debug("putting display to sleeping");
fbdev_blank();
lv_obj_move_foreground(screen_saver);
// spdlog::debug("screen saver foreground");
is_sleeping = true;
}
} else {
if (is_sleeping.load()) {
spdlog::debug("waking up display");
fbdev_unblank();
lv_obj_move_background(screen_saver);
is_sleeping = false;
}
}
}
#endif // SIMULATOR
Expand Down
2 changes: 1 addition & 1 deletion src/main_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void MainPanel::create_sensors(json &temp_sensors) {
lv_chart_add_series(temp_chart, color_code, LV_CHART_AXIS_PRIMARY_Y);

sensors.insert({key, std::make_shared<SensorContainer>(ws, temp_cont, sensor_img, 150,
display_name.c_str(), color_code, controllable, numpad, key,
display_name.c_str(), color_code, controllable, false, numpad, key,
temp_chart, temp_series)});
}
}
Expand Down
Loading

0 comments on commit 6d71018

Please sign in to comment.