2017-04-02 06:04:54 +00: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SERIAL_H__
|
|
|
|
#define __SERIAL_H__
|
|
|
|
|
2017-05-17 10:07:35 +00:00
|
|
|
#include "MarlinConfig.h"
|
|
|
|
|
2017-04-02 06:04:54 +00:00
|
|
|
#ifdef USBCON
|
2017-12-15 21:02:39 +00:00
|
|
|
#include <HardwareSerial.h>
|
2017-04-02 06:04:54 +00:00
|
|
|
#if ENABLED(BLUETOOTH)
|
2018-02-07 12:13:28 +00:00
|
|
|
extern HardwareSerial bluetoothSerial;
|
2018-02-14 08:53:55 +00:00
|
|
|
#define MYSERIAL0 bluetoothSerial
|
2017-04-02 06:04:54 +00:00
|
|
|
#else
|
2018-02-14 08:53:55 +00:00
|
|
|
#define MYSERIAL0 Serial
|
2017-04-02 06:04:54 +00:00
|
|
|
#endif // BLUETOOTH
|
|
|
|
#else
|
|
|
|
#include "MarlinSerial.h"
|
2018-02-14 08:53:55 +00:00
|
|
|
#define MYSERIAL0 customizedSerial
|
2017-04-02 06:04:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern const char echomagic[] PROGMEM;
|
|
|
|
extern const char errormagic[] PROGMEM;
|
|
|
|
|
2018-02-14 08:53:55 +00:00
|
|
|
#define SERIAL_CHAR(x) ((void)MYSERIAL0.write(x))
|
2017-06-09 15:51:23 +00:00
|
|
|
#define SERIAL_EOL() SERIAL_CHAR('\n')
|
2017-04-02 06:04:54 +00:00
|
|
|
|
2018-02-14 08:53:55 +00:00
|
|
|
#define SERIAL_PRINT(x,b) MYSERIAL0.print(x,b)
|
|
|
|
#define SERIAL_PRINTLN(x,b) MYSERIAL0.println(x,b)
|
|
|
|
#define SERIAL_PRINTF(args...) MYSERIAL0.printf(args)
|
2018-01-10 01:05:37 +00:00
|
|
|
|
2017-04-02 06:04:54 +00:00
|
|
|
#define SERIAL_PROTOCOLCHAR(x) SERIAL_CHAR(x)
|
2018-02-14 08:53:55 +00:00
|
|
|
#define SERIAL_PROTOCOL(x) MYSERIAL0.print(x)
|
|
|
|
#define SERIAL_PROTOCOL_F(x,y) MYSERIAL0.print(x,y)
|
2018-01-10 01:05:37 +00:00
|
|
|
#define SERIAL_PROTOCOLPGM(x) serialprintPGM(PSTR(x))
|
2018-02-14 08:53:55 +00:00
|
|
|
#define SERIAL_PROTOCOLLN(x) do{ MYSERIAL0.print(x); SERIAL_EOL(); }while(0)
|
2018-01-10 01:05:37 +00:00
|
|
|
#define SERIAL_PROTOCOLLNPGM(x) serialprintPGM(PSTR(x "\n"))
|
2018-02-16 23:35:26 +00:00
|
|
|
#define SERIAL_PROTOCOLPAIR(name, value) serial_echopair_PGM(PSTR(name),(value))
|
2017-06-09 15:51:23 +00:00
|
|
|
#define SERIAL_PROTOCOLLNPAIR(name, value) do{ SERIAL_PROTOCOLPAIR(name, value); SERIAL_EOL(); }while(0)
|
2017-04-02 06:04:54 +00:00
|
|
|
|
2018-01-10 01:05:37 +00:00
|
|
|
#define SERIAL_ECHO_START() serialprintPGM(echomagic)
|
2017-04-02 06:04:54 +00:00
|
|
|
#define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
|
|
|
|
#define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
|
|
|
|
#define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
|
|
|
|
#define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
|
2017-09-24 20:05:27 +00:00
|
|
|
#define SERIAL_ECHOPAIR(pre,value) SERIAL_PROTOCOLPAIR(pre, value)
|
|
|
|
#define SERIAL_ECHOLNPAIR(pre,value) SERIAL_PROTOCOLLNPAIR(pre, value)
|
2017-04-02 06:04:54 +00:00
|
|
|
#define SERIAL_ECHO_F(x,y) SERIAL_PROTOCOL_F(x,y)
|
|
|
|
|
2018-01-10 01:05:37 +00:00
|
|
|
#define SERIAL_ERROR_START() serialprintPGM(errormagic)
|
2017-04-02 06:04:54 +00:00
|
|
|
#define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
|
|
|
|
#define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
|
|
|
|
#define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
|
|
|
|
#define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
|
|
|
|
|
2017-04-01 01:06:38 +00:00
|
|
|
// These macros compensate for float imprecision
|
2017-09-24 20:05:27 +00:00
|
|
|
#define SERIAL_PROTOCOLPAIR_F(pre, value) SERIAL_PROTOCOLPAIR(pre, FIXFLOAT(value))
|
|
|
|
#define SERIAL_PROTOCOLLNPAIR_F(pre, value) SERIAL_PROTOCOLLNPAIR(pre, FIXFLOAT(value))
|
|
|
|
#define SERIAL_ECHOPAIR_F(pre,value) SERIAL_ECHOPAIR(pre, FIXFLOAT(value))
|
|
|
|
#define SERIAL_ECHOLNPAIR_F(pre, value) SERIAL_ECHOLNPAIR(pre, FIXFLOAT(value))
|
2017-04-01 01:06:38 +00:00
|
|
|
|
2018-02-16 23:35:26 +00:00
|
|
|
void serial_echopair_PGM(const char* s_P, const char *v);
|
|
|
|
void serial_echopair_PGM(const char* s_P, char v);
|
|
|
|
void serial_echopair_PGM(const char* s_P, int v);
|
|
|
|
void serial_echopair_PGM(const char* s_P, long v);
|
|
|
|
void serial_echopair_PGM(const char* s_P, float v);
|
|
|
|
void serial_echopair_PGM(const char* s_P, double v);
|
|
|
|
void serial_echopair_PGM(const char* s_P, unsigned int v);
|
|
|
|
void serial_echopair_PGM(const char* s_P, unsigned long v);
|
|
|
|
FORCE_INLINE void serial_echopair_PGM(const char* s_P, uint8_t v) { serial_echopair_PGM(s_P, (int)v); }
|
|
|
|
FORCE_INLINE void serial_echopair_PGM(const char* s_P, uint16_t v) { serial_echopair_PGM(s_P, (int)v); }
|
|
|
|
FORCE_INLINE void serial_echopair_PGM(const char* s_P, bool v) { serial_echopair_PGM(s_P, (int)v); }
|
|
|
|
FORCE_INLINE void serial_echopair_PGM(const char* s_P, void *v) { serial_echopair_PGM(s_P, (unsigned long)v); }
|
2017-04-02 06:04:54 +00:00
|
|
|
|
2017-04-28 22:15:39 +00:00
|
|
|
void serial_spaces(uint8_t count);
|
|
|
|
#define SERIAL_ECHO_SP(C) serial_spaces(C)
|
|
|
|
#define SERIAL_ERROR_SP(C) serial_spaces(C)
|
|
|
|
#define SERIAL_PROTOCOL_SP(C) serial_spaces(C)
|
|
|
|
|
2017-04-02 06:04:54 +00:00
|
|
|
//
|
|
|
|
// Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
|
|
|
|
//
|
|
|
|
FORCE_INLINE void serialprintPGM(const char* str) {
|
2018-02-14 08:53:55 +00:00
|
|
|
while (char ch = pgm_read_byte(str++)) MYSERIAL0.write(ch);
|
2017-04-02 06:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __SERIAL_H__
|