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

(rebase/build) Add M117 support (print progress with octoprint) #3147

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -2071,6 +2071,8 @@ static void _server_update_vars() {
uint8_t progress = 0;
if (oProgressData.oPercentDone.mIsActual(marlin_vars()->print_duration))
progress = static_cast<uint8_t>(oProgressData.oPercentDone.mGetValue());
else if (oProgressData.oPercentDirectControl.mIsActual(marlin_vars() ->print_duration))
progress = static_cast<uint8_t>(oProgressData.oPercentDirectControl.mGetValue());
else
progress = static_cast<uint8_t>(media_print_get_percent_done());

Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ target_sources(
window_file_list.cpp
window_filebrowser.cpp
window_header.cpp
window_lcd_message.cpp
window_msgbox_wrong_printer.cpp
window_print_progress.cpp
window_temp_graph.cpp
Expand Down
Binary file removed src/gui/res/png/serial_printing_172x138.png
Binary file not shown.
Binary file added src/gui/res/png/serial_printing_172x69.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/gui/screen_printing_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

screen_printing_serial_data_t::screen_printing_serial_data_t()
: AddSuperWindow<ScreenPrintingModel>(_(caption))
, octo_icon(this, Rect16((240 - png::serial_printing_172x138.w) / 2, GuiDefaults::RectScreenBody.Top(), png::serial_printing_172x138.w, png::serial_printing_172x138.h), &png::serial_printing_172x138)
, octo_icon(this, Rect16((120 - png::serial_printing_172x69.w) / 2, GuiDefaults::RectScreenBody.Top() + 8, png::serial_printing_172x69.w, png::serial_printing_172x69.h), &png::serial_printing_172x69)
, w_progress(this, Rect16(10, GuiDefaults::RectScreenBody.Top() + png::serial_printing_172x69.h + 14, GuiDefaults::RectScreen.Width() - 2 * 10, 16))
, w_progress_txt(this, Rect16(10, GuiDefaults::RectScreenBody.Top() + png::serial_printing_172x69.h + 34, GuiDefaults::RectScreen.Width() - 2 * 10, 30))
, w_message(this, Rect16(10, GuiDefaults::RectScreenBody.Top() + png::serial_printing_172x69.h + 60, GuiDefaults::RectScreen.Width() - 2 * 10, 20))
, last_tick(0)
, connection(connection_state_t::connected) {
ClrMenuTimeoutClose();
Expand All @@ -26,6 +29,10 @@ screen_printing_serial_data_t::screen_printing_serial_data_t()
octo_icon.Unshadow();

SetButtonIconAndLabel(BtnSocket::Right, BtnRes::Disconnect, LabelRes::Disconnect);

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

void screen_printing_serial_data_t::windowEvent(EventLock /*has private ctor*/, window_t *sender, GUI_event_t event, void *param) {
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 @@ -14,6 +16,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 "ScreenHandler.hpp"
#include "marlin_client.hpp"

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;
};
1 change: 1 addition & 0 deletions src/marlin_stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target_sources(
PRIVATE G26.cpp
G64.cpp
gcode.cpp
M117.cpp
M300.cpp
M330.cpp
M505.cpp
Expand Down
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
}
2 changes: 2 additions & 0 deletions src/marlin_stubs/PrusaGcodeSuite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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

Expand Down
5 changes: 5 additions & 0 deletions src/marlin_stubs/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ bool GcodeSuite::process_parsed_command_custom(bool no_ok) {
case 50:
PrusaGcodeSuite::M50(); // selftest
break;
case 117:
PrusaGcodeSuite::M117();
if (!no_ok)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just break here. The ok_to_send stuff is handled below.

queue.ok_to_send();
return true;
#if HAS_LEDS
case 150:
PrusaGcodeSuite::M150();
Expand Down