farmbot-arduino-firmware/src/CurrentState.cpp

119 lines
2.2 KiB
C++
Raw Normal View History

/*
* CurrentState.cpp
*
* Created on: 15 maj 2014
* Author: MattLech
*/
#include "CurrentState.h"
static CurrentState* instance;
2014-07-23 01:46:21 -06:00
long x = 0;
long y = 0;
long z = 0;
unsigned int speed = 0;
2014-07-23 01:46:21 -06:00
bool endStopState[3][2];
CurrentState * CurrentState::getInstance() {
if (!instance) {
instance = new CurrentState();
};
return instance;
};
CurrentState::CurrentState() {
x = 0;
y = 0;
z = 0;
speed = 0;
}
2014-07-24 15:04:19 -06:00
long CurrentState::getX() {
return x;
}
2014-07-24 15:04:19 -06:00
long CurrentState::getY() {
return y;
}
2014-07-24 15:04:19 -06:00
long CurrentState::getZ() {
return z;
}
2014-07-24 15:04:19 -06:00
long* CurrentState::getPoint() {
long currentPoint[3] = {x, y, z};
return currentPoint;
}
2014-07-24 15:04:19 -06:00
void CurrentState::setX(long newX) {
x = newX;
}
2014-07-24 15:04:19 -06:00
void CurrentState::setY(long newY) {
y = newY;
}
2014-07-24 15:04:19 -06:00
void CurrentState::setZ(long newZ) {
z = newZ;
}
2014-07-23 01:46:21 -06:00
void CurrentState::setEndStopState(unsigned int axis, unsigned int position, bool state) {
endStopState[axis][position] = state;
}
2014-07-24 15:04:19 -06:00
void CurrentState::storeEndStops() {
CurrentState::getInstance()->setEndStopState(0,0,digitalRead(X_MIN_PIN));
CurrentState::getInstance()->setEndStopState(0,1,digitalRead(X_MAX_PIN));
CurrentState::getInstance()->setEndStopState(1,0,digitalRead(Y_MIN_PIN));
CurrentState::getInstance()->setEndStopState(1,1,digitalRead(Y_MAX_PIN));
CurrentState::getInstance()->setEndStopState(2,0,digitalRead(Z_MIN_PIN));
2014-10-30 14:05:17 -06:00
CurrentState::getInstance()->setEndStopState(2,1,digitalRead(Z_MAX_PIN));
2014-07-24 15:04:19 -06:00
}
2014-07-23 01:46:21 -06:00
void CurrentState::printPosition() {
Serial.print("R82");
2014-07-23 01:46:21 -06:00
Serial.print(" X");
Serial.print(x);
2014-07-23 01:46:21 -06:00
Serial.print(" Y");
Serial.print(y);
2014-07-23 01:46:21 -06:00
Serial.print(" Z");
Serial.print(z);
Serial.print("\r\n");
2014-07-23 01:46:21 -06:00
}
void CurrentState::printBool(bool value)
{
if (value)
{
Serial.print("1");
}
else
{
Serial.print("0");
}
}
void CurrentState::printEndStops() {
Serial.print("R81");
2014-07-23 01:46:21 -06:00
Serial.print(" XA");
printBool(endStopState[0][0]);
Serial.print(" XB");
printBool(endStopState[0][1]);
Serial.print(" YA");
printBool(endStopState[1][0]);
Serial.print(" YB");
printBool(endStopState[1][1]);
Serial.print(" ZA");
printBool(endStopState[2][0]);
Serial.print(" ZB");
printBool(endStopState[2][1]);
Serial.print("\r\n");
2014-07-23 01:46:21 -06:00
}
void CurrentState::print() {
printPosition();
printEndStops();
}