forked from Integreight/1Sheeld-Arduino-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLCDShield.cpp
138 lines (116 loc) · 5.21 KB
/
GLCDShield.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
/*
Project: 1Sheeld Library
File: GLCDShield.cpp
Version: 7.0
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2015.7
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "GLCDShield.h"
GLCDShield::GLCDShield() : ShieldParent(GLCD_ID)
{
for(int i=0;i<MAX_NO_OF_SHAPE_USED;i++){
interactiveShapesArray[i]=NULL;
}
}
void GLCDShield::clear()
{
byte functionId = GLCD_CLEAR;
OneSheeld.sendShieldFrame(GLCD_ID,0,GLCD_TYPE,1,new FunctionArg(1,&functionId));
}
void GLCDShield::draw(ShapeClass &usersShape)
{
byte currentShapeType = usersShape.shapeType;
if(usersShape.isInteractiveShape)
{
bool shapeIsAdded = addToShapesArray(usersShape);
if(shapeIsAdded) usersShape.draw();
}
else
{
usersShape.draw();
}
}
bool GLCDShield::addToShapesArray(ShapeClass & shape)
{
int i;
for (i = 0; i < MAX_NO_OF_SHAPE_USED; i++)
{
if(interactiveShapesArray[i]==NULL)break;
}
if(i>=MAX_NO_OF_SHAPE_USED)return false;
else
{
interactiveShapesArray[i]= &shape;
return true;
}
}
void GLCDShield::processData()
{
byte functionId = getOneSheeldInstance().getArgumentData(0)[0];
if(functionId == GLCD_GET_DATA_FROM_SHAPE)
{
int shapeId =(getOneSheeldInstance().getArgumentData(1)[0] | ((getOneSheeldInstance().getArgumentData(1)[1])<<8));
byte incomingShapeType = getOneSheeldInstance().getFunctionId();
for(int i = 0 ; i<MAX_NO_OF_SHAPE_USED ;i++)
{
if(interactiveShapesArray[i] != NULL && interactiveShapesArray[i]->shapeID == shapeId && interactiveShapesArray[i]->shapeType == incomingShapeType)
{
switch(incomingShapeType)
{
case GLCD_BUTTON_TYPE : {
bool incomingButtonValue = getOneSheeldInstance().getArgumentData(2)[0];
GLCDButton * buttonPointer = ((GLCDButton*)(interactiveShapesArray[i]));
buttonPointer->value = incomingButtonValue;
if(buttonPointer->isCallBackAssigned && !isInACallback())
{
enteringACallback();
buttonPointer->onChangeCallback(incomingButtonValue);
exitingACallback();
}
break;
}
case GLCD_RADIO_BUTTON_TYPE : {
bool incomingRadioButtonValue = getOneSheeldInstance().getArgumentData(2)[0];
GLCDRadioButton * radioButtonPointer = ((GLCDRadioButton *)(interactiveShapesArray[i]));
radioButtonPointer->value = incomingRadioButtonValue;
if(radioButtonPointer->isCallbackAssigned && !isInACallback())
{
enteringACallback();
radioButtonPointer->onChangeCallback(incomingRadioButtonValue);
exitingACallback();
}
break;
}
case GLCD_CHECK_BOX_TYPE : {
bool incomingCheckBoxValue = getOneSheeldInstance().getArgumentData(2)[0];
GLCDCheckBox * checkBoxPointer = ((GLCDCheckBox *)(interactiveShapesArray[i]));
checkBoxPointer->value = incomingCheckBoxValue;
if(checkBoxPointer->isCallbackAssigned && !isInACallback())
{
enteringACallback();
checkBoxPointer->onChangeCallback(incomingCheckBoxValue);
exitingACallback();
}
break;
}
case GLCD_SLIDER_TYPE : {
int incomingSliderValue =(getOneSheeldInstance().getArgumentData(2)[0] | ((getOneSheeldInstance().getArgumentData(2)[1])<<8));
GLCDSlider * sliderPointer = ((GLCDSlider *)(interactiveShapesArray[i]));
sliderPointer->value = incomingSliderValue;
if(sliderPointer->isCallbackAssigned && !isInACallback())
{
enteringACallback();
sliderPointer->onChangeCallback(incomingSliderValue);
exitingACallback();
}
break;
}
}
break;
}
}
}
}