USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
message.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2 
3 This software may be distributed and modified under the terms of the GNU
4 General Public License version 2 (GPL2) as published by the Free Software
5 Foundation and appearing in the file GPL2.TXT included in the packaging of
6 this file. Please note that GPL2 Section 2[b] requires that all works based
7 on this software must also be made publicly available under the terms of
8 the GPL2 ("Copyleft").
9 
10 Contact information
11 -------------------
12 
13 Circuits At Home, LTD
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
16  */
17 
18 #include "Usb.h"
19 // 0x80 is the default (i.e. trace) to turn off set this global to something lower.
20 // this allows for 126 other debugging levels.
21 // TO-DO: Allow assignment to a different serial port by software
22 int UsbDEBUGlvl = 0x80;
23 
24 void E_Notifyc(char c, int lvl) {
25  if(UsbDEBUGlvl < lvl) return;
26 #if defined(ARDUINO) && ARDUINO >=100
27  USB_HOST_SERIAL.print(c);
28 #else
29  USB_HOST_SERIAL.print(c, BYTE);
30 #endif
31  //USB_HOST_SERIAL.flush();
32 }
33 
34 void E_Notify(char const * msg, int lvl) {
35  if(UsbDEBUGlvl < lvl) return;
36  if(!msg) return;
37  char c;
38 
39  while((c = pgm_read_byte(msg++))) E_Notifyc(c, lvl);
40 }
41 
42 void E_NotifyStr(char const * msg, int lvl) {
43  if(UsbDEBUGlvl < lvl) return;
44  if(!msg) return;
45  char c;
46 
47  while((c = *msg++)) E_Notifyc(c, lvl);
48 }
49 
50 void E_Notify(uint8_t b, int lvl) {
51  if(UsbDEBUGlvl < lvl) return;
52 #if defined(ARDUINO) && ARDUINO >=100
53  USB_HOST_SERIAL.print(b);
54 #else
55  USB_HOST_SERIAL.print(b, DEC);
56 #endif
57  //USB_HOST_SERIAL.flush();
58 }
59 
60 void E_Notify(double d, int lvl) {
61  if(UsbDEBUGlvl < lvl) return;
62  USB_HOST_SERIAL.print(d);
63  //USB_HOST_SERIAL.flush();
64 }
65 
66 #ifdef DEBUG_USB_HOST
67 
68 void NotifyFailGetDevDescr(void) {
69  Notify(PSTR("\r\ngetDevDescr "), 0x80);
70 }
71 
72 void NotifyFailSetDevTblEntry(void) {
73  Notify(PSTR("\r\nsetDevTblEn "), 0x80);
74 }
75 
76 void NotifyFailGetConfDescr(void) {
77  Notify(PSTR("\r\ngetConf "), 0x80);
78 }
79 
80 void NotifyFailSetConfDescr(void) {
81  Notify(PSTR("\r\nsetConf "), 0x80);
82 }
83 
84 void NotifyFailGetDevDescr(uint8_t reason) {
86  NotifyFail(reason);
87 }
88 
89 void NotifyFailSetDevTblEntry(uint8_t reason) {
91  NotifyFail(reason);
92 
93 }
94 
95 void NotifyFailGetConfDescr(uint8_t reason) {
97  NotifyFail(reason);
98 }
99 
100 void NotifyFailSetConfDescr(uint8_t reason) {
102  NotifyFail(reason);
103 }
104 
105 void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) {
106  Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80);
107  D_PrintHex<uint16_t > (VID, 0x80);
108  Notify(PSTR(" PID: "), 0x80);
109  D_PrintHex<uint16_t > (PID, 0x80);
110 }
111 
112 void NotifyFail(uint8_t rcode) {
113  D_PrintHex<uint8_t > (rcode, 0x80);
114  Notify(PSTR("\r\n"), 0x80);
115 }
116 #endif
void E_NotifyStr(char const *msg, int lvl)
Definition: message.cpp:42
#define NotifyFail(...)
Definition: message.h:55
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
void E_Notifyc(char c, int lvl)
Definition: message.cpp:24
#define Notify(...)
Definition: message.h:44
#define USB_HOST_SERIAL
Definition: settings.h:34
#define NotifyFailGetConfDescr(...)
Definition: message.h:52
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
void E_Notify(char const *msg, int lvl)
Definition: message.cpp:34
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
int UsbDEBUGlvl
Definition: message.cpp:22
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51