Skip to content

Commit a098aef

Browse files
scottmudgeW4tel-BiDi
authored andcommitted
MeatPack followup (MarlinFirmware#20896)
1 parent f626de9 commit a098aef

File tree

1 file changed

+18
-43
lines changed

1 file changed

+18
-43
lines changed

Marlin/src/feature/meatpack.cpp

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
MeatPack meatpack;
4646

4747
#define MeatPack_ProtocolVersion "PV01"
48-
//#define MEATPACK_LOOKUP_TABLE
4948
//#define MP_DEBUG
5049

5150
#define DEBUG_OUT ENABLED(MP_DEBUG)
@@ -59,35 +58,13 @@ uint8_t MeatPack::cmd_count = 0, // Counts how many command bytes are r
5958
MeatPack::char_out_count = 0; // Stores number of characters to be read out.
6059
uint8_t MeatPack::char_out_buf[2]; // Output buffer for caching up to 2 characters
6160

62-
#if ENABLED(MEATPACK_LOOKUP_TABLE)
63-
// The 15 most-common characters used in G-code, ~90-95% of all G-code uses these characters
64-
// Stored in SRAM for performance.
65-
static const uint8_t meatPackLookupTable[16] = {
66-
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
67-
'.', ' ', '\n', 'G', 'X',
68-
'\0' // Unused. 0b1111 indicates a literal character
69-
};
70-
#endif
71-
72-
uint8_t MeatPack::unpacked_char(register const uint8_t in) {
73-
#if ENABLED(MEATPACK_LOOKUP_TABLE)
74-
75-
return meatPackLookupTable[in];
76-
77-
#else
78-
79-
switch (in) {
80-
case 0b0000 ... 0b1001: return '0' + in;
81-
case 0b1010: return '.';
82-
case 0b1011: return (state & MPConfig_Bit_NoSpaces) ? kSpaceCharReplace : ' ';
83-
case 0b1100: return '\n';
84-
case 0b1101: return 'G';
85-
case 0b1110: return 'X';
86-
}
87-
return 0;
88-
89-
#endif
90-
}
61+
// The 15 most-common characters used in G-code, ~90-95% of all G-code uses these characters
62+
// Stored in SRAM for performance.
63+
uint8_t meatPackLookupTable[16] = {
64+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
65+
'.', ' ', '\n', 'G', 'X',
66+
'\0' // Unused. 0b1111 indicates a literal character
67+
};
9168

9269
TERN_(MP_DEBUG, uint8_t chars_decoded = 0); // Log the first 64 bytes after each reset
9370

@@ -112,15 +89,15 @@ uint8_t MeatPack::unpack_chars(const uint8_t pk, uint8_t* __restrict const chars
11289
out = kFirstCharIsLiteral;
11390
else {
11491
const uint8_t chr = pk & 0x0F;
115-
chars_out[0] = unpacked_char(chr); // Set the first char
92+
chars_out[0] = meatPackLookupTable[(uint8_t)chr]; // Set the first char
11693
}
11794

11895
// Check if upper nybble is 1111... if so, we don't need the second char.
11996
if ((pk & kSecondNotPacked) == kSecondNotPacked)
12097
out |= kSecondCharIsLiteral;
12198
else {
12299
const uint8_t chr = (pk >> 4) & 0x0F;
123-
chars_out[1] = unpacked_char(chr); // Set the second char
100+
chars_out[1] = meatPackLookupTable[(uint8_t)chr]; // Set the second char
124101
}
125102

126103
return out;
@@ -184,18 +161,18 @@ void MeatPack::handle_output_char(const uint8_t c) {
184161
*/
185162
void MeatPack::handle_command(const MeatPack_Command c) {
186163
switch (c) {
164+
case MPCommand_QueryConfig: break;
187165
case MPCommand_EnablePacking: SBI(state, MPConfig_Bit_Active); DEBUG_ECHOLNPGM("[MPDBG] ENA REC"); break;
188166
case MPCommand_DisablePacking: CBI(state, MPConfig_Bit_Active); DEBUG_ECHOLNPGM("[MPDBG] DIS REC"); break;
189167
case MPCommand_TogglePacking: TBI(state, MPConfig_Bit_Active); DEBUG_ECHOLNPGM("[MPDBG] TGL REC"); break;
190168
case MPCommand_ResetAll: reset_state(); DEBUG_ECHOLNPGM("[MPDBG] RESET REC"); break;
191-
case MPCommand_EnableNoSpaces: SBI(state, MPConfig_Bit_NoSpaces); DEBUG_ECHOLNPGM("[MPDBG] ENA NSP");
192-
TERN_(USE_LOOKUP_TABLE, MeatPackLookupTbl[kSpaceCharIdx] = kSpaceCharReplace);
193-
break;
194-
case MPCommand_DisableNoSpaces: CBI(state, MPConfig_Bit_NoSpaces); DEBUG_ECHOLNPGM("[MPDBG] DIS NSP");
195-
TERN_(USE_LOOKUP_TABLE, MeatPackLookupTbl[kSpaceCharIdx] = ' ');
196-
break;
169+
case MPCommand_EnableNoSpaces:
170+
SBI(state, MPConfig_Bit_NoSpaces);
171+
meatPackLookupTable[kSpaceCharIdx] = kSpaceCharReplace; DEBUG_ECHOLNPGM("[MPDBG] ENA NSP"); break;
172+
case MPCommand_DisableNoSpaces:
173+
CBI(state, MPConfig_Bit_NoSpaces);
174+
meatPackLookupTable[kSpaceCharIdx] = ' '; DEBUG_ECHOLNPGM("[MPDBG] DIS NSP"); break;
197175
default: DEBUG_ECHOLNPGM("[MPDBG] UNK CMD REC");
198-
case MPCommand_QueryConfig: break;
199176
}
200177
report_state();
201178
}
@@ -204,11 +181,9 @@ void MeatPack::report_state() {
204181
// NOTE: if any configuration vars are added below, the outgoing sync text for host plugin
205182
// should not contain the "PV' substring, as this is used to indicate protocol version
206183
SERIAL_ECHOPGM("[MP] ");
207-
SERIAL_ECHOPGM(MeatPack_ProtocolVersion);
184+
SERIAL_ECHOPGM(MeatPack_ProtocolVersion " ");
208185
serialprint_onoff(TEST(state, MPConfig_Bit_Active));
209-
SERIAL_CHAR(' ');
210-
serialprintPGM(TEST(state, MPConfig_Bit_NoSpaces) ? PSTR("NSP") : PSTR("ESP"));
211-
SERIAL_EOL();
186+
serialprintPGM(TEST(state, MPConfig_Bit_NoSpaces) ? PSTR(" NSP\n") : PSTR(" ESP\n"));
212187
}
213188

214189
/**

0 commit comments

Comments
 (0)