Browse Source

Added methods to print decimals in various sizes.

Thomas Buck 8 years ago
parent
commit
64cc230916
2 changed files with 76 additions and 3 deletions
  1. 4
    0
      include/serial.h
  2. 72
    3
      src/serial.c

+ 4
- 0
include/serial.h View File

@@ -122,6 +122,10 @@ uint8_t serialTxBufferFull(uint8_t uart);
122 122
 uint8_t serialTxBufferEmpty(uint8_t uart);
123 123
 
124 124
 void serialWriteHex(uint8_t uart, uint8_t value);
125
+void serialWriteUnsigned8(uint8_t uart, uint8_t value);
126
+void serialWriteUnsigned16(uint8_t uart, uint16_t value);
127
+void serialWriteUnsigned32(uint8_t uart, uint32_t value);
128
+void serialWriteUnsigned64(uint8_t uart, uint64_t value);
125 129
 
126 130
 #endif // _serial_h
127 131
 /** @} */

+ 72
- 3
src/serial.c View File

@@ -51,15 +51,15 @@
51 51
 // #define SERIALINJECTCR
52 52
 
53 53
 #ifndef RX_BUFFER_SIZE
54
-#define RX_BUFFER_SIZE 32 /**< RX Buffer Size in Bytes (Power of 2) */
54
+#define RX_BUFFER_SIZE 16 /**< RX Buffer Size in Bytes (Power of 2) */
55 55
 #endif
56 56
 
57 57
 #ifndef TX_BUFFER_SIZE
58
-#define TX_BUFFER_SIZE 32 /**< TX Buffer Size in Bytes (Power of 2) */
58
+#define TX_BUFFER_SIZE 128 /**< TX Buffer Size in Bytes (Power of 2) */
59 59
 #endif
60 60
 
61 61
 /** Defining this enables incoming XON XOFF (sends XOFF if rx buff is full) */
62
-#define FLOWCONTROL
62
+//#define FLOWCONTROL
63 63
 
64 64
 #define FLOWMARK 5 /**< Space remaining to trigger xoff/xon */
65 65
 #define XON 0x11 /**< XON Value */
@@ -333,6 +333,75 @@ void serialWriteHex(uint8_t uart, uint8_t value) {
333 333
     serialWriteString(uart, buff);
334 334
 }
335 335
 
336
+void serialWriteUnsigned8(uint8_t uart, uint8_t value) {
337
+    char buff[4] = { '0', '0', '0', '\0' };
338
+
339
+    uint8_t pos = sizeof(buff) - 2;
340
+    while (value > 0) {
341
+        buff[pos--] = '0' + (value % 10);
342
+        value /= 10;
343
+    }
344
+
345
+    uint8_t start = 0;
346
+    while ((start < (sizeof(buff) - 2)) && (buff[start] == '0')) {
347
+        start++;
348
+    }
349
+
350
+    serialWriteString(uart, buff + start);
351
+}
352
+
353
+void serialWriteUnsigned16(uint8_t uart, uint16_t value) {
354
+    char buff[6] = { '0', '0', '0', '0', '0', '\0' };
355
+
356
+    uint8_t pos = sizeof(buff) - 2;
357
+    while (value > 0) {
358
+        buff[pos--] = '0' + (value % 10);
359
+        value /= 10;
360
+    }
361
+
362
+    uint8_t start = 0;
363
+    while ((start < (sizeof(buff) - 2)) && (buff[start] == '0')) {
364
+        start++;
365
+    }
366
+
367
+    serialWriteString(uart, buff + start);
368
+}
369
+
370
+void serialWriteUnsigned32(uint8_t uart, uint32_t value) {
371
+    char buff[11] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '\0' };
372
+
373
+    uint8_t pos = sizeof(buff) - 2;
374
+    while (value > 0) {
375
+        buff[pos--] = '0' + (value % 10);
376
+        value /= 10;
377
+    }
378
+
379
+    uint8_t start = 0;
380
+    while ((start < (sizeof(buff) - 2)) && (buff[start] == '0')) {
381
+        start++;
382
+    }
383
+
384
+    serialWriteString(uart, buff + start);
385
+}
386
+
387
+void serialWriteUnsigned64(uint8_t uart, uint64_t value) {
388
+    char buff[21] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
389
+                      '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '\0' };
390
+
391
+    uint8_t pos = sizeof(buff) - 2;
392
+    while (value > 0) {
393
+        buff[pos--] = '0' + (value % 10);
394
+        value /= 10;
395
+    }
396
+
397
+    uint8_t start = 0;
398
+    while ((start < (sizeof(buff) - 2)) && (buff[start] == '0')) {
399
+        start++;
400
+    }
401
+
402
+    serialWriteString(uart, buff + start);
403
+}
404
+
336 405
 uint8_t serialTxBufferFull(uint8_t uart) {
337 406
     if (uart >= UART_COUNT)
338 407
         return 0;

Loading…
Cancel
Save