Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add M117 support (print progress with octoprint) #1497

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/marlin_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,8 @@ static uint64_t _server_update_vars(uint64_t update) {
uint8_t progress = 0;
if (oProgressData.oPercentDone.mIsActual(marlin_server.vars.print_duration))
progress = static_cast<uint8_t>(oProgressData.oPercentDone.mGetValue());
else if (oProgressData.oPercentDirectControl.mIsActual(marlin_server.vars.print_duration))
progress = static_cast<uint8_t>(oProgressData.oPercentDirectControl.mGetValue());
else
progress = static_cast<uint8_t>(media_print_get_percent_done());
if (marlin_server.vars.sd_percent_done != progress) {
Expand Down
1,535 changes: 1,535 additions & 0 deletions src/gui/res/cc/png_serial_printing.c

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/gui/screen_printing_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include "odometer.hpp"
#include "window_icon.hpp"

//octo icon
static point_ui16_t pt_ico() {
auto sz = window_icon_t::CalculateMinimalSize("/internal/res/png/screen_printing_serial.png");
return { sz.w, sz.h };
}
//octo icon, 86x69
static point_ui16_t pt_ico() { return icon_meas(resource_ptr(IDR_PNG_serial_printing)); }

screen_printing_serial_data_t::screen_printing_serial_data_t()
: AddSuperWindow<ScreenPrintingModel>(_(caption))
, octo_icon(this, Rect16((240 - pt_ico().x) / 2, GuiDefaults::RectScreenBody.Top(), pt_ico().x, pt_ico().y), "/internal/res/png/screen_printing_serial.png")
, octo_icon(this, Rect16(120 - pt_ico().x / 2, GuiDefaults::RectScreenBody.Top() + 8, pt_ico().x, pt_ico().y), IDR_PNG_serial_printing)
, w_progress(this, Rect16(10, GuiDefaults::RectScreenBody.Top() + pt_ico().y + 14, GuiDefaults::RectScreen.Width() - 2 * 10, 16))
, w_progress_txt(this, Rect16(10, GuiDefaults::RectScreenBody.Top() + pt_ico().y + 34, GuiDefaults::RectScreen.Width() - 2 * 10, 30))
, w_message(this, Rect16(10, GuiDefaults::RectScreenBody.Top() + pt_ico().y + 60, GuiDefaults::RectScreen.Width() - 2 * 10, 20))
, last_tick(0)
, connection(connection_state_t::connected) {
ClrMenuTimeoutClose();
Expand All @@ -26,6 +26,10 @@ screen_printing_serial_data_t::screen_printing_serial_data_t()
octo_icon.Disable();
octo_icon.Unshadow();

w_message.font = resource_font(IDR_FNT_SMALL);
w_message.SetAlignment(Align_t::CenterBottom());
w_message.SetPadding({ 0, 2, 0, 2 });

initAndSetIconAndLabel(btn_tune, res_tune);
initAndSetIconAndLabel(btn_pause, res_pause);
initAndSetIconAndLabel(btn_stop, res_disconnect);
Expand Down
6 changes: 6 additions & 0 deletions src/gui/screen_printing_serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "gui.hpp"
#include "window_header.hpp"
#include "status_footer.hpp"
#include "window_print_progress.hpp"
#include "window_text.hpp"
#include "window_lcd_message.hpp"
#include <array>
#include "non_file_printing_counter.hpp"

Expand All @@ -17,6 +19,10 @@ class screen_printing_serial_data_t : public AddSuperWindow<ScreenPrintingModel>

window_icon_t octo_icon;

WindowPrintProgress w_progress;
WindowNumbPrintProgress w_progress_txt;
WindowLCDMessage w_message;

int last_tick;
enum class connection_state_t { connected,
disconnect,
Expand Down
50 changes: 50 additions & 0 deletions src/gui/window_lcd_message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2021 Matthew Lloyd <[email protected]>
* All rights reserved.
*
* This file is part of Llama Mini.
*
* Llama Mini is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Llama Mini is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Llama Mini. If not, see <https://www.gnu.org/licenses/>.
*/

#include "window_lcd_message.hpp"
#include "gui.hpp"
#include <algorithm>
#include "resource.h"
#include "marlin_client.h"

char lcd_message_text[LCD_MESSAGE_MAX_LEN + 1];

/*****************************************************************************/
//WindowLCDMessage
WindowLCDMessage::WindowLCDMessage(window_t *parent, Rect16 rect)
: AddSuperWindow<window_text_t>(parent, rect, is_multiline::no) {
last_lcd_message_text[0] = 0;
last_lcd_message_text[LCD_MESSAGE_MAX_LEN] = 0;
lcd_message_text[0] = 0;
lcd_message_text[LCD_MESSAGE_MAX_LEN] = 0;
font = resource_font(IDR_FNT_SMALL);
SetAlignment(Align_t::Center());
}

void WindowLCDMessage::windowEvent(EventLock /*has private ctor*/, window_t *sender, GUI_event_t event, void *param) {
if (event == GUI_event_t::LOOP) {
if (strncmp(lcd_message_text, last_lcd_message_text, LCD_MESSAGE_MAX_LEN) != 0) {
strncpy(last_lcd_message_text, lcd_message_text, LCD_MESSAGE_MAX_LEN);
SetText(string_view_utf8::MakeRAM((const uint8_t *)lcd_message_text));
Invalidate();
}
}
SuperWindowEvent(sender, event, param);
}
36 changes: 36 additions & 0 deletions src/gui/window_lcd_message.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021 Matthew Lloyd <[email protected]>
* All rights reserved.
*
* This file is part of Llama Mini.
*
* Llama Mini is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Llama Mini is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Llama Mini. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include "window_text.hpp"

#define LCD_MESSAGE_MAX_LEN 30
extern char lcd_message_text[LCD_MESSAGE_MAX_LEN + 1];

class WindowLCDMessage : public AddSuperWindow<window_text_t> {
char last_lcd_message_text[LCD_MESSAGE_MAX_LEN + 1];

public:
WindowLCDMessage(window_t *parent, Rect16 rect);

protected:
void windowEvent(EventLock /*has private ctor*/, window_t *sender, GUI_event_t event, void *param) override;
};
15 changes: 15 additions & 0 deletions src/marlin_stubs/M117.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "window_lcd_message.hpp"
#include "../../lib/Marlin/Marlin/src/gcode/gcode.h"

#include "M117.hpp"
#include <stdint.h>

/**
* M117: LCD message
*/
void PrusaGcodeSuite::M117() {
if (parser.string_arg && parser.string_arg[0])
strncpy(lcd_message_text, parser.string_arg, LCD_MESSAGE_MAX_LEN);
else
lcd_message_text[0] = 0;
}
5 changes: 5 additions & 0 deletions src/marlin_stubs/M117.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace PrusaGcodeSuite {
void M117(); // LCD message
}
3 changes: 2 additions & 1 deletion src/marlin_stubs/PrusaGcodeSuite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ void G163(); /// measure length of axis

void M50(); /// selftest

void M117(); /// M117 LCD message (print status)

void M300(); /// beep
void M505(); /// set eeprom variable
void M650();
Expand All @@ -29,5 +31,4 @@ void M1587(); /// Wi-Fi credentials
void M1600(); /// Menu change filament. Prusa STM32 platform specific
void M1700(); /// Preheat. Prusa STM32 platform specific
void M1701(); /// Autoload. Prusa STM32 platform specific

}
7 changes: 6 additions & 1 deletion src/marlin_stubs/gcode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../../lib/Marlin/Marlin/src/gcode/gcode.h"
#include "../../lib/Marlin/Marlin/src/gcode/queue.h"

#include "PrusaGcodeSuite.hpp"

Expand All @@ -11,9 +12,13 @@ bool GcodeSuite::process_parsed_command_custom(bool no_ok) {
case 50:
PrusaGcodeSuite::M50(); //selftest
return true;
case 117:
PrusaGcodeSuite::M117();
if (!no_ok)
queue.ok_to_send();
return true;
case 300:
PrusaGcodeSuite::M300();
return true;
#if defined(_DEBUG)
case 330:
PrusaGcodeSuite::M330();
Expand Down