forked from Integreight/1Sheeld-Arduino-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneSheeldPrintln.cpp
127 lines (104 loc) · 2.53 KB
/
OneSheeldPrintln.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
/*
Project: 1Sheeld Library
File: OneSheeldPrintln.cpp
Version: 1.2
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2014.9
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "OneSheeldPrintln.h"
//Constructor
PrintlnClass::PrintlnClass(byte shid,byte writefnid, byte printfnid):PrintClass(shid,writefnid,printfnid)
{
}
//Print newline
void PrintlnClass::println()
{
char buffer[3];
buffer[0]='\r';
buffer[1]='\n';
buffer[2]='\0';
print(buffer);
}
//Print character with newline
void PrintlnClass::println(char data)
{
char buffer[4];
buffer[0]=data;
buffer[1]='\r';
buffer[2]='\n';
buffer[3]='\0';
print(buffer);
}
//Print integers with newline
void PrintlnClass::println(int data ,byte base)
{
char stringPointer[10];
snprintf(stringPointer,9,"%d",data);
strcat(stringPointer,"\r\n");
print(stringPointer);
}
//Print unsigned integers with newline
void PrintlnClass::println(unsigned int data , byte base)
{
char stringPointer[9];
snprintf(stringPointer,8,"%d",data);
strcat(stringPointer,"\r\n");
print(stringPointer);
}
//Print long with newline
void PrintlnClass::println(long data ,byte base)
{
char stringPointer[15];
snprintf(stringPointer,14,"%ld",data);
strcat(stringPointer,"\r\n");
print(stringPointer);
}
//Print unsigned long with newline
void PrintlnClass::println(unsigned long data , byte base)
{
char stringPointer[14];
snprintf(stringPointer,13,"%lu",data);
strcat(stringPointer,"\r\n");
print(stringPointer);
}
//Print string with newline
void PrintlnClass::println(const char * stringData)
{
char stringNewLine[strlen(stringData)+3];
stringNewLine[0]='\0';
strcat(stringNewLine,stringData);
strcat(stringNewLine,"\r\n");
print(stringNewLine);
}
//Support strings
void PrintlnClass::println(String stringData)
{
int stringDataLength = stringData.length();
char cTypeStringData[stringDataLength+3];
for(int i=0 ;i<stringDataLength ;i++)
{
cTypeStringData[i]=stringData[i];
}
cTypeStringData[stringDataLength]='\r';
cTypeStringData[stringDataLength+1]='\n';
cTypeStringData[stringDataLength+2]='\0';
print(cTypeStringData);
}
//Unsupported by Intel Galileo board and Arduino Due
#if !defined(ARDUINO_LINUX) && !defined(SAM3X8)
void PrintlnClass::println(double data, int precesion)
{
int i=0;
char buffer[32]={'\0'};
dtostrf(data,1,precesion,buffer);
while(buffer[i]!='\0' && i<32)i++;
if(i+2>32)return;
buffer[i]='\r';
buffer[i+1]='\n';
buffer[i+2]='\0';
print(buffer);
}
#endif