瀏覽代碼

Apply coding standards to Max7219 code

Scott Lahteine 7 年之前
父節點
當前提交
8f57a3e28a
共有 1 個檔案被更改,包括 50 行新增81 行删除
  1. 50
    81
      Marlin/Max7219_Debug_LEDs.cpp

+ 50
- 81
Marlin/Max7219_Debug_LEDs.cpp 查看文件

102
 
102
 
103
 void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
103
 void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
104
   if (row > 7 || col > 7) {
104
   if (row > 7 || col > 7) {
105
-    int r,c;
106
-    r = row;
107
-    c = col;
108
-    SERIAL_ECHOPAIR("??? Max7219_LED_Set(",r);
109
-    SERIAL_ECHOPAIR(",",c);
110
-    SERIAL_ECHO(")\n");
105
+    SERIAL_ECHOPAIR("??? Max7219_LED_Set(", (int)row);
106
+    SERIAL_ECHOPAIR(",", (int)col);
107
+    SERIAL_ECHOLNPGM(")");
111
     return;
108
     return;
112
   }
109
   }
113
   if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
110
   if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
117
 
114
 
118
 void Max7219_LED_On(const uint8_t col, const uint8_t row) {
115
 void Max7219_LED_On(const uint8_t col, const uint8_t row) {
119
   if (row > 7 || col > 7) {
116
   if (row > 7 || col > 7) {
120
-    int r,c;
121
-    r = row;
122
-    c = col;
123
-    SERIAL_ECHOPAIR("??? Max7219_LED_On(",c);
124
-    SERIAL_ECHOPAIR(",",r);
125
-    SERIAL_ECHO(")\n");
117
+    SERIAL_ECHOPAIR("??? Max7219_LED_On(", (int)col);
118
+    SERIAL_ECHOPAIR(",", (int)row);
119
+    SERIAL_ECHOLNPGM(")");
126
     return;
120
     return;
127
   }
121
   }
128
   Max7219_LED_Set(col, row, true);
122
   Max7219_LED_Set(col, row, true);
130
 
124
 
131
 void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
125
 void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
132
   if (row > 7 || col > 7) {
126
   if (row > 7 || col > 7) {
133
-    int r,c;
134
-    r = row;
135
-    c = col;
136
-    SERIAL_ECHOPAIR("??? Max7219_LED_Off(",r);
137
-    SERIAL_ECHOPAIR(",",c);
138
-    SERIAL_ECHO(")\n");
127
+    SERIAL_ECHOPAIR("??? Max7219_LED_Off(", (int)row);
128
+    SERIAL_ECHOPAIR(",", (int)col);
129
+    SERIAL_ECHOLNPGM(")");
139
     return;
130
     return;
140
   }
131
   }
141
   Max7219_LED_Set(col, row, false);
132
   Max7219_LED_Set(col, row, false);
143
 
134
 
144
 void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
135
 void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
145
   if (row > 7 || col > 7) {
136
   if (row > 7 || col > 7) {
146
-    int r,c;
147
-    r = row;
148
-    c = col;
149
-    SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(",r);
150
-    SERIAL_ECHOPAIR(",",c);
151
-    SERIAL_ECHO(")\n");
137
+    SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(", (int)row);
138
+    SERIAL_ECHOPAIR(",", (int)col);
139
+    SERIAL_ECHOLNPGM(")");
152
     return;
140
     return;
153
   }
141
   }
154
   if (TEST(LEDs[row], col))
142
   if (TEST(LEDs[row], col))
159
 
147
 
160
 void Max7219_Clear_Column(const uint8_t col) {
148
 void Max7219_Clear_Column(const uint8_t col) {
161
   if (col > 7) {
149
   if (col > 7) {
162
-    int c;
163
-    c = col;
164
-    SERIAL_ECHOPAIR("??? Max7219_Clear_Column(",c);
165
-    SERIAL_ECHO(")\n");
150
+    SERIAL_ECHOPAIR("??? Max7219_Clear_Column(", (int)col);
151
+    SERIAL_ECHOLNPGM(")");
166
     return;
152
     return;
167
   }
153
   }
168
   LEDs[col] = 0;
154
   LEDs[col] = 0;
171
 
157
 
172
 void Max7219_Clear_Row(const uint8_t row) {
158
 void Max7219_Clear_Row(const uint8_t row) {
173
   if (row > 7) {
159
   if (row > 7) {
174
-    int r;
175
-    r = row;
176
-    SERIAL_ECHOPAIR("??? Max7219_Clear_Row(",r);
177
-    SERIAL_ECHO(")\n");
160
+    SERIAL_ECHOPAIR("??? Max7219_Clear_Row(", (int)row);
161
+    SERIAL_ECHOLNPGM(")");
178
     return;
162
     return;
179
   }
163
   }
180
   for (uint8_t c = 0; c <= 7; c++)
164
   for (uint8_t c = 0; c <= 7; c++)
182
 }
166
 }
183
 
167
 
184
 void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
168
 void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
185
-  if (row > 7 || val>255) {
186
-    int r, v;
187
-    r = row;
188
-    v = val;
189
-    SERIAL_ECHOPAIR("??? Max7219_Set_Row(",r);
190
-    SERIAL_ECHOPAIR(",",v);
191
-    SERIAL_ECHO(")\n");
169
+  if (row > 7) {
170
+    SERIAL_ECHOPAIR("??? Max7219_Set_Row(", (int)row);
171
+    SERIAL_ECHOPAIR(",", (int)val);
172
+    SERIAL_ECHOLNPGM(")");
192
     return;
173
     return;
193
   }
174
   }
194
   for (uint8_t b = 0; b <= 7; b++)
175
   for (uint8_t b = 0; b <= 7; b++)
199
 }
180
 }
200
 
181
 
201
 void Max7219_Set_2_Rows(const uint8_t row, const uint16_t val) {
182
 void Max7219_Set_2_Rows(const uint8_t row, const uint16_t val) {
202
-  if (row > 6 || val>65535) {
203
-    int r, v;
204
-    r = row;
205
-    v = val;
206
-    SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(",r);
207
-    SERIAL_ECHOPAIR(",",v);
208
-    SERIAL_ECHO(")\n");
183
+  if (row > 6) {
184
+    SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(", (int)row);
185
+    SERIAL_ECHOPAIR(",", (int)val);
186
+    SERIAL_ECHOLNPGM(")");
209
     return;
187
     return;
210
   }
188
   }
211
-  Max7219_Set_Row(row+1, (val & 0xff00) >> 8 );
212
-  Max7219_Set_Row(row+0, (val & 0xff));
189
+  Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
190
+  Max7219_Set_Row(row + 0, (val     ) & 0xFF);
213
 }
191
 }
214
 
192
 
215
 void Max7219_Set_4_Rows(const uint8_t row, const uint32_t val) {
193
 void Max7219_Set_4_Rows(const uint8_t row, const uint32_t val) {
216
-  if (row > 4 ) {
217
-    int r;
218
-    long v;
219
-    r = row;
220
-    v = val;
221
-    SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(",r);
222
-    SERIAL_ECHOPAIR(",",v);
223
-    SERIAL_ECHO(")\n");
194
+  if (row > 4) {
195
+    SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(", (int)row);
196
+    SERIAL_ECHOPAIR(",", (long)val);
197
+    SERIAL_ECHOLNPGM(")");
224
     return;
198
     return;
225
   }
199
   }
226
-  Max7219_Set_Row(row+3, (val & 0xff000000) >> 24);
227
-  Max7219_Set_Row(row+2, (val & 0xff0000) >> 16);
228
-  Max7219_Set_Row(row+1, (val & 0xff00) >> 8);
229
-  Max7219_Set_Row(row+0, (val & 0xff));
200
+  Max7219_Set_Row(row + 3, (val >> 24) & 0xFF);
201
+  Max7219_Set_Row(row + 2, (val >> 16) & 0xFF);
202
+  Max7219_Set_Row(row + 1, (val >>  8) & 0xFF);
203
+  Max7219_Set_Row(row + 0, (val      ) & 0xFF);
230
 }
204
 }
231
 
205
 
232
 void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
206
 void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
233
-  if (val > 255 || col > 7) {
234
-    int v,c;
235
-    v = val;
236
-    c = col;
237
-    SERIAL_ECHOPAIR("??? Max7219_Column(",c);
238
-    SERIAL_ECHOPAIR(",",v);
239
-    SERIAL_ECHO(")\n");
207
+  if (col > 7) {
208
+    SERIAL_ECHOPAIR("??? Max7219_Column(", (int)col);
209
+    SERIAL_ECHOPAIR(",", (int)val);
210
+    SERIAL_ECHOLNPGM(")");
240
     return;
211
     return;
241
   }
212
   }
242
   LEDs[col] = val;
213
   LEDs[col] = val;
304
 #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
275
 #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
305
   CRITICAL_SECTION_START
276
   CRITICAL_SECTION_START
306
   #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
277
   #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
307
-    uint8_t head;
308
-    head = planner.block_buffer_head;
278
+    const uint8_t head = planner.block_buffer_head;
309
   #endif
279
   #endif
310
   #if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
280
   #if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
311
-    uint8_t tail;
312
-    tail = planner.block_buffer_tail;
281
+    const uint8_t tail = planner.block_buffer_tail;
313
   #endif
282
   #endif
314
   CRITICAL_SECTION_END
283
   CRITICAL_SECTION_END
315
 #endif
284
 #endif
323
   #endif
292
   #endif
324
 
293
 
325
   #ifdef MAX7219_DEBUG_STEPPER_HEAD
294
   #ifdef MAX7219_DEBUG_STEPPER_HEAD
326
-    static int16_t last_head_cnt=0;
295
+    static int16_t last_head_cnt = 0;
327
     if (last_head_cnt != head) {
296
     if (last_head_cnt != head) {
328
       if (last_head_cnt < 8)
297
       if (last_head_cnt < 8)
329
-        Max7219_LED_Off( last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
298
+        Max7219_LED_Off(last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
330
       else
299
       else
331
-        Max7219_LED_Off( last_head_cnt-8, MAX7219_DEBUG_STEPPER_HEAD+1);
300
+        Max7219_LED_Off(last_head_cnt - 8, MAX7219_DEBUG_STEPPER_HEAD + 1);
332
 
301
 
333
       last_head_cnt = head;
302
       last_head_cnt = head;
334
       if (head < 8)
303
       if (head < 8)
335
         Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
304
         Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
336
       else
305
       else
337
-        Max7219_LED_On(head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
306
+        Max7219_LED_On(head - 8, MAX7219_DEBUG_STEPPER_HEAD + 1);
338
     }
307
     }
339
   #endif
308
   #endif
340
 
309
 
341
   #ifdef MAX7219_DEBUG_STEPPER_TAIL
310
   #ifdef MAX7219_DEBUG_STEPPER_TAIL
342
-    static int16_t last_tail_cnt=0;
311
+    static int16_t last_tail_cnt = 0;
343
     if (last_tail_cnt != tail) {
312
     if (last_tail_cnt != tail) {
344
       if (last_tail_cnt < 8)
313
       if (last_tail_cnt < 8)
345
-        Max7219_LED_Off( last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
314
+        Max7219_LED_Off(last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
346
       else
315
       else
347
-        Max7219_LED_Off( last_tail_cnt-8, MAX7219_DEBUG_STEPPER_TAIL+1);
316
+        Max7219_LED_Off(last_tail_cnt - 8, MAX7219_DEBUG_STEPPER_TAIL + 1);
348
 
317
 
349
       last_tail_cnt = tail;
318
       last_tail_cnt = tail;
350
       if (tail < 8)
319
       if (tail < 8)
351
         Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
320
         Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
352
       else
321
       else
353
-        Max7219_LED_On(tail-8, MAX7219_DEBUG_STEPPER_TAIL+1);
322
+        Max7219_LED_On(tail - 8, MAX7219_DEBUG_STEPPER_TAIL + 1);
354
     }
323
     }
355
   #endif
324
   #endif
356
 
325
 
367
                     en = max(current_depth, last_depth);
336
                     en = max(current_depth, last_depth);
368
       if (current_depth < last_depth)
337
       if (current_depth < last_depth)
369
         for (uint8_t i = st; i <= en; i++)   // clear the highest order LEDs
338
         for (uint8_t i = st; i <= en; i++)   // clear the highest order LEDs
370
-          Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
339
+          Max7219_LED_Off(i / 2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
371
       else
340
       else
372
         for (uint8_t i = st; i <= en; i++)   // set the LEDs to current depth
341
         for (uint8_t i = st; i <= en; i++)   // set the LEDs to current depth
373
-          Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
342
+          Max7219_LED_On(i / 2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
374
 
343
 
375
       last_depth = current_depth;
344
       last_depth = current_depth;
376
     }
345
     }

Loading…
取消
儲存