-
Notifications
You must be signed in to change notification settings - Fork 24
/
MagnetometerSensorShield.cpp
82 lines (67 loc) · 1.8 KB
/
MagnetometerSensorShield.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
/*
Project: 1Sheeld Library
File: MagnetometerSensorShield.cpp
Version: 1.0
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2014.5
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "MagnetometerSensorShield.h"
//Class Constructor
MagnetometerSensorShield::MagnetometerSensorShield():ShieldParent(MAGNETOMETER_ID)
{
valueX=0;
valueY=0;
valueZ=0;
isCallBackAssigned=false;
}
//X-Axis getter function
float MagnetometerSensorShield::getX()
{
return valueX;
}
//Y-Axis getter function
float MagnetometerSensorShield::getY()
{
return valueY;
}
//Z-Axis getter function
float MagnetometerSensorShield::getZ()
{
return valueZ;
}
//MagnetometerSensor Data processing
void MagnetometerSensorShield::processData()
{
//Check Function-ID
byte functionId=getOneSheeldInstance().getFunctionId();
if(functionId==MAGNETOMETER_VALUE)
{
//Process X-Axis Value
valueX=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(0));
//Process Y-Axis Value
valueY=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(1));
//Process Z-Axis Value
valueZ=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(2));
//User Function Invoked
if(isCallBackAssigned && !isInACallback())
{
enteringACallback();
(*changeCallBack)(valueX,valueY,valueZ);
exitingACallback();
}
}
}
//Users Function Setter
void MagnetometerSensorShield::setOnValueChange(void (*userFunction)(float valueX, float valueY ,float valueZ))
{
changeCallBack=userFunction;
isCallBackAssigned=true;
}
//Helper
float MagnetometerSensorShield::getMagneticStrength()
{
return sqrt((valueX*valueX)+(valueY*valueY)+(valueZ*valueZ));
}