Mercurial > louis > kiibohd-controller
annotate Debug/print/print.c @ 449:45feb80a2ad1
Major USB update, fixes most (if not all) known issues
USB - General
- Refactored descriptors
- Enabled/Disable USB endpoints
- Added debug flags for special features
- Code cleanup
- Interface count calculation based off of enabled endpoints
- Delayed wTotalLength calculation to simplify descriptor offsets
- Re-ordered endpoints and interfaces
- Added more debug output
- Added usbInitTime to show how long keyboard initialization took
(Useful when debugging bad init sequences)
- Added function for usb_resume() which takes care of the resume sequence
* Resume is now only called if packets are starting to timeout
USB - Special Options
- Added enableDeviceRestartOnUSBTimeout
* A last resort hammer for bad USB Chipsets/OSs, don't use if you can help it
* Disabled
- Added enableUSBResume
* Enables host resume wake-up signalling, required to wake a computer from sleep
* Enabled
- Added enableUSBLowPowerNegotiation
* Enables power negotiation hack
* Required to use firmware with an IPad and other hard-limit low-power USB hosts
* Hasn't been tested with the recent changes
* Disabled
- Added enableUSBSuspend
* Enables power down events on host USB bus suspend
* Enabled
USB - Keyboard
- Attempted to cleanup HID SET_REPORT
* Works much better
* Still has an issue under Linux which generates *a lot* of NAKs (initializes quickly regardless)
+ Not present on other keyboards
+ SETUP -> OUT -> IN : This sequence is the problem
+ Specifically during the OUT phase
- Enabled
USB - CDC Virtual Serial Port
- Code cleanup
- Added convenience struct USBCDCLineCoding for easier debugging
- Attempted to cleanup CDC_SET_LING_CODING
* Works much better
* Still has an issue under Linux which generates *a lot* of NAKs (initializes quickly regardless)
+ SETUP -> OUT -> IN : This sequence is the problem
+ Specifically during the OUT phase
+ Likely the same issues as HID SET_REPORT
- Enabled
USB - Mouse
- Enabled
USB - Joystick
- Disabled
USB - RawIO
- Initial code, API not used yet
- Disabled
DFU
- Updated load script, now faster
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Tue, 31 May 2016 00:19:45 -0700 |
parents | e8841d3c6db5 |
children |
rev | line source |
---|---|
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
340
diff
changeset
|
1 /* Copyright (C) 2011-2016 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 | 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 | 125 void printHex32_op( uint32_t in, uint8_t op ) |
126 { | |
127 // With an op of 1, the max number of characters is 6 + 1 for null | |
128 // e.g. "0xFFFF\0" | |
129 // op 2 and 4 require fewer characters (2+1 and 4+1 respectively) | |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
340
diff
changeset
|
130 char tmpStr[11]; |
175 | 131 |
132 // Convert number | |
133 hex32ToStr_op( in, tmpStr, op ); | |
134 | |
135 // Print number | |
136 dPrintStr( tmpStr ); | |
137 } | |
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 | 240 void hex32ToStr_op( uint32_t in, char* out, uint8_t op ) |
241 { | |
242 // Position container | |
243 uint32_t pos = 0; | |
244 | |
245 // Evaluate through digits as hex | |
246 do | |
247 { | |
248 uint32_t cur = in % 16; | |
249 out[pos++] = cur + (( cur < 10 ) ? '0' : 'A' - 10); | |
250 } | |
251 while ( (in /= 16) > 0 ); | |
252 | |
253 // Output formatting options | |
254 switch ( op ) | |
255 { | |
256 case 1: // Add 0x | |
257 out[pos++] = 'x'; | |
258 out[pos++] = '0'; | |
259 break; | |
260 case 2: // 8-bit padding | |
261 case 4: // 16-bit padding | |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
340
diff
changeset
|
262 case 8: // 32-bit padding |
175 | 263 while ( pos < op ) |
264 out[pos++] = '0'; | |
265 break; | |
266 } | |
267 | |
268 // Append null | |
269 out[pos] = '\0'; | |
270 | |
271 // Reverse the string to the correct order | |
272 revsStr(out); | |
273 } | |
274 | |
275 | |
24
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
276 void revsStr( char* in ) |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
277 { |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
278 // Iterators |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
279 int i, j; |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
280 |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
281 // Temp storage |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
282 char c; |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
283 |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
284 // 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
|
285 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
|
286 { |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
287 c = in[i]; |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
288 in[i] = in[j]; |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
289 in[j] = c; |
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 |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
294 uint16_t lenStr( char* in ) |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
295 { |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
296 // Iterator |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
297 char *pos; |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
298 |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
299 // Loop until null is found |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
300 for ( pos = in; *pos; pos++ ); |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
301 |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
302 // 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
|
303 return (pos - in); |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
304 } |
2d65da455ef3
Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents:
diff
changeset
|
305 |
106
15961894eaeb
Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
306 |
114
c57ec00a0abc
Adding basic Tab completion.
Jacob Alexander <haata@kiibohd.com>
parents:
106
diff
changeset
|
307 int16_t eqStr( char* str1, char* str2 ) |
106
15961894eaeb
Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
308 { |
15961894eaeb
Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
309 // 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
|
310 while( *str1 != '\0' && *str1++ == *str2++ ); |
15961894eaeb
Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
311 |
114
c57ec00a0abc
Adding basic Tab completion.
Jacob Alexander <haata@kiibohd.com>
parents:
106
diff
changeset
|
312 // 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
|
313 // 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
|
314 return *--str1 == *--str2 ? -1 : *++str1; |
106
15961894eaeb
Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
315 } |
15961894eaeb
Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
316 |
195
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
317 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
|
318 { |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
319 // 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
|
320 char* lsd = in; |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
321 char* msd = in; |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
322 |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
323 int total = 0; |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
324 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
|
325 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
|
326 |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
327 // 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
|
328 while ( *lsd != '\0' ) |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
329 { |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
330 // 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
|
331 switch ( *lsd++ ) |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
332 { |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
333 // 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
|
334 // 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
|
335 case '-': sign = -1; |
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 case ' ': |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
338 msd = lsd; |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
339 break; |
195
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
340 case 'x': // Hex Mode |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
341 base = 0x10; |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
342 msd = lsd; |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
343 break; |
120
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 } |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
346 |
195
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
347 // 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
|
348 switch ( base ) |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
349 { |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
350 case 10: // Decimal |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
351 // 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
|
352 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
|
353 total += ( (*--lsd) - '0' ) * digit; |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
354 break; |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
355 |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
356 case 0x10: // Hex |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
357 // 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
|
358 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
|
359 { |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
360 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
|
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 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
|
363 } |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
364 break; |
58cfcb7bac88
Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
365 } |
120
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
366 |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
367 // 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
|
368 return total * sign; |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
369 } |
b90e5316ffe7
Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents:
119
diff
changeset
|
370 |