forked from mathijsvandenberg/g29emu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLUFASerial.cpp
157 lines (134 loc) · 3.91 KB
/
LUFASerial.cpp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
Copyright 2019 Mathijs van den Berg (mathijsvandenberg3 [at] gmail [dot] com)
Redistributed under the GPLv3 licence.
Original licence:
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
NOTE: Sloppy code, just needed an arduino like Serial class because the USB Shield library needed one!
*/
// LUFASerial, because the arduino default serial doesnt work!
#include <LUFA/LUFA/Drivers/Peripheral/Serial.h>
#include "LUFASerial.h"
LUFASerial::LUFASerial()
{
}
void LUFASerial::begin(long baud)
{
Serial_Init(baud, false);
}
void LUFASerial::print(const char* StringPtr)
{
uint8_t CurrByte;
while ((CurrByte = *StringPtr) != 0x00)
{
Serial_SendByte(CurrByte);
StringPtr++;
}
}
void LUFASerial::print(long value)
{
int a;
byte temp[16];
for (a=0;a<16;a++)
{
temp[a]=0x00;
}
a=0;
while(value>0 && a < 16)
{
temp[a++] = (value % 10);
value=value/10;
}
if (a==0) { Serial_SendByte(0x30); return; }
for (a=15;a>0;a--)
{
if (temp[a] > 0) { Serial_SendByte(0x30 + temp[a]); }
}
Serial_SendByte(0x30 + temp[0]);
}
void LUFASerial::printhex(int value)
{
int v1,v2;
v1 = (value >> 4) & 0x0F;
switch(v1)
{
case 0: Serial_SendByte('0');break;
case 1: Serial_SendByte('1');break;
case 2: Serial_SendByte('2');break;
case 3: Serial_SendByte('3');break;
case 4: Serial_SendByte('4');break;
case 5: Serial_SendByte('5');break;
case 6: Serial_SendByte('6');break;
case 7: Serial_SendByte('7');break;
case 8: Serial_SendByte('8');break;
case 9: Serial_SendByte('9');break;
case 10: Serial_SendByte('A');break;
case 11: Serial_SendByte('B');break;
case 12: Serial_SendByte('C');break;
case 13: Serial_SendByte('D');break;
case 14: Serial_SendByte('E');break;
case 15: Serial_SendByte('F');break;
default: break;
}
v2 = value & 0x0F;
switch(v2)
{
case 0: Serial_SendByte('0');break;
case 1: Serial_SendByte('1');break;
case 2: Serial_SendByte('2');break;
case 3: Serial_SendByte('3');break;
case 4: Serial_SendByte('4');break;
case 5: Serial_SendByte('5');break;
case 6: Serial_SendByte('6');break;
case 7: Serial_SendByte('7');break;
case 8: Serial_SendByte('8');break;
case 9: Serial_SendByte('9');break;
case 10: Serial_SendByte('A');break;
case 11: Serial_SendByte('B');break;
case 12: Serial_SendByte('C');break;
case 13: Serial_SendByte('D');break;
case 14: Serial_SendByte('E');break;
case 15: Serial_SendByte('F');break;
default: break;
}
}
void LUFASerial::println(const char* StringPtr)
{
LUFASerial::print(StringPtr);
Serial_SendByte('\r');
Serial_SendByte('\n');
return;
}
void LUFASerial::write(int value)
{
Serial_SendByte(value);
return;
}
void LUFASerial::println(long value)
{
LUFASerial::print(value);
Serial_SendByte('\r');
Serial_SendByte('\n');
return;
}
void LUFASerial::println(long value,int type)
{
LUFASerial::print(value);
Serial_SendByte('\r');
Serial_SendByte('\n');
return;
}