forked from Integreight/1Sheeld-Arduino-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OneSheeldPrint.cpp
105 lines (85 loc) · 2.63 KB
/
OneSheeldPrint.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
/*
Project: 1Sheeld Library
File: OneSheeldPrint.cpp
Version: 1.2
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2014.9
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "OneSheeldPrint.h"
//Constructor
PrintClass::PrintClass(byte shid,byte writefnid, byte printfnid)
{
shieldId=shid;
print_fn_id=printfnid;
write_fn_id=writefnid;
}
//Write character
void PrintClass::write(char data)
{
OneSheeld.sendShieldFrame(shieldId,0,write_fn_id,1,new FunctionArg(1,(byte *)&data));
}
//Print character
void PrintClass::print(char data)
{
OneSheeld.sendShieldFrame(shieldId,0,print_fn_id,1,new FunctionArg(1,(byte *)&data));
}
//Print integers
void PrintClass::print(int data, byte base)
{
char stringPointer[7];
snprintf(stringPointer,7,"%d",data);
OneSheeld.sendShieldFrame(shieldId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
}
//Print unsigned integers
void PrintClass::print(unsigned int data, byte base)
{
char stringPointer[6];
snprintf(stringPointer,6,"%d",data);
OneSheeld.sendShieldFrame(shieldId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
}
//Print long integers
void PrintClass::print(long data, byte base)
{
char stringPointer[12];
snprintf(stringPointer,12,"%ld",data);
OneSheeld.sendShieldFrame(shieldId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
}
//Print unsigned long integers
void PrintClass::print(unsigned long data , byte base)
{
char stringPointer[11];
snprintf(stringPointer,11,"%lu",data);
OneSheeld.sendShieldFrame(shieldId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
}
//Print string
void PrintClass::print(const char * stringData)
{
//Check length of string
int stringDataLength = strlen(stringData);
if(!stringDataLength) return;
OneSheeld.sendShieldFrame(shieldId,0,print_fn_id,1,new FunctionArg(stringDataLength,(byte*)stringData));
}
void PrintClass::print(String stringData)
{
int stringDataLength = stringData.length();
char cTypeStringData[stringDataLength+1];
for(int i=0 ;i<stringDataLength ;i++)
{
cTypeStringData[i]=stringData[i];
}
cTypeStringData[stringDataLength]='\0';
print(cTypeStringData);
}
//Print double
//Unsupported by Intel Galileo board and Arduino Due
#if !defined(ARDUINO_LINUX) && !defined(SAM3X8)
void PrintClass::print(double data , int precesion)
{
char buffer[32]={'\0'};
dtostrf(data,1,precesion,buffer);
OneSheeld.sendShieldFrame(shieldId,0,print_fn_id,1,new FunctionArg(strlen(buffer),(byte *) buffer));
}
#endif