Kaynağa Gözat

get rid of indirect ringbuffer calls, made some inlines, removed virtual and streaming class requirements.

Bernhard 13 yıl önce
ebeveyn
işleme
dd5ca68c87
6 değiştirilmiş dosya ile 385 ekleme ve 187 silme
  1. 202
    38
      Marlin/MarlinSerial.cpp
  2. 83
    12
      Marlin/MarlinSerial.h
  3. 42
    74
      Marlin/SdBaseFile.cpp
  4. 4
    9
      Marlin/SdBaseFile.h
  5. 7
    7
      Marlin/SdFatUtil.cpp
  6. 47
    47
      Marlin/SdFatUtil.h

+ 202
- 38
Marlin/MarlinSerial.cpp Dosyayı Görüntüle

@@ -33,35 +33,25 @@
33 33
 
34 34
 #include "MarlinSerial.h"
35 35
 
36
-// Define constants and variables for buffering incoming serial data.  We're
37
-// using a ring buffer (I think), in which rx_buffer_head is the index of the
38
-// location to which to write the next incoming character and rx_buffer_tail
39
-// is the index of the location from which to read.
40
-#define RX_BUFFER_SIZE 128
41 36
 
42
-struct ring_buffer
43
-{
44
-  unsigned char buffer[RX_BUFFER_SIZE];
45
-  int head;
46
-  int tail;
47
-};
37
+
48 38
 
49 39
 #if defined(UBRRH) || defined(UBRR0H)
50 40
   ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
51 41
 #endif
52 42
 
53 43
 
54
-inline void store_char(unsigned char c, ring_buffer *rx_buffer)
44
+inline void store_char(unsigned char c)
55 45
 {
56
-  int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;
46
+  int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
57 47
 
58 48
   // if we should be storing the received character into the location
59 49
   // just before the tail (meaning that the head would advance to the
60 50
   // current location of the tail), we're about to overflow the buffer
61 51
   // and so we don't write the character or advance the head.
62
-  if (i != rx_buffer->tail) {
63
-    rx_buffer->buffer[rx_buffer->head] = c;
64
-    rx_buffer->head = i;
52
+  if (i != rx_buffer.tail) {
53
+    rx_buffer.buffer[rx_buffer.head] = c;
54
+    rx_buffer.head = i;
65 55
   }
66 56
 }
67 57
 
@@ -79,19 +69,18 @@ inline void store_char(unsigned char c, ring_buffer *rx_buffer)
79 69
   #else
80 70
     #error UDR not defined
81 71
   #endif
82
-    store_char(c, &rx_buffer);
72
+    store_char(c);
83 73
   }
84 74
 #endif
85 75
 
86 76
 // Constructors ////////////////////////////////////////////////////////////////
87 77
 
