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 "message.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
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
68  Notify(PSTR("\r\ngetDevDescr"), 0x80);
69 }
70 
72  Notify(PSTR("\r\nsetDevTblEn"), 0x80);
73 }
75  Notify(PSTR("\r\ngetConf"), 0x80);
76 }
77 
79  Notify(PSTR("\r\nsetConf"), 0x80);
80 }
81 
82 void NotifyFailGetDevDescr(uint8_t reason) {
84  NotifyFail(reason);
85 }
86 
87 void NotifyFailSetDevTblEntry(uint8_t reason) {
89  NotifyFail(reason);
90 
91 }
92 
93 void NotifyFailGetConfDescr(uint8_t reason) {
95  NotifyFail(reason);
96 }
97 
98 /* Will we need this in the future?
99 void NotifyFailSetConfDescr(uint8_t reason) {
100  NotifyFailSetConfDescr();
101  NotifyFail(reason);
102 }
103 */
104 void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) {
105  Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80);
106  D_PrintHex<uint16_t > (VID, 0x80);
107  Notify(PSTR(" PID: "), 0x80);
108  D_PrintHex<uint16_t > (PID, 0x80);
109 }
110 
111 void NotifyFail(uint8_t rcode) {
112  D_PrintHex<uint8_t > (rcode, 0x80);
113  Notify(PSTR("\r\n"), 0x80);
114 }
115 #endif