-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathprint.h
138 lines (106 loc) · 5.17 KB
/
print.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* Copyright (C) 2011-2020 by Jacob Alexander
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
// ----- Includes -----
#include <Lib/mcu_compat.h>
// Compiler Includes
#if defined(_avr_at_)
#include <avr/pgmspace.h>
#endif
// Project Includes
#include <Lib/time.h>
#include <output_com.h>
// ----- Defines -----
#define NL "\r\n"
// ----- Functions and Corresponding Function Aliases -----
/* XXX
* Note that all the variadic functions below, take comma separated string lists, they are purposely not printf style (simplicity)
*/
// Function Aliases
#define dPrint(c) Output_putstr(c)
#define dPrintStr(c) Output_putstr(c)
#define dPrintStrs(...) printstrs(__VA_ARGS__, "\0\0\0") // Convenience Variadic Macro
#define dPrintStrNL(c) dPrintStrs (c, NL) // Appends New Line Macro
#define dPrintStrsNL(...) printstrs(__VA_ARGS__, NL, "\0\0\0") // Appends New Line Macro
// Special Msg Constructs (Uses VT100 tags)
#define dPrintMsg(colour_code_str,msg,...) \
printstrs("\033[", colour_code_str, "m", msg, "\033[0m - ", __VA_ARGS__, NL, "\0\0\0")
#define printMsgNL(colour_code_str,msg,str) \
print("\033[" colour_code_str "m" msg "\033[0m - " str NL)
#define printMsg(colour_code_str,msg,str) \
print("\033[" colour_code_str "m" msg "\033[0m - " str)
// Info Messages
#define info_dPrint(...) dPrintMsg ("1;32", "INFO", __VA_ARGS__) // Info Msg
#define info_print(str) printMsg ("1;32", "INFO", str) // Info Msg
#define info_printNL(str) printMsgNL ("1;32", "INFO", str) // Info Msg
// Warning Messages
#define warn_dPrint(...) dPrintMsg ("1;33", "WARNING", __VA_ARGS__) // Warning Msg
#define warn_print(str) printMsg ("1;33", "WARNING", str) // Warning Msg
#define warn_printNL(str) printMsgNL ("1;33", "WARNING", str) // Warning Msg
// Error Messages
#define erro_dPrint(...) dPrintMsg ("1;5;31", "ERROR", __VA_ARGS__) // Error Msg
#define erro_print(str) printMsg ("1;5;31", "ERROR", str) // Error Msg
#define erro_printNL(str) printMsgNL ("1;5;31", "ERROR", str) // Error Msg
// Debug Messages
#define dbug_dPrint(...) dPrintMsg ("1;35", "DEBUG", __VA_ARGS__) // Debug Msg
#define dbug_print(str) printMsg ("1;35", "DEBUG", str) // Debug Msg
#define dbug_printNL(str) printMsgNL ("1;35", "DEBUG", str) // Debug Msg
// Static String Printing
#if defined(_avr_at_)
#define print(s) _print(PSTR(s))
#else
#define print(s) _print(s)
#define printNL(s) _print(s NL)
#endif
void _print( const char *s );
void printstrs( char* first, ... );
void printChar( char c );
// Printing numbers
#define printHex(hex) printHex_op(hex, 1)
#define printHex32(hex) printHex32_op(hex, 1)
void printInt8 ( uint8_t in );
void printInt16 ( uint16_t in );
void printInt32 ( uint32_t in );
void printSInt32 ( int32_t in );
void printHex_op ( uint16_t in, uint8_t op );
void printHex32_op( uint32_t in, uint8_t op );
void printInt8Pad ( uint8_t in );
void printInt16Pad( uint16_t in );
void printInt32Pad( uint32_t in );
// The given number is divided by a power a 10 (e.g. 10, 100, 100)
// Any value less than the mul, is after the decimal
// Any value greater than the mul, is before the decimal
// in * mul must not exceed the maximum size of in
void printDecimal32( uint32_t in, uint32_t mul );
void printTime( Time time );
// String Functions
#define hexToStr(hex, out) hexToStr_op(hex, out, 1)
void int8ToStr ( uint8_t in, char* out );
void int16ToStr ( uint16_t in, char* out );
void int32ToStr ( uint32_t in, char* out );
void sint32ToStr ( int32_t in, char* out );
void hexToStr_op ( uint16_t in, char* out, uint8_t op );
void hex32ToStr_op( uint32_t in, char* out, uint8_t op );
void revsStr ( char* in );
uint16_t lenStr ( char* in );
int16_t eqStr ( char* str1, char* str2 ); // Returns -1 if identical, last character of str1 comparison (0 if str1 is like str2)
int numToInt ( char* in ); // Returns the int representation of a string
void hex32ToStr16 ( uint32_t in, uint16_t* out, uint8_t op ); // Used for USB Descriptors