88
-MarlinSerial::MarlinSerial(ring_buffer *rx_buffer,
78
+MarlinSerial::MarlinSerial(
89 79
   volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
90 80
   volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
91 81
   volatile uint8_t *udr,
92 82
   uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
93 83
 {
94
-  _rx_buffer = rx_buffer;
95 84
   _ubrrh = ubrrh;
96 85
   _ubrrl = ubrrl;
97 86
   _ucsra = ucsra;
@@ -144,28 +133,25 @@ void MarlinSerial::end()
144 133
   cbi(*_ucsrb, _rxcie);  
145 134
 }
146 135
 
147
-int MarlinSerial::available(void)
148
-{
149
-  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
150
-}
136
+
151 137
 
152 138
 int MarlinSerial::peek(void)
153 139
 {
154
-  if (_rx_buffer->head == _rx_buffer->tail) {
140
+  if (rx_buffer.head == rx_buffer.tail) {
155 141
     return -1;
156 142
   } else {
157
-    return _rx_buffer->buffer[_rx_buffer->tail];
143
+    return rx_buffer.buffer[rx_buffer.tail];
158 144
   }
159 145
 }
160 146
 
161 147
 int MarlinSerial::read(void)
162 148
 {
163 149
   // if the head isn't ahead of the tail, we don't have any characters
164
-  if (_rx_buffer->head == _rx_buffer->tail) {
150
+  if (rx_buffer.head == rx_buffer.tail) {
165 151
     return -1;
166 152
   } else {
167
-    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
168
-    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
153
+    unsigned char c = rx_buffer.buffer[rx_buffer.tail];
154
+    rx_buffer.tail = (unsigned int)(rx_buffer.tail + 1) % RX_BUFFER_SIZE;
169 155
     return c;
170 156
   }
171 157
 }
@@ -181,29 +167,207 @@ void MarlinSerial::flush()
181 167
   // the value to rx_buffer_tail; the previous value of rx_buffer_head
182 168
   // may be written to rx_buffer_tail, making it appear as if the buffer
183 169
   // were full, not empty.
184
-  _rx_buffer->head = _rx_buffer->tail;
170
+  rx_buffer.head = rx_buffer.tail;
185 171
 }
186 172
 
187
-void MarlinSerial::write(uint8_t c)
173
+
174
+
175
+
176
+/// imports from print.h
177
+/* default implementation: may be overridden */
178
+void MarlinSerial::write(const char *str)
188 179
 {
189
-  while (!((*_ucsra) & (1 << _udre)))
190
-    ;
180
+  while (*str)
181
+    write(*str++);
182
+}
191 183
 
192
-  *_udr = c;
184
+/* default implementation: may be overridden */
185
+void MarlinSerial::write(const uint8_t *buffer, size_t size)
186
+{
187
+  while (size--)
188
+    write(*buffer++);
193 189
 }
194 190
 
195
-void MarlinSerial::checkRx()
191
+void MarlinSerial::print(const String &s)
196 192
 {
197
-  if((UCSR0A & (1<<RXC0)) != 0) {
198
-    unsigned char c  =  UDR0;
199
-    store_char(c, &rx_buffer);
193
+  for (int i = 0; i < s.length(); i++) {
194
+    write(s[i]);
200 195
   }
201 196
 }
202 197
 
198
+void MarlinSerial::print(const char str[])
199
+{
200
+  write(str);
201
+}
202
+
203
+void MarlinSerial::print(char c, int base)
204
+{
205
+  print((long) c, base);
206
+}
207
+
208
+void MarlinSerial::print(unsigned char b, int base)
209
+{
210
+  print((unsigned long) b, base);
211
+}
212
+
213
+void MarlinSerial::print(int n, int base)
214
+{
215
+  print((long) n, base);
216
+}
217
+
218
+void MarlinSerial::print(unsigned int n, int base)
219
+{
220
+  print((unsigned long) n, base);
221
+}
222
+
223
+void MarlinSerial::print(long n, int base)
224
+{
225
+  if (base == 0) {
226
+    write(n);
227
+  } else if (base == 10) {
228
+    if (n < 0) {
229
+      print('-');
230
+      n = -n;
231
+    }
232
+    printNumber(n, 10);
233
+  } else {
234
+    printNumber(n, base);
235
+  }
236
+}
237
+
238
+void MarlinSerial::print(unsigned long n, int base)
239
+{
240
+  if (base == 0) write(n);
241
+  else printNumber(n, base);
242
+}
243
+
244
+void MarlinSerial::print(double n, int digits)
245
+{
246
+  printFloat(n, digits);
247
+}
248
+
249
+void MarlinSerial::println(void)
250
+{
251
+  print('\r');
252
+  print('\n');  
253
+}
254
+
255
+void MarlinSerial::println(const String &s)
256
+{
257
+  print(s);
258
+  println();
259
+}
260
+
261
+void MarlinSerial::println(const char c[])
262
+{
263
+  print(c);
264
+  println();
265
+}
266
+
267
+void MarlinSerial::println(char c, int base)
268
+{
269
+  print(c, base);
270
+  println();
271
+}
272
+
273
+void MarlinSerial::println(unsigned char b, int base)
274
+{
275
+  print(b, base);
276
+  println();
277
+}
278
+
279
+void MarlinSerial::println(int n, int base)
280
+{
281
+  print(n, base);
282
+  println();
283
+}
284
+
285
+void MarlinSerial::println(unsigned int n, int base)
286
+{
287
+  print(n, base);
288
+  println();
289
+}
290
+
291
+void MarlinSerial::println(long n, int base)
292
+{
293
+  print(n, base);
294
+  println();
295
+}
296
+
297
+void MarlinSerial::println(unsigned long n, int base)
298
+{
299
+  print(n, base);
300
+  println();
301
+}
302
+
303
+void MarlinSerial::println(double n, int digits)
304
+{
305
+  print(n, digits);
306
+  println();
307
+}
308
+
309
+// Private Methods /////////////////////////////////////////////////////////////
310
+
311
+void MarlinSerial::printNumber(unsigned long n, uint8_t base)
312
+{
313
+  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
314
+  unsigned long i = 0;
315
+
316
+  if (n == 0) {
317
+    print('0');
318
+    return;
319
+  } 
320
+
321
+  while (n > 0) {
322
+    buf[i++] = n % base;
323
+    n /= base;
324
+  }
325
+
326
+  for (; i > 0; i--)
327
+    print((char) (buf[i - 1] < 10 ?
328
+      '0' + buf[i - 1] :
329
+      'A' + buf[i - 1] - 10));
330
+}
331
+
332
+void MarlinSerial::printFloat(double number, uint8_t digits) 
333
+{ 
334
+  // Handle negative numbers
335
+  if (number < 0.0)
336
+  {
337
+     print('-');
338
+     number = -number;
339
+  }
340
+
341
+  // Round correctly so that print(1.999, 2) prints as "2.00"
342
+  double rounding = 0.5;
343
+  for (uint8_t i=0; i<digits; ++i)
344
+    rounding /= 10.0;
345
+  
346
+  number += rounding;
347
+
348
+  // Extract the integer part of the number and print it
349
+  unsigned long int_part = (unsigned long)number;
350
+  double remainder = number - (double)int_part;
351
+  print(int_part);
352
+
353
+  // Print the decimal point, but only if there are digits beyond
354
+  if (digits > 0)
355
+    print("."); 
356
+
357
+  // Extract digits from the remainder one at a time
358
+  while (digits-- > 0)
359
+  {
360
+    remainder *= 10.0;
361
+    int toPrint = int(remainder);
362
+    print(toPrint);
363
+    remainder -= toPrint; 
364
+  } 
365
+}
366
+
203 367
 // Preinstantiate Objects //////////////////////////////////////////////////////
204 368
 
205 369
 #if defined(UBRR0H) && defined(UBRR0L)
206
-  MarlinSerial MSerial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
370
+  MarlinSerial MSerial( &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
207 371
 #else
208 372
   #error no serial port defined  (port 0)
209 373
 #endif

+ 83
- 12
Marlin/MarlinSerial.h Dosyayı Görüntüle

@@ -23,15 +23,30 @@
23 23
 #define MarlinSerial_h
24 24
 
25 25
 #include <inttypes.h>
26
+#include <Stream.h>
26 27
 
27
-#include "Stream.h"
28 28
 
29
-struct ring_buffer;
29
+// Define constants and variables for buffering incoming serial data.  We're
30
+// using a ring buffer (I think), in which rx_buffer_head is the index of the
31
+// location to which to write the next incoming character and rx_buffer_tail
32
+// is the index of the location from which to read.
33
+#define RX_BUFFER_SIZE 128
30 34
 
31
-class MarlinSerial : public Stream
35
+
36
+struct ring_buffer
37
+{
38
+  unsigned char buffer[RX_BUFFER_SIZE];
39
+  int head;
40
+  int tail;
41
+};
42
+
43
+#if defined(UBRRH) || defined(UBRR0H)
44
+  extern ring_buffer rx_buffer;
45
+#endif
46
+
47
+class MarlinSerial //: public Stream
32 48
 {
33 49
   private:
34
-    ring_buffer *_rx_buffer;
35 50
     volatile uint8_t *_ubrrh;
36 51
     volatile uint8_t *_ubrrl;
37 52
     volatile uint8_t *_ucsra;
@@ -43,20 +58,76 @@ class MarlinSerial : public Stream
43 58
     uint8_t _udre;
44 59
     uint8_t _u2x;
45 60
   public:
46
-    MarlinSerial(ring_buffer *rx_buffer,
61
+    MarlinSerial(
47 62
       volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
48 63
       volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
49 64
       volatile uint8_t *udr,
50 65
       uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
51 66
     void begin(long);
52 67
     void end();
53
-    virtual int available(void);
54
-    virtual int peek(void);
55
-    virtual int read(void);
56
-    virtual void flush(void);
57
-    virtual void write(uint8_t);
58
-    virtual void checkRx(void);
59
-    using Print::write; // pull in write(str) and write(buf, size) from Print
68
+    inline int available(void)
69
+    {
70
+      return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
71
+    }
72
+    int peek(void);
73
+    int read(void);
74
+    void flush(void);
75
+    inline void write(uint8_t c)
76
+    {
77
+      while (!((*_ucsra) & (1 << _udre)))
78
+        ;
79
+
80
+      *_udr = c;
81
+    }
82
+    
83
+    
84
+    inline void checkRx(void)
85
+    {
86
+      if((UCSR0A & (1<<RXC0)) != 0) {
87
+        unsigned char c  =  UDR0;
88
+        int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
89
+
90
+        // if we should be storing the received character into the location
91
+        // just before the tail (meaning that the head would advance to the
92
+        // current location of the tail), we're about to overflow the buffer
93
+        // and so we don't write the character or advance the head.
94
+        if (i != rx_buffer.tail) {
95
+          rx_buffer.buffer[rx_buffer.head] = c;
96
+          rx_buffer.head = i;
97
+        }
98
+      }
99
+    }
100
+    
101
+    
102
+    private:
103
+    void printNumber(unsigned long, uint8_t);
104
+    void printFloat(double, uint8_t);
105
+    
106
+    
107
+  public:
108
+    void write(const char *str);
109
+    void write( const uint8_t *buffer, size_t size);
110
+    
111
+    void print(const String &);
112
+    void print(const char[]);
113
+    void print(char, int = BYTE);
114
+    void print(unsigned char, int = BYTE);
115
+    void print(int, int = DEC);
116
+    void print(unsigned int, int = DEC);
117
+    void print(long, int = DEC);
118
+    void print(unsigned long, int = DEC);
119
+    void print(double, int = 2);
120
+
121
+    void println(const String &s);
122
+    void println(const char[]);
123
+    void println(char, int = BYTE);
124
+    void println(unsigned char, int = BYTE);
125
+    void println(int, int = DEC);
126
+    void println(unsigned int, int = DEC);
127
+    void println(long, int = DEC);
128
+    void println(unsigned long, int = DEC);
129
+    void println(double, int = 2);
130
+    void println(void);
60 131
 };
61 132
 
62 133
 #if defined(UBRRH) || defined(UBRR0H)

+ 42
- 74
Marlin/SdBaseFile.cpp Dosyayı Görüntüle

@@ -17,6 +17,8 @@
17 17
  * along with the Arduino SdFat Library.  If not, see
18 18
  * <http://www.gnu.org/licenses/>.
19 19
  */
20
+
21
+#define SERIAL MSerial
20 22
 #include "SdBaseFile.h"
21 23
 //------------------------------------------------------------------------------
22 24
 // pointer to cwd directory
@@ -294,20 +296,7 @@ void SdBaseFile::getpos(fpos_t* pos) {
294 296
   pos->position = curPosition_;
295 297
   pos->cluster = curCluster_;
296 298
 }
297
-//------------------------------------------------------------------------------
298
-/** List directory contents to Serial.
299
- *
300
- * \param[in] flags The inclusive OR of
301
- *
302
- * LS_DATE - %Print file modification date
303
- *
304
- * LS_SIZE - %Print file size.
305
- *
306
- * LS_R - Recursive list of subdirectories.
307
- */
308
-void SdBaseFile::ls(uint8_t flags) {
309
-  ls(&MSerial, flags, 0);
310
-}
299
+
311 300
 //------------------------------------------------------------------------------
312 301
 /** List directory contents.
313 302
  *
@@ -324,14 +313,14 @@ void SdBaseFile::ls(uint8_t flags) {
324 313
  * \param[in] indent Amount of space before file name. Used for recursive
325 314
  * list to indicate subdirectory level.
326 315
  */
327
-void SdBaseFile::ls(Print* pr, uint8_t flags, uint8_t indent) {
316
+void SdBaseFile::ls(uint8_t flags, uint8_t indent) {
328 317
   rewind();
329 318
   int8_t status;
330
-  while ((status = lsPrintNext(pr, flags, indent))) {
319
+  while ((status = lsPrintNext( flags, indent))) {
331 320
     if (status > 1 && (flags & LS_R)) {
332 321
       uint16_t index = curPosition()/32 - 1;
333 322
       SdBaseFile s;
334
-      if (s.open(this, index, O_READ)) s.ls(pr, flags, indent + 2);
323
+      if (s.open(this, index, O_READ)) s.ls( flags, indent + 2);
335 324
       seekSet(32 * (index + 1));
336 325
     }
337 326
   }
@@ -339,7 +328,7 @@ void SdBaseFile::ls(Print* pr, uint8_t flags, uint8_t indent) {
339 328
 //------------------------------------------------------------------------------
340 329
 // saves 32 bytes on stack for ls recursion
341 330
 // return 0 - EOF, 1 - normal file, or 2 - directory
342
-int8_t SdBaseFile::lsPrintNext(Print *pr, uint8_t flags, uint8_t indent) {
331
+int8_t SdBaseFile::lsPrintNext( uint8_t flags, uint8_t indent) {
343 332
   dir_t dir;
344 333
   uint8_t w = 0;
345 334
 
@@ -352,38 +341,38 @@ int8_t SdBaseFile::lsPrintNext(Print *pr, uint8_t flags, uint8_t indent) {
352 341
       && DIR_IS_FILE_OR_SUBDIR(&dir)) break;
353 342
   }
354 343
   // indent for dir level
355
-  for (uint8_t i = 0; i < indent; i++) pr->write(' ');
344
+  for (uint8_t i = 0; i < indent; i++) MSerial.write(' ');
356 345
 
357 346
   // print name
358 347
   for (uint8_t i = 0; i < 11; i++) {
359 348
     if (dir.name[i] == ' ')continue;
360 349
     if (i == 8) {
361
-      pr->write('.');
350
+      MSerial.write('.');
362 351
       w++;
363 352
     }
364
-    pr->write(dir.name[i]);
353
+    MSerial.write(dir.name[i]);
365 354
     w++;
366 355
   }
367 356
   if (DIR_IS_SUBDIR(&dir)) {
368
-    pr->write('/');
357
+    MSerial.write('/');
369 358
     w++;
370 359
   }
371 360
   if (flags & (LS_DATE | LS_SIZE)) {
372
-    while (w++ < 14) pr->write(' ');
361
+    while (w++ < 14) MSerial.write(' ');
373 362
   }
374 363
   // print modify date/time if requested
375 364
   if (flags & LS_DATE) {
376
-    pr->write(' ');
377
-    printFatDate(pr, dir.lastWriteDate);
378
-    pr->write(' ');
379
-    printFatTime(pr, dir.lastWriteTime);
365
+    MSerial.write(' ');
366
+    printFatDate( dir.lastWriteDate);
367
+    MSerial.write(' ');
368
+    printFatTime( dir.lastWriteTime);
380 369
   }
381 370
   // print size if requested
382 371
   if (!DIR_IS_SUBDIR(&dir) && (flags & LS_SIZE)) {
383
-    pr->write(' ');
384
-    pr->print(dir.fileSize);
372
+    MSerial.write(' ');
373
+    MSerial.print(dir.fileSize);
385 374
   }
386
-  pr->println();
375
+  MSerial.println();
387 376
   return DIR_IS_FILE(&dir) ? 1 : 2;
388 377
 }
389 378
 //------------------------------------------------------------------------------
@@ -940,17 +929,7 @@ int SdBaseFile::peek() {
940 929
   if (c >= 0) setpos(&pos);
941 930
   return c;
942 931
 }
943
-//------------------------------------------------------------------------------
944
-/** %Print the name field of a directory entry in 8.3 format to Serial.
945
- *
946
- * \param[in] dir The directory structure containing the name.
947
- * \param[in] width Blank fill name if length is less than \a width.
948
- * \param[in] printSlash Print '/' after directory names if true.
949
- */
950
-void SdBaseFile::printDirName(const dir_t& dir,
951
-  uint8_t width, bool printSlash) {
952
-  printDirName(&MSerial, dir, width, printSlash);
953
-}
932
+
954 933
 //------------------------------------------------------------------------------
955 934
 /** %Print the name field of a directory entry in 8.3 format.
956 935
  * \param[in] pr Print stream for output.
@@ -958,32 +937,32 @@ void SdBaseFile::printDirName(const dir_t& dir,
958 937
  * \param[in] width Blank fill name if length is less than \a width.
959 938
  * \param[in] printSlash Print '/' after directory names if true.
960 939
  */
961
-void SdBaseFile::printDirName(Print* pr, const dir_t& dir,
940
+void SdBaseFile::printDirName(const dir_t& dir,
962 941
   uint8_t width, bool printSlash) {
963 942
   uint8_t w = 0;
964 943
   for (uint8_t i = 0; i < 11; i++) {
965 944
     if (dir.name[i] == ' ')continue;
966 945
     if (i == 8) {
967
-      pr->write('.');
946
+      MSerial.write('.');
968 947
       w++;
969 948
     }
970
-    pr->write(dir.name[i]);
949
+    MSerial.write(dir.name[i]);
971 950
     w++;
972 951
   }
973 952
   if (DIR_IS_SUBDIR(&dir) && printSlash) {
974
-    pr->write('/');
953
+    MSerial.write('/');
975 954
     w++;
976 955
   }
977 956
   while (w < width) {
978
-    pr->write(' ');
957
+    MSerial.write(' ');
979 958
     w++;
980 959
   }
981 960
 }
982 961
 //------------------------------------------------------------------------------
983 962
 // print uint8_t with width 2
984
-static void print2u(Print* pr, uint8_t v) {
985
-  if (v < 10) pr->write('0');
986
-  pr->print(v, DEC);
963
+static void print2u( uint8_t v) {
964
+  if (v < 10) MSerial.write('0');
965
+  MSerial.print(v, DEC);
987 966
 }
988 967
 //------------------------------------------------------------------------------
989 968
 /** %Print a directory date field to Serial.
@@ -992,9 +971,7 @@ static void print2u(Print* pr, uint8_t v) {
992 971
  *
993 972
  * \param[in] fatDate The date field from a directory entry.
994 973
  */
995
-void SdBaseFile::printFatDate(uint16_t fatDate) {
996
-  printFatDate(&MSerial, fatDate);
997
-}
974
+
998 975
 //------------------------------------------------------------------------------
999 976
 /** %Print a directory date field.
1000 977
  *
@@ -1003,23 +980,14 @@ void SdBaseFile::printFatDate(uint16_t fatDate) {
1003 980
  * \param[in] pr Print stream for output.
1004 981
  * \param[in] fatDate The date field from a directory entry.
1005 982
  */
1006
-void SdBaseFile::printFatDate(Print* pr, uint16_t fatDate) {
1007
-  pr->print(FAT_YEAR(fatDate));
1008
-  pr->write('-');
1009
-  print2u(pr, FAT_MONTH(fatDate));
1010
-  pr->write('-');
1011
-  print2u(pr, FAT_DAY(fatDate));
1012
-}
1013
-//------------------------------------------------------------------------------
1014
-/** %Print a directory time field to Serial.
1015
- *
1016
- * Format is hh:mm:ss.
1017
- *
1018
- * \param[in] fatTime The time field from a directory entry.
1019
- */
1020
-void SdBaseFile::printFatTime(uint16_t fatTime) {
1021
-  printFatTime(&MSerial, fatTime);
983
+void SdBaseFile::printFatDate(uint16_t fatDate) {
984
+  MSerial.print(FAT_YEAR(fatDate));
985
+  MSerial.write('-');
986
+  print2u( FAT_MONTH(fatDate));
987
+  MSerial.write('-');
988
+  print2u( FAT_DAY(fatDate));
1022 989
 }
990
+
1023 991
 //------------------------------------------------------------------------------
1024 992
 /** %Print a directory time field.
1025 993
  *
@@ -1028,12 +996,12 @@ void SdBaseFile::printFatTime(uint16_t fatTime) {
1028 996
  * \param[in] pr Print stream for output.
1029 997
  * \param[in] fatTime The time field from a directory entry.
1030 998
  */
1031
-void SdBaseFile::printFatTime(Print* pr, uint16_t fatTime) {
1032
-  print2u(pr, FAT_HOUR(fatTime));
1033
-  pr->write(':');
1034
-  print2u(pr, FAT_MINUTE(fatTime));
1035
-  pr->write(':');
1036
-  print2u(pr, FAT_SECOND(fatTime));
999
+void SdBaseFile::printFatTime( uint16_t fatTime) {
1000
+  print2u( FAT_HOUR(fatTime));
1001
+  MSerial.write(':');
1002
+  print2u( FAT_MINUTE(fatTime));
1003
+  MSerial.write(':');
1004
+  print2u( FAT_SECOND(fatTime));
1037 1005
 }
1038 1006
 //------------------------------------------------------------------------------
1039 1007
 /** Print a file's name to Serial

+ 4
- 9
Marlin/SdBaseFile.h Dosyayı Görüntüle

@@ -270,8 +270,7 @@ class SdBaseFile {
270 270
   bool isRoot() const {
271 271
     return type_ == FAT_FILE_TYPE_ROOT_FIXED || type_ == FAT_FILE_TYPE_ROOT32;
272 272
   }
273
-  void ls(Print* pr, uint8_t flags = 0, uint8_t indent = 0);
274
-  void ls(uint8_t flags = 0);
273
+  void ls( uint8_t flags = 0, uint8_t indent = 0);
275 274
   bool mkdir(SdBaseFile* dir, const char* path, bool pFlag = true);
276 275
   // alias for backward compactability
277 276
   bool makeDir(SdBaseFile* dir, const char* path) {
@@ -284,9 +283,7 @@ class SdBaseFile {
284 283
   bool openRoot(SdVolume* vol);
285 284
   int peek();
286 285
   static void printFatDate(uint16_t fatDate);
287
-  static void printFatDate(Print* pr, uint16_t fatDate);
288
-  static void printFatTime(uint16_t fatTime);
289
-  static void printFatTime(Print* pr, uint16_t fatTime);
286
+  static void printFatTime( uint16_t fatTime);
290 287
   bool printName();
291 288
   int16_t read();
292 289
   int16_t read(void* buf, uint16_t nbyte);
@@ -359,7 +356,7 @@ class SdBaseFile {
359 356
   bool addCluster();
360 357
   bool addDirCluster();
361 358
   dir_t* cacheDirEntry(uint8_t action);
362
-  int8_t lsPrintNext(Print *pr, uint8_t flags, uint8_t indent);
359
+  int8_t lsPrintNext( uint8_t flags, uint8_t indent);
363 360
   static bool make83Name(const char* str, uint8_t* name, const char** ptr);
364 361
   bool mkdir(SdBaseFile* parent, const uint8_t dname[11]);
365 362
   bool open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t oflag);
@@ -367,9 +364,7 @@ class SdBaseFile {
367 364
   dir_t* readDirCache();
368 365
 //------------------------------------------------------------------------------
369 366
 // to be deleted
370
-  static void printDirName(const dir_t& dir,
371
-    uint8_t width, bool printSlash);
372
-  static void printDirName(Print* pr, const dir_t& dir,
367
+  static void printDirName( const dir_t& dir,
373 368
     uint8_t width, bool printSlash);
374 369
 //------------------------------------------------------------------------------
375 370
 // Deprecated functions  - suppress cpplint warnings with NOLINT comment

+ 7
- 7
Marlin/SdFatUtil.cpp Dosyayı Görüntüle

@@ -43,8 +43,8 @@ int SdFatUtil::FreeRam() {
43 43
  * \param[in] pr Print object for output.
44 44
  * \param[in] str Pointer to string stored in flash memory.
45 45
  */
46
-void SdFatUtil::print_P(Print* pr, PGM_P str) {
47
-  for (uint8_t c; (c = pgm_read_byte(str)); str++) pr->write(c);
46
+void SdFatUtil::print_P( PGM_P str) {
47
+  for (uint8_t c; (c = pgm_read_byte(str)); str++) MSerial.write(c);
48 48
 }
49 49
 //------------------------------------------------------------------------------
50 50
 /** %Print a string in flash memory followed by a CR/LF.
@@ -52,9 +52,9 @@ void SdFatUtil::print_P(Print* pr, PGM_P str) {
52 52
  * \param[in] pr Print object for output.
53 53
  * \param[in] str Pointer to string stored in flash memory.
54 54
  */
55
-void SdFatUtil::println_P(Print* pr, PGM_P str) {
56
-  print_P(pr, str);
57
-  pr->println();
55
+void SdFatUtil::println_P( PGM_P str) {
56
+  print_P( str);
57
+  MSerial.println();
58 58
 }
59 59
 //------------------------------------------------------------------------------
60 60
 /** %Print a string in flash memory to Serial.
@@ -62,7 +62,7 @@ void SdFatUtil::println_P(Print* pr, PGM_P str) {
62 62
  * \param[in] str Pointer to string stored in flash memory.
63 63
  */
64 64
 void SdFatUtil::SerialPrint_P(PGM_P str) {
65
-  print_P(&MSerial, str);
65
+  print_P(str);
66 66
 }
67 67
 //------------------------------------------------------------------------------
68 68
 /** %Print a string in flash memory to Serial followed by a CR/LF.
@@ -70,5 +70,5 @@ void SdFatUtil::SerialPrint_P(PGM_P str) {
70 70
  * \param[in] str Pointer to string stored in flash memory.
71 71
  */
72 72
 void SdFatUtil::SerialPrintln_P(PGM_P str) {
73
-  println_P(&MSerial, str);
73
+  println_P( str);
74 74
 }

+ 47
- 47
Marlin/SdFatUtil.h Dosyayı Görüntüle

@@ -1,48 +1,48 @@
1
-/* Arduino SdFat Library
2
- * Copyright (C) 2008 by William Greiman
3
- *
4
- * This file is part of the Arduino SdFat Library
5
- *
6
- * This Library is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This Library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
-
16
- * You should have received a copy of the GNU General Public License
17
- * along with the Arduino SdFat Library.  If not, see
18
- * <http://www.gnu.org/licenses/>.
19
- */
20
-#ifndef SdFatUtil_h
21
-#define SdFatUtil_h
22
-/**
23
- * \file
24
- * \brief Useful utility functions.
25
- */
26
-#include <avr/pgmspace.h>
27
-#if ARDUINO < 100
28
-#define  HardwareSerial_h // trick to disable the standard HWserial
29
-#include <WProgram.h>
30
-#include "MarlinSerial.h"
31
-#else  // ARDUINO
32
-#include <Arduino.h>
33
-#endif  // ARDUINO
34
-/** Store and print a string in flash memory.*/
35
-#define PgmPrint(x) SerialPrint_P(PSTR(x))
36
-/** Store and print a string in flash memory followed by a CR/LF.*/
37
-#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
38
-
39
-namespace SdFatUtil {
40
-  int FreeRam();
41
-  void print_P(Print* pr, PGM_P str);
42
-  void println_P(Print* pr, PGM_P str);
43
-  void SerialPrint_P(PGM_P str);
44
-  void SerialPrintln_P(PGM_P str);
45
-}
46
-
47
-using namespace SdFatUtil;  // NOLINT
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2008 by William Greiman
3
+ *
4
+ * This file is part of the Arduino SdFat Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#ifndef SdFatUtil_h
21
+#define SdFatUtil_h
22
+/**
23
+ * \file
24
+ * \brief Useful utility functions.
25
+ */
26
+#include <avr/pgmspace.h>
27
+#if ARDUINO < 100
28
+#define  HardwareSerial_h // trick to disable the standard HWserial
29
+#include <WProgram.h>
30
+#include "MarlinSerial.h"
31
+#else  // ARDUINO
32
+#include <Arduino.h>
33
+#endif  // ARDUINO
34
+/** Store and print a string in flash memory.*/
35
+#define PgmPrint(x) SerialPrint_P(PSTR(x))
36
+/** Store and print a string in flash memory followed by a CR/LF.*/
37
+#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
38
+
39
+namespace SdFatUtil {
40
+  int FreeRam();
41
+  void print_P( PGM_P str);
42
+  void println_P( PGM_P str);
43
+  void SerialPrint_P(PGM_P str);
44
+  void SerialPrintln_P(PGM_P str);
45
+}
46
+
47
+using namespace SdFatUtil;  // NOLINT
48 48
 #endif  // #define SdFatUtil_h

Loading…
İptal
Kaydet