-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatch.cpp
50 lines (40 loc) · 830 Bytes
/
latch.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
// latch.cpp
// Paul Wiegele 2014
#include "latch.h"
#include "assert.h"
#include "sensor.h"
#include "motor.h"
#include "string.h"
CLatch::CLatch(CMotor * motor, CSensor * sensor, int * buffer)
{
assert(motor);
assert(sensor);
assert(buffer);
mMotor = motor;
mMotor->ResetMotor();
mSensor = sensor;
if(!mSensor->Calibrate())
//OUch!
mData=buffer;
memcpy(&mData, &buffer, sizeof(int*));
mSensor->ReadData(mData);
mLatchState = DS_OPEN;
}
bool CLatch::getLatchState()
{
return mLatchState;
}
void CLatch::setLatchState(bool newState)
{
mLatchState = newState;
}
void CLatch::moveMotor(unsigned int distance)
{
assert(distance >= 0 && distance < MAX_SENSOR_DATA);
mMotor->MoveMotor(distance);
}
int CLatch::getData()
{
return mData[mMotor->getCurrentPos()];
}