2014-02-03 05:12:20 +00:00
|
|
|
/* Copyright (C) 2011-2014 by Jacob Alexander
|
2014-01-20 00:40:36 +00:00
|
|
|
*
|
2011-09-29 06:25:51 +00:00
|
|
|
* 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:
|
2014-01-20 00:40:36 +00:00
|
|
|
*
|
2011-09-29 06:25:51 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2014-01-20 00:40:36 +00:00
|
|
|
*
|
2011-09-29 06:25:51 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef print_h__
|
|
|
|
#define print_h__
|
|
|
|
|
2011-09-30 05:22:19 +00:00
|
|
|
// ----- Includes -----
|
|
|
|
|
2013-01-26 20:43:59 +00:00
|
|
|
// Compiler Includes
|
2013-01-26 20:05:28 +00:00
|
|
|
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
|
2013-01-26 20:43:59 +00:00
|
|
|
#include <avr/pgmspace.h>
|
2013-01-26 20:05:28 +00:00
|
|
|
#endif
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2014-03-31 08:07:48 +00:00
|
|
|
// Project Includes
|
|
|
|
#include <output_com.h>
|
|
|
|
|
2011-09-30 05:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----- Defines -----
|
2011-09-29 06:25:51 +00:00
|
|
|
#define NL "\r\n"
|
|
|
|
|
|
|
|
|
2011-09-30 05:22:19 +00:00
|
|
|
|
|
|
|
// ----- Functions and Corresponding Function Aliases -----
|
|
|
|
|
2011-09-29 06:25:51 +00:00
|
|
|
/* XXX
|
|
|
|
* Note that all the variadic functions below, take comma separated string lists, they are purposely not printf style (simplicity)
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Function Aliases
|
2014-04-06 18:49:27 +00:00
|
|
|
#define dPrint(c) Output_putstr(c)
|
|
|
|
#define dPrintStr(c) Output_putstr(c)
|
2014-03-31 08:07:48 +00:00
|
|
|
#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
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
// Special Msg Constructs (Uses VT100 tags)
|
|
|
|
#define dPrintMsg(colour_code_str,msg,...) \
|
2014-03-31 08:07:48 +00:00
|
|
|
printstrs("\033[", colour_code_str, "m", msg, "\033[0m - ", __VA_ARGS__, NL, "\0\0\0")
|
2013-11-18 00:17:54 +00:00
|
|
|
#define printMsgNL(colour_code_str,msg,str) \
|
2011-09-29 06:25:51 +00:00
|
|
|
print("\033[" colour_code_str "m" msg "\033[0m - " str NL)
|
2013-11-18 00:17:54 +00:00
|
|
|
#define printMsg(colour_code_str,msg,str) \
|
|
|
|
print("\033[" colour_code_str "m" msg "\033[0m - " str)
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
// Info Messages
|
|
|
|
#define info_dPrint(...) dPrintMsg ("1;32", "INFO", __VA_ARGS__) // Info Msg
|
2013-11-18 00:17:54 +00:00
|
|
|
#define info_print(str) printMsgNL ("1;32", "INFO", str) // Info Msg
|
|
|
|
#define info_msg(str) printMsg ("1;32", "INFO", str) // Info Msg
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
// Warning Messages
|
|
|
|
#define warn_dPrint(...) dPrintMsg ("1;33", "WARNING", __VA_ARGS__) // Warning Msg
|
2013-11-18 00:17:54 +00:00
|
|
|
#define warn_print(str) printMsgNL ("1;33", "WARNING", str) // Warning Msg
|
|
|
|
#define warn_msg(str) printMsg ("1;33", "WARNING", str) // Warning Msg
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
// Error Messages
|
|
|
|
#define erro_dPrint(...) dPrintMsg ("1;5;31", "ERROR", __VA_ARGS__) // Error Msg
|
2013-11-18 00:17:54 +00:00
|
|
|
#define erro_print(str) printMsgNL ("1;5;31", "ERROR", str) // Error Msg
|
|
|
|
#define erro_msg(str) printMsg ("1;5;31", "ERROR", str) // Error Msg
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
// Debug Messages
|
|
|
|
#define dbug_dPrint(...) dPrintMsg ("1;35", "DEBUG", __VA_ARGS__) // Debug Msg
|
2013-11-18 00:17:54 +00:00
|
|
|
#define dbug_print(str) printMsgNL ("1;35", "DEBUG", str) // Debug Msg
|
|
|
|
#define dbug_msg(str) printMsg ("1;35", "DEBUG", str) // Debug Msg
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2013-04-14 02:35:59 +00:00
|
|
|
|
2011-09-29 06:25:51 +00:00
|
|
|
// Static String Printing
|
|
|
|
#define print(s) _print(PSTR(s))
|
|
|
|
|
|
|
|
void _print(const char *s);
|
2014-03-31 08:07:48 +00:00
|
|
|
void printstrs( char* first, ... );
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
|
2013-04-14 00:11:40 +00:00
|
|
|
// Printing numbers
|
|
|
|
#define printHex(hex) printHex_op(hex, 1)
|
|
|
|
|
|
|
|
void printInt8 ( uint8_t in );
|
|
|
|
void printInt16 ( uint16_t in );
|
2014-02-02 08:03:51 +00:00
|
|
|
void printInt32 ( uint32_t in );
|
2013-04-14 00:11:40 +00:00
|
|
|
void printHex_op( uint16_t in, uint8_t op );
|
|
|
|
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
// String Functions
|
|
|
|
#define hexToStr(hex, out) hexToStr_op(hex, out, 1)
|
|
|
|
|
2013-04-14 02:35:59 +00:00
|
|
|
void int8ToStr ( uint8_t in, char* out );
|
|
|
|
void int16ToStr ( uint16_t in, char* out );
|
2014-02-02 08:03:51 +00:00
|
|
|
void int32ToStr ( uint32_t in, char* out );
|
2013-04-14 02:35:59 +00:00
|
|
|
void hexToStr_op( uint16_t in, char* out, uint8_t op );
|
2011-09-29 06:25:51 +00:00
|
|
|
void revsStr ( char* in );
|
|
|
|
uint16_t lenStr ( char* in );
|
2014-01-24 11:01:09 +00:00
|
|
|
int16_t eqStr ( char* str1, char* str2 ); // Returns -1 if identical, last character of str1 comparison (0 if str1 is like str2)
|
2014-02-03 08:41:57 +00:00
|
|
|
int decToInt ( char* in ); // Returns the int representation of a string
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|