Browse Source

MeatPack followup (#20896)

Scott Mudge 4 years ago
parent
commit
5e5dfff6fe
No account linked to committer's email address
1 changed files with 18 additions and 43 deletions
  1. 18
    43
      Marlin/src/feature/meatpack.cpp

+ 18
- 43
Marlin/src/feature/meatpack.cpp View File

@@ -45,7 +45,6 @@
45 45
 MeatPack meatpack;
46 46
 
47 47
 #define MeatPack_ProtocolVersion "PV01"
48
-//#define MEATPACK_LOOKUP_TABLE
49 48
 //#define MP_DEBUG
50 49
 
51 50
 #define DEBUG_OUT ENABLED(MP_DEBUG)
@@ -59,35 +58,13 @@ uint8_t MeatPack::cmd_count = 0,          // Counts how many command bytes are r
59 58
         MeatPack::char_out_count = 0;     // Stores number of characters to be read out.
60 59
 uint8_t MeatPack::char_out_buf[2];        // Output buffer for caching up to 2 characters
61 60
 
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
+};
91 68
 
92 69
 TERN_(MP_DEBUG, uint8_t chars_decoded = 0); // Log the first 64 bytes after each reset
93 70
 
@@ -112,7 +89,7 @@ uint8_t MeatPack::unpack_chars(const uint8_t pk, uint8_t* __restrict const chars
112 89
     out = kFirstCharIsLiteral;
113 90
   else {
114 91
     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
116 93
   }
117 94
 
118 95
   // Check if upper nybble is 1111... if so, we don't need the second char.
@@ -120,7 +97,7 @@ uint8_t MeatPack::unpack_chars(const uint8_t pk, uint8_t* __restrict const chars
120 97
     out |= kSecondCharIsLiteral;
121 98
   else {
122 99
     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
124 101
   }
125 102
 
126 103
   return out;
@@ -184,18 +161,18 @@ void MeatPack::handle_output_char(const uint8_t c) {
184 161
  */
185 162
 void MeatPack::handle_command(const MeatPack_Command c) {
186 163
   switch (c) {
164
+    case MPCommand_QueryConfig:     break;
187 165
     case MPCommand_EnablePacking:   SBI(state, MPConfig_Bit_Active);   DEBUG_ECHOLNPGM("[MPDBG] ENA REC");   break;
188 166
     case MPCommand_DisablePacking:  CBI(state, MPConfig_Bit_Active);   DEBUG_ECHOLNPGM("[MPDBG] DIS REC");   break;
189 167
     case MPCommand_TogglePacking:   TBI(state, MPConfig_Bit_Active);   DEBUG_ECHOLNPGM("[MPDBG] TGL REC");   break;
190 168
     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;
197 175
     default:                                                           DEBUG_ECHOLNPGM("[MPDBG] UNK CMD REC");
198
-    case MPCommand_QueryConfig: break;
199 176
   }
200 177
   report_state();
201 178
 }
@@ -204,11 +181,9 @@ void MeatPack::report_state() {
204 181
   // NOTE: if any configuration vars are added below, the outgoing sync text for host plugin
205 182
   // should not contain the "PV' substring, as this is used to indicate protocol version
206 183
   SERIAL_ECHOPGM("[MP] ");
207
-  SERIAL_ECHOPGM(MeatPack_ProtocolVersion);
184
+  SERIAL_ECHOPGM(MeatPack_ProtocolVersion " ");
208 185
   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"));
212 187
 }
213 188
 
214 189
 /**

Loading…
Cancel
Save