Indent MarlinSerial code

2.0.x
Scott Lahteine 8 years ago
parent 7a7a80e6c5
commit eaa66f3c46

@ -33,10 +33,9 @@
#include "stepper.h" #include "stepper.h"
#include "Marlin.h" #include "Marlin.h"
#ifndef USBCON // Disable HardwareSerial.cpp to support chips without a UART (Attiny, etc.)
// this next line disables the entire HardwareSerial.cpp,
// this is so I can support Attiny series and any other chip without a UART #if !defined(USBCON) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H))
#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
#if UART_PRESENT(SERIAL_PORT) #if UART_PRESENT(SERIAL_PORT)
ring_buffer_r rx_buffer = { { 0 }, 0, 0 }; ring_buffer_r rx_buffer = { { 0 }, 0, 0 };
@ -46,6 +45,97 @@
#endif #endif
#endif #endif
#if ENABLED(EMERGENCY_PARSER)
#include "language.h"
// Currently looking for: M108, M112, M410
// If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
FORCE_INLINE void emergency_parser(const unsigned char c) {
static e_parser_state state = state_RESET;
switch (state) {
case state_RESET:
switch (c) {
case ' ': break;
case 'N': state = state_N; break;
case 'M': state = state_M; break;
default: state = state_IGNORE;
}
break;
case state_N:
switch (c) {
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;
}
break;
case state_M:
switch (c) {
case ' ': break;
case '1': state = state_M1; break;
case '4': state = state_M4; break;
default: state = state_IGNORE;
}
break;
case state_M1:
switch (c) {
case '0': state = state_M10; break;
case '1': state = state_M11; break;
default: state = state_IGNORE;
}
break;
case state_M10:
state = (c == '8') ? state_M108 : state_IGNORE;
break;
case state_M11:
state = (c == '2') ? state_M112 : state_IGNORE;
break;
case state_M4:
state = (c == '1') ? state_M41 : state_IGNORE;
break;
case state_M41:
state = (c == '0') ? state_M410 : state_IGNORE;
break;
case state_IGNORE:
if (c == '\n') state = state_RESET;
break;
default:
if (c == '\n') {
switch (state) {
case state_M108:
wait_for_user = wait_for_heatup = false;
break;
case state_M112:
kill(PSTR(MSG_KILLED));
break;
case state_M410:
quickstop_stepper();
break;
default:
break;
}
state = state_RESET;
}
}
}
#endif
FORCE_INLINE void store_char(unsigned char c) { FORCE_INLINE void store_char(unsigned char c) {
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
@ -104,11 +194,7 @@ FORCE_INLINE void store_char(unsigned char c) {
} }
#endif #endif
// Constructors //////////////////////////////////////////////////////////////// // Public Methods
MarlinSerial::MarlinSerial() { }
// Public Methods //////////////////////////////////////////////////////////////
void MarlinSerial::begin(long baud) { void MarlinSerial::begin(long baud) {
uint16_t baud_setting; uint16_t baud_setting;
@ -376,7 +462,7 @@ void MarlinSerial::println(double n, int digits) {
println(); println();
} }
// Private Methods ///////////////////////////////////////////////////////////// // Private Methods
void MarlinSerial::printNumber(unsigned long n, uint8_t base) { void MarlinSerial::printNumber(unsigned long n, uint8_t base) {
if (n) { if (n) {
@ -424,104 +510,13 @@ void MarlinSerial::printFloat(double number, uint8_t digits) {
} }
} }
} }
// Preinstantiate Objects //////////////////////////////////////////////////////
// Preinstantiate
MarlinSerial customizedSerial; MarlinSerial customizedSerial;
#endif // whole file #endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H)
#endif // !USBCON
// For AT90USB targets use the UART for BT interfacing // For AT90USB targets use the UART for BT interfacing
#if defined(USBCON) && ENABLED(BLUETOOTH) #if defined(USBCON) && ENABLED(BLUETOOTH)
HardwareSerial bluetoothSerial; HardwareSerial bluetoothSerial;
#endif #endif
#if ENABLED(EMERGENCY_PARSER)
// Currently looking for: M108, M112, M410
// If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
FORCE_INLINE void emergency_parser(unsigned char c) {
static e_parser_state state = state_RESET;
switch (state) {
case state_RESET:
switch (c) {
case ' ': break;
case 'N': state = state_N; break;
case 'M': state = state_M; break;
default: state = state_IGNORE;
}
break;
case state_N:
switch (c) {
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;
}
break;
case state_M:
switch (c) {
case ' ': break;
case '1': state = state_M1; break;
case '4': state = state_M4; break;
default: state = state_IGNORE;
}
break;
case state_M1:
switch (c) {
case '0': state = state_M10; break;
case '1': state = state_M11; break;
default: state = state_IGNORE;
}
break;
case state_M10:
state = (c == '8') ? state_M108 : state_IGNORE;
break;
case state_M11:
state = (c == '2') ? state_M112 : state_IGNORE;
break;
case state_M4:
state = (c == '1') ? state_M41 : state_IGNORE;
break;
case state_M41:
state = (c == '0') ? state_M410 : state_IGNORE;
break;
case state_IGNORE:
if (c == '\n') state = state_RESET;
break;
default:
if (c == '\n') {
switch (state) {
case state_M108:
wait_for_user = wait_for_heatup = false;
break;
case state_M112:
kill(PSTR(MSG_KILLED));
break;
case state_M410:
quickstop_stepper();
break;
default:
break;
}
state = state_RESET;
}
}
}
#endif

@ -29,8 +29,8 @@
*/ */
#ifndef MarlinSerial_h #ifndef MARLINSERIAL_H
#define MarlinSerial_h #define MARLINSERIAL_H
#include "MarlinConfig.h" #include "MarlinConfig.h"
@ -52,8 +52,7 @@
#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix
#endif #endif
// Registers used by MarlinSerial class (these are expanded // Registers used by MarlinSerial class (expanded depending on selected serial port)
// depending on selected serial port
#define M_UCSRxA SERIAL_REGNAME(UCSR,SERIAL_PORT,A) // defines M_UCSRxA to be UCSRnA where n is the serial port number #define M_UCSRxA SERIAL_REGNAME(UCSR,SERIAL_PORT,A) // defines M_UCSRxA to be UCSRnA where n is the serial port number
#define M_UCSRxB SERIAL_REGNAME(UCSR,SERIAL_PORT,B) #define M_UCSRxB SERIAL_REGNAME(UCSR,SERIAL_PORT,B)
#define M_RXENx SERIAL_REGNAME(RXEN,SERIAL_PORT,) #define M_RXENx SERIAL_REGNAME(RXEN,SERIAL_PORT,)
@ -70,14 +69,12 @@
#define M_U2Xx SERIAL_REGNAME(U2X,SERIAL_PORT,) #define M_U2Xx SERIAL_REGNAME(U2X,SERIAL_PORT,)
#define M_USARTx_UDRE_vect SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect) #define M_USARTx_UDRE_vect SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)
#define DEC 10 #define DEC 10
#define HEX 16 #define HEX 16
#define OCT 8 #define OCT 8
#define BIN 2 #define BIN 2
#define BYTE 0 #define BYTE 0
#ifndef USBCON #ifndef USBCON
// Define constants and variables for buffering incoming serial data. We're // Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which rx_buffer_head is the index of the // using a ring buffer (I think), in which rx_buffer_head is the index of the
@ -118,15 +115,10 @@ struct ring_buffer_r {
#endif #endif
#endif #endif
#if ENABLED(EMERGENCY_PARSER)
#include "language.h"
void emergency_parser(unsigned char c);
#endif
class MarlinSerial { //: public Stream class MarlinSerial { //: public Stream
public: public:
MarlinSerial(); MarlinSerial() {};
static void begin(long); static void begin(long);
static void end(); static void end();
static int peek(void); static int peek(void);
@ -171,6 +163,7 @@ class MarlinSerial { //: public Stream
}; };
extern MarlinSerial customizedSerial; extern MarlinSerial customizedSerial;
#endif // !USBCON #endif // !USBCON
// Use the UART for Bluetooth in AT90USB configurations // Use the UART for Bluetooth in AT90USB configurations
@ -178,4 +171,4 @@ extern MarlinSerial customizedSerial;
extern HardwareSerial bluetoothSerial; extern HardwareSerial bluetoothSerial;
#endif #endif
#endif #endif // MARLINSERIAL_H

Loading…
Cancel
Save