annotate Debug/print/print.c @ 340:e8841d3c6db5

mk20dx256vlh7 working! - Interrupt vector table position fix (affected everything in the firmware) - Added fault debug messages - Fixed usbMuxUart
author Jacob Alexander <haata@kiibohd.com>
date Sat, 13 Jun 2015 20:42:12 -0700
parents 58cfcb7bac88
children 45feb80a2ad1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
814b5d3d7da6 Finished USB for Teensy 3.1 (Now 3.1 compatible!)
Jacob Alexander <haata@kiibohd.com>
parents: 115
diff changeset
1 /* Copyright (C) 2011-2014 by Jacob Alexander
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents: 84
diff changeset
2 *
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
4 * of this software and associated documentation files (the "Software"), to deal
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
5 * in the Software without restriction, including without limitation the rights
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
7 * copies of the Software, and to permit persons to whom the Software is
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
8 * furnished to do so, subject to the following conditions:
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents: 84
diff changeset
9 *
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
10 * The above copyright notice and this permission notice shall be included in
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
11 * all copies or substantial portions of the Software.
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents: 84
diff changeset
12 *
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
19 * THE SOFTWARE.
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
20 */
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
21
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
22 // ----- Includes -----
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
23
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
24 // Compiler Includes
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
25 #include <stdarg.h>
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
26
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
27 // Project Includes
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
28 #include "print.h"
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
29
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
30
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
31
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
32 // ----- Functions -----
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
33
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
34 // Multiple string Output
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 120
diff changeset
35 void printstrs( char* first, ... )
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
36 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
37 // Initialize the variadic function parameter list
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
38 va_list ap;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
39
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
40 // Get the first parameter
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
41 va_start( ap, first );
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
42 char *cur = first;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
43
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
44 // Loop through the variadic list until "\0\0\0" is found
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
45 while ( !( cur[0] == '\0' && cur[1] == '\0' && cur[2] == '\0' ) )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
46 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
47 // Print out the given string
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
48 Output_putstr( cur );
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
49
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
50 // Get the next argument ready
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
51 cur = va_arg( ap, char* );
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
52 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
53
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
54 va_end( ap ); // Not required, but good practice
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
55 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
56
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
57 // Print a constant string
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 120
diff changeset
58 void _print( const char* s )
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
59 {
69
87658fa6091b Updating AVR abstraction to be compatible with ARM, nearly ready for ARM files
Jacob Alexander <triplehaata@gmail.com>
parents: 24
diff changeset
60 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 120
diff changeset
61 // Pull string out of flash
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
62 char c;
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 120
diff changeset
63 while ( ( c = pgm_read_byte( s++ ) ) != '\0' )
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
64 {
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
65 Output_putchar( c );
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
66 }
340
e8841d3c6db5 mk20dx256vlh7 working!
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
67 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
68 Output_putstr( (char*)s );
69
87658fa6091b Updating AVR abstraction to be compatible with ARM, nearly ready for ARM files
Jacob Alexander <triplehaata@gmail.com>
parents: 24
diff changeset
69 #endif
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
70 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
71
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
72
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
73
84
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
74 // Number Printing Functions
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
75 void printInt8( uint8_t in )
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
76 {
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
77 // Max number of characters is 3 + 1 for null
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
78 char tmpStr[4];
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
79
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
80 // Convert number
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
81 int8ToStr( in, tmpStr );
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
82
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
83 // Print number
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
84 dPrintStr( tmpStr );
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
85 }
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
86
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
87 void printInt16( uint16_t in )
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
88 {
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
89 // Max number of characters is 5 + 1 for null
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
90 char tmpStr[6];
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
91
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
92 // Convert number
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
93 int16ToStr( in, tmpStr );
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
94
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
95 // Print number
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
96 dPrintStr( tmpStr );
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
97 }
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
98
115
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
99 void printInt32( uint32_t in )
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
100 {
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
101 // Max number of characters is 10 + 1 for null
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
102 char tmpStr[11];
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
103
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
104 // Convert number
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
105 int32ToStr( in, tmpStr );
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
106
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
107 // Print number
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
108 dPrintStr( tmpStr );
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
109 }
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
110
84
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
111 void printHex_op( uint16_t in, uint8_t op )
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
112 {
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
113 // With an op of 1, the max number of characters is 6 + 1 for null
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
114 // e.g. "0xFFFF\0"
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
115 // op 2 and 4 require fewer characters (2+1 and 4+1 respectively)
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
116 char tmpStr[7];
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
117
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
118 // Convert number
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
119 hexToStr_op( in, tmpStr, op );
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
120
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
121 // Print number
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
122 dPrintStr( tmpStr );
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
123 }
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
124
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
125 void printHex32_op( uint32_t in, uint8_t op )
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
126 {
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
127 // With an op of 1, the max number of characters is 6 + 1 for null
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
128 // e.g. "0xFFFF\0"
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
129 // op 2 and 4 require fewer characters (2+1 and 4+1 respectively)
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
130 char tmpStr[7];
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
131
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
132 // Convert number
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
133 hex32ToStr_op( in, tmpStr, op );
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
134
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
135 // Print number
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
136 dPrintStr( tmpStr );
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
137 }
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
138
84
fcef1286ab60 Adding additional convenience functions to print.
Jacob Alexander <triplehaata@gmail.com>
parents: 69
diff changeset
139
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
140
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
141 // String Functions
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
142 void int8ToStr( uint8_t in, char* out )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
143 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
144 // Position and sign containers
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
145 uint8_t pos;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
146 pos = 0;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
147
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
148 // Evaluate through digits as decimal
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
149 do
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
150 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
151 out[pos++] = in % 10 + '0';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
152 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
153 while ( (in /= 10) > 0 );
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
154
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
155 // Append null
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
156 out[pos] = '\0';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
157
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
158 // Reverse the string to the correct order
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
159 revsStr(out);
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
160 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
161
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
162
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
163 void int16ToStr( uint16_t in, char* out )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
164 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
165 // Position and sign containers
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
166 uint16_t pos;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
167 pos = 0;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
168
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
169 // Evaluate through digits as decimal
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
170 do
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
171 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
172 out[pos++] = in % 10 + '0';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
173 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
174 while ( (in /= 10) > 0 );
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
175
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
176 // Append null
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
177 out[pos] = '\0';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
178
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
179 // Reverse the string to the correct order
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
180 revsStr(out);
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
181 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
182
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
183
115
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
184 void int32ToStr( uint32_t in, char* out )
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
185 {
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
186 // Position and sign containers
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
187 uint32_t pos;
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
188 pos = 0;
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
189
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
190 // Evaluate through digits as decimal
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
191 do
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
192 {
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
193 out[pos++] = in % 10 + '0';
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
194 }
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
195 while ( (in /= 10) > 0 );
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
196
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
197 // Append null
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
198 out[pos] = '\0';
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
199
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
200 // Reverse the string to the correct order
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
201 revsStr(out);
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
202 }
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
203
d3a47c0dfb50 Initial work for iGaging distance gauge.
Jacob Alexander <haata@kiibohd.com>
parents: 114
diff changeset
204
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
205 void hexToStr_op( uint16_t in, char* out, uint8_t op )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
206 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
207 // Position container
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
208 uint16_t pos = 0;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
209
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
210 // Evaluate through digits as hex
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
211 do
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
212 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
213 uint16_t cur = in % 16;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
214 out[pos++] = cur + (( cur < 10 ) ? '0' : 'A' - 10);
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
215 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
216 while ( (in /= 16) > 0 );
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
217
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
218 // Output formatting options
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
219 switch ( op )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
220 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
221 case 1: // Add 0x
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
222 out[pos++] = 'x';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
223 out[pos++] = '0';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
224 break;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
225 case 2: // 8-bit padding
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
226 case 4: // 16-bit padding
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
227 while ( pos < op )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
228 out[pos++] = '0';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
229 break;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
230 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
231
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
232 // Append null
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
233 out[pos] = '\0';
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
234
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
235 // Reverse the string to the correct order
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
236 revsStr(out);
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
237 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
238
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
239
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
240 void hex32ToStr_op( uint32_t in, char* out, uint8_t op )
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
241 {
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
242 // Position container
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
243 uint32_t pos = 0;
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
244
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
245 // Evaluate through digits as hex
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
246 do
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
247 {
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
248 uint32_t cur = in % 16;
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
249 out[pos++] = cur + (( cur < 10 ) ? '0' : 'A' - 10);
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
250 }
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
251 while ( (in /= 16) > 0 );
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
252
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
253 // Output formatting options
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
254 switch ( op )
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
255 {
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
256 case 1: // Add 0x
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
257 out[pos++] = 'x';
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
258 out[pos++] = '0';
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
259 break;
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
260 case 2: // 8-bit padding
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
261 case 4: // 16-bit padding
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
262 while ( pos < op )
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
263 out[pos++] = '0';
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
264 break;
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
265 }
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
266
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
267 // Append null
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
268 out[pos] = '\0';
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
269
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
270 // Reverse the string to the correct order
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
271 revsStr(out);
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
272 }
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
273
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
274
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
275 void revsStr( char* in )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
276 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
277 // Iterators
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
278 int i, j;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
279
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
280 // Temp storage
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
281 char c;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
282
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
283 // Loop through the string, and reverse the order of the characters
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
284 for ( i = 0, j = lenStr( in ) - 1; i < j; i++, j-- )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
285 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
286 c = in[i];
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
287 in[i] = in[j];
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
288 in[j] = c;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
289 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
290 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
291
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
292
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
293 uint16_t lenStr( char* in )
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
294 {
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
295 // Iterator
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
296 char *pos;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
297
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
298 // Loop until null is found
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
299 for ( pos = in; *pos; pos++ );
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
300
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
301 // Return the difference between the pointers of in and pos (which is the string length)
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
302 return (pos - in);
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
303 }
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
304
106
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
305
114
c57ec00a0abc Adding basic Tab completion.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
306 int16_t eqStr( char* str1, char* str2 )
106
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
307 {
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
308 // Scan each string for NULLs and whether they are the same
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
309 while( *str1 != '\0' && *str1++ == *str2++ );
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
310
114
c57ec00a0abc Adding basic Tab completion.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
311 // If the strings are still identical (i.e. both NULL), then return -1, otherwise current *str1
c57ec00a0abc Adding basic Tab completion.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
312 // If *str1 is 0, then str1 ended (and str1 is "like" str2), otherwise strings are different
c57ec00a0abc Adding basic Tab completion.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
313 return *--str1 == *--str2 ? -1 : *++str1;
106
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
314 }
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
315
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
316 int numToInt( char* in )
120
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
317 {
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
318 // Pointers to the LSD (Least Significant Digit) and MSD
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
319 char* lsd = in;
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
320 char* msd = in;
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
321
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
322 int total = 0;
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
323 int sign = 1; // Default to positive
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
324 uint8_t base = 10; // Use base 10 by default TODO Add support for bases other than 10 and 16
120
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
325
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
326 // Scan the string once to determine the length
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
327 while ( *lsd != '\0' )
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
328 {
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
329 // Check for positive/negative
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
330 switch ( *lsd++ )
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
331 {
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
332 // Fall through is intentional, only do something on negative, ignore the rest
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
333 // Update the MSD to remove leading spaces and signs
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
334 case '-': sign = -1;
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
335 case '+':
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
336 case ' ':
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
337 msd = lsd;
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
338 break;
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
339 case 'x': // Hex Mode
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
340 base = 0x10;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
341 msd = lsd;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
342 break;
120
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
343 }
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
344 }
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
345
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
346 // Process string depending on which base
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
347 switch ( base )
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
348 {
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
349 case 10: // Decimal
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
350 // Rescan the string from the LSD to MSD to convert it to a decimal number
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
351 for ( unsigned int digit = 1; lsd > msd ; digit *= 10 )
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
352 total += ( (*--lsd) - '0' ) * digit;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
353 break;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
354
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
355 case 0x10: // Hex
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
356 // Rescan the string from the LSD to MSD to convert it to a hexadecimal number
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
357 for ( unsigned int digit = 1; lsd > msd ; digit *= 0x10 )
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
358 {
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
359 if ( *--lsd <= '9' ) total += ( *lsd - '0' ) * digit;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
360 else if ( *lsd <= 'F' ) total += ( *lsd - 'A' + 10 ) * digit;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
361 else if ( *lsd <= 'f' ) total += ( *lsd - 'a' + 10 ) * digit;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
362 }
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
363 break;
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
364 }
120
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
365
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
366 // Propagate sign and return
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
367 return total * sign;
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
368 }
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 119
diff changeset
369