2016-03-25 02:19:46 -04:00
|
|
|
/**
|
2016-03-24 14:01:20 -04:00
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-25 02:19:46 -04:00
|
|
|
/**
|
2016-07-25 23:06:00 -04:00
|
|
|
* MarlinSerial.cpp - Hardware serial library for Wiring
|
|
|
|
* Copyright (c) 2006 Nicholas Zambetti. All right reserved.
|
|
|
|
*
|
|
|
|
* Modified 23 November 2006 by David A. Mellis
|
|
|
|
* Modified 28 September 2010 by Mark Sproul
|
|
|
|
* Modified 14 February 2016 by Andreas Hardtung (added tx buffer)
|
|
|
|
*/
|
2011-12-22 08:55:45 -05:00
|
|
|
#include "MarlinSerial.h"
|
2016-08-02 22:36:58 -04:00
|
|
|
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
#include "stepper.h"
|
2016-08-02 22:36:58 -04:00
|
|
|
#include "Marlin.h"
|
|
|
|
|
2015-05-24 12:32:34 -04:00
|
|
|
#ifndef USBCON
|
2015-10-03 02:08:58 -04:00
|
|
|
// this next line disables the entire HardwareSerial.cpp,
|
2014-02-17 05:58:36 -05:00
|
|
|
// this is so I can support Attiny series and any other chip without a UART
|
2011-11-27 15:12:55 -05:00
|
|
|
#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
|
|
|
|
|
2012-11-05 05:34:27 -05:00
|
|
|
#if UART_PRESENT(SERIAL_PORT)
|
2016-07-08 11:25:21 -04:00
|
|
|
ring_buffer_r rx_buffer = { { 0 }, 0, 0 };
|
|
|
|
#if TX_BUFFER_SIZE > 0
|
|
|
|
ring_buffer_t tx_buffer = { { 0 }, 0, 0 };
|
|
|
|
static bool _written;
|
|
|
|
#endif
|
2011-11-27 15:12:55 -05:00
|
|
|
#endif
|
|
|
|
|
2016-07-08 11:25:21 -04:00
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
FORCE_INLINE void store_char(unsigned char c) {
|
2016-02-24 11:18:12 -05:00
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
uint8_t h = rx_buffer.head;
|
|
|
|
uint8_t i = (uint8_t)(h + 1) & (RX_BUFFER_SIZE - 1);
|
|
|
|
|
|
|
|
// if we should be storing the received character into the location
|
|
|
|
// just before the tail (meaning that the head would advance to the
|
|
|
|
// current location of the tail), we're about to overflow the buffer
|
|
|
|
// and so we don't write the character or advance the head.
|
|
|
|
if (i != rx_buffer.tail) {
|
|
|
|
rx_buffer.buffer[h] = c;
|
|
|
|
rx_buffer.head = i;
|
|
|
|
}
|
|
|
|
CRITICAL_SECTION_END;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
#if ENABLED(EMERGENCY_PARSER)
|
|
|
|
emergency_parser(c);
|
|
|
|
#endif
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
|
|
|
|
2016-07-08 11:25:21 -04:00
|
|
|
#if TX_BUFFER_SIZE > 0
|
|
|
|
FORCE_INLINE void _tx_udr_empty_irq(void)
|
|
|
|
{
|
|
|
|
// If interrupts are enabled, there must be more data in the output
|
|
|
|
// buffer. Send the next byte
|
|
|
|
uint8_t t = tx_buffer.tail;
|
|
|
|
uint8_t c = tx_buffer.buffer[t];
|
|
|
|
tx_buffer.tail = (t + 1) & (TX_BUFFER_SIZE - 1);
|
|
|
|
|
|
|
|
M_UDRx = c;
|
|
|
|
|
|
|
|
// clear the TXC bit -- "can be cleared by writing a one to its bit
|
|
|
|
// location". This makes sure flush() won't return until the bytes
|
|
|
|
// actually got written
|
|
|
|
SBI(M_UCSRxA, M_TXCx);
|
|
|
|
|
|
|
|
if (tx_buffer.head == tx_buffer.tail) {
|
|
|
|
// Buffer empty, so disable interrupts
|
|
|
|
CBI(M_UCSRxB, M_UDRIEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(M_USARTx_UDRE_vect)
|
|
|
|
ISR(M_USARTx_UDRE_vect) {
|
|
|
|
_tx_udr_empty_irq();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2011-11-27 15:12:55 -05:00
|
|
|
|
2012-11-05 05:34:27 -05:00
|
|
|
#if defined(M_USARTx_RX_vect)
|
2016-07-08 11:25:21 -04:00
|
|
|
ISR(M_USARTx_RX_vect) {
|
2012-11-05 05:34:27 -05:00
|
|
|
unsigned char c = M_UDRx;
|
2011-11-28 13:13:40 -05:00
|
|
|
store_char(c);
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Constructors ////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
MarlinSerial::MarlinSerial() { }
|
2011-11-27 15:12:55 -05:00
|
|
|
|
|
|
|
// Public Methods //////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::begin(long baud) {
|
2011-11-27 15:12:55 -05:00
|
|
|
uint16_t baud_setting;
|
2012-11-05 05:34:27 -05:00
|
|
|
bool useU2X = true;
|
2011-11-27 15:12:55 -05:00
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
#if F_CPU == 16000000UL && SERIAL_PORT == 0
|
|
|
|
// hard-coded exception for compatibility with the bootloader shipped
|
|
|
|
// with the Duemilanove and previous boards and the firmware on the 8U2
|
|
|
|
// on the Uno and Mega 2560.
|
|
|
|
if (baud == 57600) {
|
|
|
|
useU2X = false;
|
|
|
|
}
|
|
|
|
#endif
|
2015-10-03 02:08:58 -04:00
|
|
|
|
2012-11-05 05:34:27 -05:00
|
|
|
if (useU2X) {
|
2016-02-27 07:51:44 -05:00
|
|
|
M_UCSRxA = _BV(M_U2Xx);
|
2011-11-27 15:12:55 -05:00
|
|
|
baud_setting = (F_CPU / 4 / baud - 1) / 2;
|
2015-10-13 06:51:34 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-11-05 05:34:27 -05:00
|
|
|
M_UCSRxA = 0;
|
2011-11-27 15:12:55 -05:00
|
|
|
baud_setting = (F_CPU / 8 / baud - 1) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
|
2012-11-05 05:34:27 -05:00
|
|
|
M_UBRRxH = baud_setting >> 8;
|
|
|
|
M_UBRRxL = baud_setting;
|
2011-11-27 15:12:55 -05:00
|
|
|
|
2016-02-27 07:52:13 -05:00
|
|
|
SBI(M_UCSRxB, M_RXENx);
|
|
|
|
SBI(M_UCSRxB, M_TXENx);
|
|
|
|
SBI(M_UCSRxB, M_RXCIEx);
|
2016-07-08 11:25:21 -04:00
|
|
|
#if TX_BUFFER_SIZE > 0
|
|
|
|
CBI(M_UCSRxB, M_UDRIEx);
|
|
|
|
_written = false;
|
|
|
|
#endif
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::end() {
|
2016-02-27 07:52:13 -05:00
|
|
|
CBI(M_UCSRxB, M_RXENx);
|
|
|
|
CBI(M_UCSRxB, M_TXENx);
|
|
|
|
CBI(M_UCSRxB, M_RXCIEx);
|
2016-07-08 11:25:21 -04:00
|
|
|
CBI(M_UCSRxB, M_UDRIEx);
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
|
|
|
|
2016-07-08 11:25:21 -04:00
|
|
|
void MarlinSerial::checkRx(void) {
|
|
|
|
if (TEST(M_UCSRxA, M_RXCx)) {
|
|
|
|
uint8_t c = M_UDRx;
|
|
|
|
store_char(c);
|
|
|
|
}
|
|
|
|
}
|
2011-11-28 13:13:40 -05:00
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
int MarlinSerial::peek(void) {
|
2016-02-24 11:18:12 -05:00
|
|
|
int v;
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
uint8_t t = rx_buffer.tail;
|
|
|
|
if (rx_buffer.head == t) {
|
|
|
|
v = -1;
|
2015-10-03 02:08:58 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-02-24 11:18:12 -05:00
|
|
|
v = rx_buffer.buffer[t];
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
2016-02-24 11:18:12 -05:00
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
return v;
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
int MarlinSerial::read(void) {
|
2016-02-24 11:18:12 -05:00
|
|
|
int v;
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
uint8_t t = rx_buffer.tail;
|
|
|
|
if (rx_buffer.head == t) {
|
|
|
|
v = -1;
|
2015-01-24 00:11:50 -05:00
|
|
|
}
|
|
|
|
else {
|
2016-02-24 11:18:12 -05:00
|
|
|
v = rx_buffer.buffer[t];
|
|
|
|
rx_buffer.tail = (uint8_t)(t + 1) & (RX_BUFFER_SIZE - 1);
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
2016-02-24 11:18:12 -05:00
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
return v;
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
|
|
|
|
2016-07-08 11:25:21 -04:00
|
|
|
uint8_t MarlinSerial::available(void) {
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
uint8_t h = rx_buffer.head;
|
|
|
|
uint8_t t = rx_buffer.tail;
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
return (uint8_t)(RX_BUFFER_SIZE + h - t) & (RX_BUFFER_SIZE - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarlinSerial::flush(void) {
|
|
|
|
// RX
|
2011-11-27 15:12:55 -05:00
|
|
|
// don't reverse this or there may be problems if the RX interrupt
|
|
|
|
// occurs after reading the value of rx_buffer_head but before writing
|
|
|
|
// the value to rx_buffer_tail; the previous value of rx_buffer_head
|
|
|
|
// may be written to rx_buffer_tail, making it appear as if the buffer
|
|
|
|
// were full, not empty.
|
2016-02-24 11:18:12 -05:00
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
rx_buffer.head = rx_buffer.tail;
|
|
|
|
CRITICAL_SECTION_END;
|
2011-11-27 15:12:55 -05:00
|
|
|
}
|
|
|
|
|
2016-07-08 11:25:21 -04:00
|
|
|
#if TX_BUFFER_SIZE > 0
|
|
|
|
uint8_t MarlinSerial::availableForWrite(void) {
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
uint8_t h = tx_buffer.head;
|
|
|
|
uint8_t t = tx_buffer.tail;
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
return (uint8_t)(TX_BUFFER_SIZE + h - t) & (TX_BUFFER_SIZE - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarlinSerial::write(uint8_t c) {
|
|
|
|
_written = true;
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
bool emty = (tx_buffer.head == tx_buffer.tail);
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
// If the buffer and the data register is empty, just write the byte
|
|
|
|
// to the data register and be done. This shortcut helps
|
|
|
|
// significantly improve the effective datarate at high (>
|
|
|
|
// 500kbit/s) bitrates, where interrupt overhead becomes a slowdown.
|
|
|
|
if (emty && TEST(M_UCSRxA, M_UDREx)) {
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
M_UDRx = c;
|
|
|
|
SBI(M_UCSRxA, M_TXCx);
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t i = (tx_buffer.head + 1) & (TX_BUFFER_SIZE - 1);
|
|
|
|
|
|
|
|
// If the output buffer is full, there's nothing for it other than to
|
|
|
|
// wait for the interrupt handler to empty it a bit
|
|
|
|
while (i == tx_buffer.tail) {
|
|
|
|
if (!TEST(SREG, SREG_I)) {
|
|
|
|
// Interrupts are disabled, so we'll have to poll the data
|
|
|
|
// register empty flag ourselves. If it is set, pretend an
|
|
|
|
// interrupt has happened and call the handler to free up
|
|
|
|
// space for us.
|
2016-07-09 19:51:12 -04:00
|
|
|
if (TEST(M_UCSRxA, M_UDREx))
|
|
|
|
_tx_udr_empty_irq();
|
2016-07-08 11:25:21 -04:00
|
|
|
} else {
|
|
|
|
// nop, the interrupt handler will free up space for us
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_buffer.buffer[tx_buffer.head] = c;
|
|
|
|
{ CRITICAL_SECTION_START;
|
|
|
|
tx_buffer.head = i;
|
|
|
|
SBI(M_UCSRxB, M_UDRIEx);
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarlinSerial::flushTX(void) {
|
|
|
|
// TX
|
|
|
|
// If we have never written a byte, no need to flush. This special
|
|
|
|
// case is needed since there is no way to force the TXC (transmit
|
|
|
|
// complete) bit to 1 during initialization
|
|
|
|
if (!_written)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (TEST(M_UCSRxB, M_UDRIEx) || !TEST(M_UCSRxA, M_TXCx)) {
|
|
|
|
if (!TEST(SREG, SREG_I) && TEST(M_UCSRxB, M_UDRIEx))
|
|
|
|
// Interrupts are globally disabled, but the DR empty
|
|
|
|
// interrupt should be enabled, so poll the DR empty flag to
|
|
|
|
// prevent deadlock
|
|
|
|
if (TEST(M_UCSRxA, M_UDREx))
|
|
|
|
_tx_udr_empty_irq();
|
|
|
|
}
|
|
|
|
// If we get here, nothing is queued anymore (DRIE is disabled) and
|
|
|
|
// the hardware finished tranmission (TXC is set).
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
void MarlinSerial::write(uint8_t c) {
|
|
|
|
while (!TEST(M_UCSRxA, M_UDREx))
|
|
|
|
;
|
|
|
|
M_UDRx = c;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// end NEW
|
2011-11-28 13:13:40 -05:00
|
|
|
|
|
|
|
/// imports from print.h
|
2011-11-27 15:12:55 -05:00
|
|
|
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::print(char c, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print((long) c, base);
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::print(unsigned char b, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print((unsigned long) b, base);
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::print(int n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print((long) n, base);
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::print(unsigned int n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print((unsigned long) n, base);
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::print(long n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
if (base == 0) {
|
|
|
|
write(n);
|
2015-01-24 00:11:50 -05:00
|
|
|
}
|
|
|
|
else if (base == 10) {
|
2011-11-28 13:13:40 -05:00
|
|
|
if (n < 0) {
|
|
|
|
print('-');
|
|
|
|
n = -n;
|
|
|
|
}
|
|
|
|
printNumber(n, 10);
|
2015-10-03 02:08:58 -04:00
|
|
|
}
|
|
|
|
else {
|
2011-11-28 13:13:40 -05:00
|
|
|
printNumber(n, base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::print(unsigned long n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
if (base == 0) write(n);
|
|
|
|
else printNumber(n, base);
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::print(double n, int digits) {
|
2011-11-28 13:13:40 -05:00
|
|
|
printFloat(n, digits);
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(void) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print('\r');
|
2015-10-03 02:08:58 -04:00
|
|
|
print('\n');
|
2011-11-28 13:13:40 -05:00
|
|
|
}
|
|
|
|
|
2015-10-03 02:08:58 -04:00
|
|
|
void MarlinSerial::println(const String& s) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(s);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(const char c[]) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(c);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(char c, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(c, base);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(unsigned char b, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(b, base);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(int n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(n, base);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(unsigned int n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(n, base);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(long n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(n, base);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(unsigned long n, int base) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(n, base);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::println(double n, int digits) {
|
2011-11-28 13:13:40 -05:00
|
|
|
print(n, digits);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private Methods /////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::printNumber(unsigned long n, uint8_t base) {
|
2015-10-03 02:08:58 -04:00
|
|
|
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
|
2011-11-28 13:13:40 -05:00
|
|
|
unsigned long i = 0;
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
print('0');
|
|
|
|
return;
|
2015-10-03 02:08:58 -04:00
|
|
|
}
|
2011-11-28 13:13:40 -05:00
|
|
|
|
|
|
|
while (n > 0) {
|
|
|
|
buf[i++] = n % base;
|
|
|
|
n /= base;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i > 0; i--)
|
2015-10-03 02:08:58 -04:00
|
|
|
print((char)(buf[i - 1] < 10 ?
|
|
|
|
'0' + buf[i - 1] :
|
|
|
|
'A' + buf[i - 1] - 10));
|
2011-11-28 13:13:40 -05:00
|
|
|
}
|
|
|
|
|
2015-01-24 00:11:50 -05:00
|
|
|
void MarlinSerial::printFloat(double number, uint8_t digits) {
|
2011-11-28 13:13:40 -05:00
|
|
|
// Handle negative numbers
|
2015-01-24 00:11:50 -05:00
|
|
|
if (number < 0.0) {
|
2015-10-03 02:08:58 -04:00
|
|
|
print('-');
|
|
|
|
number = -number;
|
2011-11-28 13:13:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Round correctly so that print(1.999, 2) prints as "2.00"
|
|
|
|
double rounding = 0.5;
|
2015-01-24 00:11:50 -05:00
|
|
|
for (uint8_t i = 0; i < digits; ++i)
|
2011-11-28 13:13:40 -05:00
|
|
|
rounding /= 10.0;
|
2015-10-03 02:08:58 -04:00
|
|
|
|
2011-11-28 13:13:40 -05:00
|
|
|
number += rounding;
|
|
|
|
|
|
|
|
// Extract the integer part of the number and print it
|
|
|
|
unsigned long int_part = (unsigned long)number;
|
|
|
|
double remainder = number - (double)int_part;
|
|
|
|
print(int_part);
|
|
|
|
|
|
|
|
// Print the decimal point, but only if there are digits beyond
|
2015-04-04 00:43:30 -04:00
|
|
|
if (digits > 0) print('.');
|
2011-11-28 13:13:40 -05:00
|
|
|
|
|
|
|
// Extract digits from the remainder one at a time
|
2015-01-24 00:11:50 -05:00
|
|
|
while (digits-- > 0) {
|
2011-11-28 13:13:40 -05:00
|
|
|
remainder *= 10.0;
|
|
|
|
int toPrint = int(remainder);
|
|
|
|
print(toPrint);
|
2015-10-03 02:08:58 -04:00
|
|
|
remainder -= toPrint;
|
|
|
|
}
|
2011-11-28 13:13:40 -05:00
|
|
|
}
|
2011-11-27 15:12:55 -05:00
|
|
|
// Preinstantiate Objects //////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2015-07-31 23:31:53 -04:00
|
|
|
MarlinSerial customizedSerial;
|
2011-11-27 15:12:55 -05:00
|
|
|
|
|
|
|
#endif // whole file
|
2015-05-24 12:32:34 -04:00
|
|
|
#endif // !USBCON
|
2013-10-30 06:45:32 -04:00
|
|
|
|
|
|
|
// For AT90USB targets use the UART for BT interfacing
|
2015-07-31 19:55:47 -04:00
|
|
|
#if defined(USBCON) && ENABLED(BLUETOOTH)
|
2015-07-31 23:31:53 -04:00
|
|
|
HardwareSerial bluetoothSerial;
|
2013-10-30 06:45:32 -04:00
|
|
|
#endif
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
#if ENABLED(EMERGENCY_PARSER)
|
|
|
|
|
|
|
|
// Currently looking for: M108, M112, M410
|
2016-07-30 07:25:30 -04:00
|
|
|
// If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
2016-07-08 11:25:21 -04:00
|
|
|
FORCE_INLINE void emergency_parser(unsigned char c) {
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
static e_parser_state state = state_RESET;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case state_RESET:
|
|
|
|
switch (c) {
|
2016-07-06 15:48:21 -04:00
|
|
|
case ' ': break;
|
|
|
|
case 'N': state = state_N; break;
|
|
|
|
case 'M': state = state_M; break;
|
|
|
|
default: state = state_IGNORE;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
}
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
2016-07-06 15:48:21 -04:00
|
|
|
case state_N:
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
switch (c) {
|
2016-07-06 15:48:21 -04:00
|
|
|
case '0': case '1': case '2':
|
|
|
|
case '3': case '4': case '5':
|
|
|
|
case '6': case '7': case '8':
|
|
|
|
case '9': case '-': case ' ': break;
|
|
|
|
case 'M': state = state_M; break;
|
|
|
|
default: state = state_IGNORE;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
}
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
2016-07-06 15:48:21 -04:00
|
|
|
case state_M:
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
switch (c) {
|
2016-07-06 15:48:21 -04:00
|
|
|
case ' ': break;
|
|
|
|
case '1': state = state_M1; break;
|
|
|
|
case '4': state = state_M4; break;
|
|
|
|
default: state = state_IGNORE;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
}
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
2016-07-06 15:48:21 -04:00
|
|
|
case state_M1:
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
switch (c) {
|
2016-07-06 15:48:21 -04:00
|
|
|
case '0': state = state_M10; break;
|
|
|
|
case '1': state = state_M11; break;
|
|
|
|
default: state = state_IGNORE;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
}
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
case state_M10:
|
2016-07-06 19:03:33 -04:00
|
|
|
state = (c == '8') ? state_M108 : state_IGNORE;
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
case state_M11:
|
2016-07-06 19:03:33 -04:00
|
|
|
state = (c == '2') ? state_M112 : state_IGNORE;
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
case state_M4:
|
2016-07-06 15:48:21 -04:00
|
|
|
state = (c == '1') ? state_M41 : state_IGNORE;
|
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
case state_M41:
|
2016-07-06 19:03:33 -04:00
|
|
|
state = (c == '0') ? state_M410 : state_IGNORE;
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
case state_IGNORE:
|
|
|
|
if (c == '\n') state = state_RESET;
|
2016-07-06 15:48:21 -04:00
|
|
|
break;
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
|
|
|
|
default:
|
2016-07-06 19:03:33 -04:00
|
|
|
if (c == '\n') {
|
|
|
|
switch (state) {
|
|
|
|
case state_M108:
|
|
|
|
wait_for_heatup = false;
|
|
|
|
break;
|
|
|
|
case state_M112:
|
|
|
|
kill(PSTR(MSG_KILLED));
|
|
|
|
break;
|
|
|
|
case state_M410:
|
|
|
|
quickstop_stepper();
|
|
|
|
break;
|
2016-04-30 05:51:18 -04:00
|
|
|
default:
|
|
|
|
break;
|
2016-07-06 19:03:33 -04:00
|
|
|
}
|
|
|
|
state = state_RESET;
|
|
|
|
}
|
Add an emergency-command parser to MarlinSerial (supporting M108)
Add an emergency-command parser to MarlinSerial's RX interrupt.
The parser tries to find and execute M108,M112,M410 before the commands disappear in the RX-buffer.
To avoid false positives for M117, comments and commands followed by filenames (M23, M28, M30, M32, M33) are filtered.
This enables Marlin to receive and react on the Emergency command at all times - regardless of whether the buffers are full or not. It remains to convince hosts to send the commands. To inform the hosts about the new feature a new entry in the M115-report was made. "`EMERGENCY_CODES:M112,M108,M410;`".
The parser is fast. It only ever needs two switch decisions and one assignment of the new state for every character.
One problem remains. If the host has sent an incomplete line before sending an emergency command the emergency command could be omitted when the parser is in `state_IGNORE`.
In that case the host should send "\ncommand\n"
Also introduces M108 to break the waiting for the heaters in M109, M190 and M303.
Rename `cancel_heatup` to `wait_for_heatup` to better see the purpose.
2016-07-04 17:23:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|