forked from Integreight/1Sheeld-Arduino-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightSensorShield.cpp
61 lines (51 loc) · 1.26 KB
/
LightSensorShield.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
/*
Project: 1Sheeld Library
File: LightSensorShield.cpp
Version: 1.0
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2014.5
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "LightSensorShield.h"
//Class Constructor
LightSensorShield::LightSensorShield() : ShieldParent(LIGHT_ID)
{
value=0;
isCallBackAssigned=false;
}
//Light Getter
unsigned long LightSensorShield::getValue()
{
return value;
}
//Light Input Data Processing
void LightSensorShield::processData()
{
//Checking Function-ID
byte functionId =getOneSheeldInstance().getFunctionId();
if(functionId==LIGHT_VALUE)
{
value=0;
data[0]=getOneSheeldInstance().getArgumentData(0)[0];
data[1]=getOneSheeldInstance().getArgumentData(0)[1];
data[2]=getOneSheeldInstance().getArgumentData(0)[2];
value|=data[0];
value|=(data[1]<<8);
value|=(data[2]<<16);
//Users Function Invoked
if(isCallBackAssigned && !isInACallback())
{
enteringACallback();
(*changeCallBack)(value);
exitingACallback();
}
}
}
//Users Function Setter
void LightSensorShield::setOnValueChange(void (*userFunction)(unsigned long lightValue))
{
changeCallBack=userFunction;
isCallBackAssigned=true;
}