changeset 177:317c0d923c51 main

Print decimal as well as hex strings.
author Bob Cook <bob@bobcookdev.com>
date Sun, 31 Mar 2013 15:37:27 -0700
parents 12681b419e60
children 7706b4a8700d
files main/packages/common/util/printutils.cpp main/packages/common/util/printutils.h
diffstat 2 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/main/packages/common/util/printutils.cpp	Sun Mar 31 15:36:26 2013 -0700
+++ b/main/packages/common/util/printutils.cpp	Sun Mar 31 15:37:27 2013 -0700
@@ -7,7 +7,7 @@
 //    
 //  This file provides printf-helper functions and macros.
 //
-//  Copyright (c) 2011 Bob Cook
+//  Copyright (c) 2011-2013 Bob Cook
 //  
 //  Permission is hereby granted, free of charge, to any person obtaining a copy
 //  of this software and associated documentation files (the "Software"), to deal
@@ -33,13 +33,35 @@
 
 #include "project_defs.h"
 
-#if defined( PRJ_PRINTHEX_ENABLE_OUTPUT_TO_STDOUT ) \
+#if defined( PRJ_PRINTDEC_ENABLE_OUTPUT_TO_STDOUT ) \
+    || defined( PRJ_PRINTHEX_ENABLE_OUTPUT_TO_STDOUT ) \
     || defined( PRJ_PRINTBITS_ENABLE_OUTPUT_TO_STDOUT )
 #include <stdio.h>
 #endif
 
 // ----------------------------------------------------------------------------------------
 
+#if defined( PRJ_PRINTDEC_ENABLE_OUTPUT_TO_BUFFER )
+
+char* print_decimal( char* outputbuf, uint8_t byte )
+{
+    outputbuf += 2;
+
+    *outputbuf-- = ( '0' + byte % 10 );
+    byte /= 10;
+
+    *outputbuf-- = ( '0' + byte % 10 );
+    byte /= 10;
+
+    *outputbuf = ( '0' + byte % 10 );
+
+    return outputbuf + 3;
+}
+
+#endif
+
+// ----------------------------------------------------------------------------------------
+
 #if defined( PRJ_PRINTHEX_ENABLE_OUTPUT_TO_STDOUT )
 
 void print_hex( uint8_t byte )
--- a/main/packages/common/util/printutils.h	Sun Mar 31 15:36:26 2013 -0700
+++ b/main/packages/common/util/printutils.h	Sun Mar 31 15:37:27 2013 -0700
@@ -39,6 +39,8 @@
 //
 //  enable various output styles:
 //
+//      + PRJ_PRINTDEC_ENABLE_OUTPUT_TO_BUFFER
+//
 //      + PRJ_PRINTHEX_ENABLE_OUTPUT_TO_STDOUT
 //      + PRJ_PRINTHEX_ENABLE_OUTPUT_TO_BUFFER
 //
@@ -48,6 +50,20 @@
 // ----------------------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------------------
+//  print_decimal
+//
+//      Print the decimal representation of the given value to the given buffer.
+//
+//      Bytes require 3 bytes in the output buffer, including any leading zeros. Words
+//      require 5 bytes, and long words require 10 bytes. There is no null terminator
+//      byte added.
+//
+//      The return value is a pointer within the buffer after the last byte added.
+//
+
+char* print_decimal( char* outputbuf, uint8_t byte );
+
+// ----------------------------------------------------------------------------------------
 //  print_hex
 //
 //      Print the hexidecimal representation of the given value to stdout.