-
Notifications
You must be signed in to change notification settings - Fork 24
/
PhoneShield.cpp
118 lines (99 loc) · 2.32 KB
/
PhoneShield.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
/*
Project: 1Sheeld Library
File: PhoneShield.cpp
Version: 1.0
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2014.5
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "PhoneShield.h"
//Class Constructor
PhoneShieldClass::PhoneShieldClass() : ShieldParent(PHONE_ID)
{
value=0;
number=NULL;
isCallBackAssigned=false;
usedSetOnString=false;
}
//Call Setter
void PhoneShieldClass::call(const char* phone)
{
//Check length of string
int phoneLength = strlen(phone);
if(!phoneLength) return;
OneSheeld.sendShieldFrame(PHONE_ID,0,PHONE_CALL,1,new FunctionArg(phoneLength,(byte *)phone));
}
void PhoneShieldClass::call(String phone)
{
call(&phone[0]);
}
//Ringing Checker
bool PhoneShieldClass::isRinging()
{
return !!value;
}
//Number Getter
char * PhoneShieldClass::getNumber()
{
value=!!value;
return number;
}
String PhoneShieldClass::getNumberAsString()
{
String phoneNumberAsString(number);
return phoneNumberAsString;
}
//Phone Input Data Processing
void PhoneShieldClass::processData()
{
//Checking Function-ID
byte functionId= getOneSheeldInstance().getFunctionId();
if (functionId==PHONE_IS_RINGING)
{
value =getOneSheeldInstance().getArgumentData(0)[0];
}
else if (functionId==PHONE_GET_NUMBER)
{
if(number!=0)
{
free(number);
}
byte length=getOneSheeldInstance().getArgumentLength(0);
number=(char*)malloc(sizeof(char)*(length+1));
for (int i=0; i< length;i++)
{
number[i]=getOneSheeldInstance().getArgumentData(0)[i];
}
number[length]='\0';
//Users Function Invoked
if(!isInACallback())
{
if (isCallBackAssigned)
{
enteringACallback();
(*changeCallBack)(value,number);
exitingACallback();
}
if(usedSetOnString)
{
enteringACallback();
String phoneNumberAsString(number);
(*changeCallBackString)(value,phoneNumberAsString);
exitingACallback();
}
}
}
}
//Users Function Setter
void PhoneShieldClass::setOnCallStatusChange(void (*userFunction)(bool isRinging,char phoneNumber []))
{
changeCallBack=userFunction;
isCallBackAssigned=true;
}
void PhoneShieldClass::setOnCallStatusChange(void (*userFunction)(bool isRinging,String phoneNumber))
{
changeCallBackString=userFunction;
usedSetOnString=true;
}