Skip to content

Commit

Permalink
MeatPack gcode compression support
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmudge committed Apr 6, 2023
1 parent 373fab8 commit a9822c2
Show file tree
Hide file tree
Showing 7 changed files with 659 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(FW_SOURCES
lcd.cpp
Marlin_main.cpp
MarlinSerial.cpp
meatpack.cpp
menu.cpp
mesh_bed_calibration.cpp
mesh_bed_leveling.cpp
Expand Down Expand Up @@ -177,6 +178,7 @@ set(FW_SOURCES
spi.c
SpoolJoin.cpp
stepper.cpp
strtod.c
swi2c.c
Tcodes.cpp
temperature.cpp
Expand Down
3 changes: 3 additions & 0 deletions Firmware/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ extern const char _sPrinterMmuName[] PROGMEM;
// This determines the communication speed of the printer
#define BAUDRATE 115200

// Enable g-code compression (see https://github.com/scottmudge/OctoPrint-MeatPack)
#define ENABLE_MEATPACK

// This enables the serial port associated to the Bluetooth interface
//#define BTENABLED // Enable BT interface on AT90USB devices

Expand Down
17 changes: 17 additions & 0 deletions Firmware/cmdqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "cardreader.h"
#include "ultralcd.h"
#include "Prusa_farm.h"
#include "meatpack.h"

// Reserve BUFSIZE lines of length MAX_CMD_SIZE plus CMDBUFFER_RESERVE_FRONT.
char cmdbuffer[BUFSIZE * (MAX_CMD_SIZE + 1) + CMDBUFFER_RESERVE_FRONT];
Expand Down Expand Up @@ -365,7 +366,20 @@ void get_command()
// start of serial line processing loop
while (((MYSERIAL.available() > 0 && !saved_printing) || (MYSERIAL.available() > 0 && isPrintPaused)) && !cmdqueue_serial_disabled) { //is print is saved (crash detection or filament detection), dont process data from serial line

#ifdef ENABLE_MEATPACK
// MeatPack Changes
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const int rec = MYSERIAL.read();
if (rec < 0) continue;

mp_handle_rx_char((uint8_t)rec);
char c_res[2] = {0, 0};
const uint8_t char_count = mp_get_result_char(c_res);
// Note -- Paired bracket in preproc switch below
for (uint8_t i = 0; i < char_count; ++i) { char serial_char = c_res[i];
#else
char serial_char = MYSERIAL.read();
#endif

serialTimeoutTimer.start();

Expand Down Expand Up @@ -526,6 +540,9 @@ void get_command()
if(serial_char == ';') comment_mode = true;
if(!comment_mode) cmdbuffer[bufindw+CMDHDRSIZE+serial_count++] = serial_char;
}
#ifdef ENABLE_MEATPACK
}
#endif
} // end of serial line processing loop

if (serial_count > 0 && serialTimeoutTimer.expired(farm_mode ? 800 : 2000)) {
Expand Down
11 changes: 10 additions & 1 deletion Firmware/cmdqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ extern void repeatcommand_front();
extern void get_command();
extern uint16_t cmdqueue_calc_sd_length();


#if defined(__cplusplus)
extern "C" {
#endif
extern double strtod_noE(const char* nptr, char** endptr);
#if defined(__cplusplus)
}
#endif

// Return True if a character was found
static inline bool code_seen(char code) { return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
static inline bool code_seen_P(const char *code_PROGMEM) { return (strchr_pointer = strstr_P(CMDBUFFER_CURRENT_STRING, code_PROGMEM)) != NULL; }
static inline float code_value() { return strtod(strchr_pointer+1, NULL);}
static inline float code_value() { return strtod_noE(strchr_pointer+1, NULL);}
static inline long code_value_long() { return strtol(strchr_pointer+1, NULL, 10); }
static inline int16_t code_value_short() { return int16_t(strtol(strchr_pointer+1, NULL, 10)); };
static inline uint8_t code_value_uint8() { return uint8_t(strtol(strchr_pointer+1, NULL, 10)); };
Expand Down
Loading

0 comments on commit a9822c2

Please sign in to comment.