communication.h 4.38 KB
Newer Older
MagoKimbra's avatar
MagoKimbra committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/**
 * MK & MK4due 3D Printer Firmware
 *
 * Based on Marlin, Sprinter and grbl
 * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
 * Copyright (C) 2013 - 2016 Alberto Cotronei @MagoKimbra
 *
 * 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
MagoKimbra's avatar
MagoKimbra committed
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MagoKimbra's avatar
MagoKimbra committed
16 17 18
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
MagoKimbra's avatar
MagoKimbra committed
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
MagoKimbra's avatar
MagoKimbra committed
20 21 22
 *
 */

MagoKimbra's avatar
MagoKimbra committed
23 24 25
#ifndef COMMUNICATION_H
  #define COMMUNICATION_H

MagoKimbra's avatar
MagoKimbra committed
26
  #define START       "start"               // start for host
MagoKimbra's avatar
MagoKimbra committed
27 28 29 30 31 32 33 34 35 36
  #define OK          "ok"                  // ok answer for host
  #define ER          "Error:"              // error for host
  #define WT          "wait"                // wait for host
  #define DB          "Echo:"               // message for user
  #define DEB         "Debug:"              // message for debug
  #define CFG         "Config:"             // config for host
  #define INFO        "Info:"               // info for host
  #define BUSY        "busy:"               // buys for host
  #define RESEND      "Resend:"             // resend for host
  #define WARNING     "Warning:"            // warning for host
MagoKimbra's avatar
MagoKimbra committed
37 38 39 40 41
  #define TNAN        "NAN"                 // NAN for host
  #define TINF        "INF"                 // INF for host
  #define PAUSE       "//action:pause"      // command for host that support action
  #define RESUME      "//action:resume"     // command for host that support action
  #define DISCONNECT  "//action:disconnect" // command for host that support action
MagoKimbra's avatar
MagoKimbra committed
42

MagoKimbra's avatar
MagoKimbra committed
43
  #define SERIAL_INIT(baud)           MKSERIAL.begin(baud), HAL::delayMilliseconds(1)
MagoKimbra's avatar
MagoKimbra committed
44 45 46
  #define SERIAL_WRITE(x)             MKSERIAL.write(x)
  #define SERIAL_PRINT(msg, args...)  MKSERIAL.print(msg, ##args)
  #define SERIAL_ENDL                 MKSERIAL.println()
MagoKimbra's avatar
MagoKimbra committed
47

MagoKimbra's avatar
MagoKimbra committed
48 49 50 51 52 53 54
  FORCE_INLINE void PS_PGM(const char *str) {
    char c;
    while (c = pgm_read_byte(str)) {
      SERIAL_WRITE(c);
      str++;
    }
  }
MagoKimbra's avatar
MagoKimbra committed
55

MagoKimbra's avatar
MagoKimbra committed
56 57 58 59 60 61 62 63 64
  #define ECHO_ENDL                         SERIAL_ENDL
  #define ECHO_PGM(message)                 PS_PGM(PSTR(message))

  #define ECHO_S(srt)                       ECHO_PGM(srt)
  #define ECHO_M(msg)                       ECHO_PGM(msg)
  #define ECHO_T                            SERIAL_PRINT
  #define ECHO_V                            SERIAL_PRINT
  #define ECHO_C                            SERIAL_WRITE
  #define ECHO_E                            SERIAL_ENDL
MagoKimbra's avatar
MagoKimbra committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

  #define ECHO_MV(msg, val, args...)        ECHO_M(msg),ECHO_V(val, ##args)
  #define ECHO_VM(val, msg, args...)        ECHO_V(val, ##args),ECHO_M(msg)
  #define ECHO_MT(msg, txt)                 ECHO_M(msg),ECHO_T(txt)
  #define ECHO_TM(txt, msg)                 ECHO_T(txt),ECHO_M(msg)

  #define ECHO_SM(srt, msg)                 ECHO_S(srt),ECHO_M(msg)
  #define ECHO_ST(srt, txt)                 ECHO_S(srt),ECHO_T(txt)
  #define ECHO_SV(srt, val, args...)        ECHO_S(srt),ECHO_V(val, ##args)
  #define ECHO_SMV(srt, msg, val, args...)  ECHO_S(srt),ECHO_MV(msg, val, ##args)
  #define ECHO_SMT(srt, msg, txt)           ECHO_S(srt),ECHO_MT(msg, txt)

  #define ECHO_EM(msg)                      ECHO_M(msg),ECHO_E
  #define ECHO_ET(txt)                      ECHO_T(txt),ECHO_E
  #define ECHO_EV(val, args...)             ECHO_V(val, ##args),ECHO_E
  #define ECHO_EMV(msg, val, args...)       ECHO_MV(msg, val, ##args),ECHO_E
  #define ECHO_EVM(val, msg, args...)       ECHO_VM(val, msg, ##args),ECHO_E
  #define ECHO_EMT(msg, txt)                ECHO_MT(msg, txt),ECHO_E

  #define ECHO_L(srt)                       ECHO_S(srt),ECHO_E
  #define ECHO_LM(srt, msg)                 ECHO_S(srt),ECHO_M(msg),ECHO_E
  #define ECHO_LT(srt, txt)                 ECHO_S(srt),ECHO_T(txt),ECHO_E
  #define ECHO_LV(srt, val, args...)        ECHO_S(srt),ECHO_V(val, ##args),ECHO_E
  #define ECHO_LMV(srt, msg, val, args...)  ECHO_S(srt),ECHO_MV(msg, val, ##args),ECHO_E
  #define ECHO_LVM(srt, val, msg, args...)  ECHO_S(srt),ECHO_VM(val, msg, ##args),ECHO_E
  #define ECHO_LMT(srt, msg, txt)           ECHO_S(srt),ECHO_MT(msg, txt),ECHO_E

#endif