forked from Integreight/1Sheeld-Arduino-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatternShield.cpp
79 lines (62 loc) · 1.42 KB
/
PatternShield.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
/*
Project: 1Sheeld Library
File: PatternShield.cpp
Version: 1.4
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2015.1
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "PatternShield.h"
//Constructor
PatternShield::PatternShield() : ShieldParent(PATTERN_ID)
{
isNewPattern =false;
isCallBackAssigned = false;
length=0;
for(int i=0;i<MAX_PATTERN_SIZE;i++){
nodes[i]=PatternNode();
}
}
PatternNode * PatternShield::getLastPattern()
{
isNewPattern = false;
return nodes;
}
int PatternShield::getLastPatternLength()
{
return length;
}
bool PatternShield::isNewPatternReceived()
{
return isNewPattern;
}
void PatternShield::setOnNewPattern(void (* userFunction)(PatternNode patternNode[] ,int length))
{
isCallBackAssigned = true;
changeCallBack = userFunction;
}
//Process Input Data
void PatternShield::processData()
{
byte functionID = getOneSheeldInstance().getFunctionId();
if(functionID==PATTERN_VALUE)
{
isNewPattern=true;
length = getOneSheeldInstance().getArgumentLength(0);
if(length>MAX_PATTERN_SIZE)return;
for (int i = 0; i < length; i++)
{
PatternNode node;
node.setValue(getOneSheeldInstance().getArgumentData(0)[i]);
nodes[i]=node;
}
if(isCallBackAssigned && !isInACallback())
{
enteringACallback();
(*changeCallBack)(nodes,length);
exitingACallback();
}
}
}