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 #define DEBUG
19 #include "message.h"
20 // 0x80 is the default (i.e. trace) to turn off set this global to something lower.
21 // this allows for 126 other debugging levels.
22 // TO-DO: Allow assignment to a different serial port
23 int UsbDEBUGlvl = 0x80;
24 
25 void Notifyc(char c, int lvl) {
26  if (UsbDEBUGlvl < lvl) return;
27 #if defined(ARDUINO) && ARDUINO >=100
28  Serial.print(c);
29 #else
30  Serial.print(c, BYTE);
31 #endif
32  Serial.flush();
33 }
34 
35 void Notify(char const * msg, int lvl) {
36  if (UsbDEBUGlvl < lvl) return;
37  if (!msg) return;
38  char c;
39 
40  while ((c = pgm_read_byte(msg++))) Notifyc(c, lvl);
41 }
42 
43 void NotifyStr(char const * msg, int lvl) {
44  if (UsbDEBUGlvl < lvl) return;
45  if (!msg) return;
46  char c;
47 
48  while (c = *msg++) Notifyc(c, lvl);
49 }
50 
51 void Notify(uint8_t b, int lvl) {
52  if (UsbDEBUGlvl < lvl) return;
53 #if defined(ARDUINO) && ARDUINO >=100
54  Serial.print(b);
55 #else
56  Serial.print(b, DEC);
57 #endif
58  Serial.flush();
59 }
60 
61 void Notify(double d, int lvl) {
62  if (UsbDEBUGlvl < lvl) return;
63  Serial.print(d);
64  Serial.flush();
65 }
66 
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 NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) {
83  Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80);
84  PrintHex<uint16_t > (VID, 0x80);
85  Notify(PSTR(" PID: "), 0x80);
86  PrintHex<uint16_t > (PID, 0x80);
87 }
88 
89 void NotifyFail(uint8_t rcode) {
90  PrintHex<uint8_t > (rcode, 0x80);
91  Notify(PSTR("\r\n"), 0x80);
92 }