2014-05-15 11:44:28 -06:00
|
|
|
/*
|
|
|
|
* 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;
|
2014-05-28 17:02:22 -06:00
|
|
|
unsigned int speed = 0;
|
2014-07-23 01:46:21 -06:00
|
|
|
bool endStopState[3][2];
|
2014-05-15 11:44:28 -06:00
|
|
|
|
|
|
|
CurrentState * CurrentState::getInstance() {
|
|
|
|
if (!instance) {
|
|
|
|
instance = new CurrentState();
|
|
|
|
};
|
|
|
|
return instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
CurrentState::CurrentState() {
|
2014-05-28 17:02:22 -06:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
z = 0;
|
|
|
|
speed = 0;
|
2014-05-15 11:44:28 -06:00
|
|
|
}
|
|
|
|
|
2014-07-24 15:04:19 -06:00
|
|
|
long CurrentState::getX() {
|
2014-05-15 11:44:28 -06:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:04:19 -06:00
|
|
|
long CurrentState::getY() {
|
2014-05-15 11:44:28 -06:00
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:04:19 -06:00
|
|
|
long CurrentState::getZ() {
|
2014-05-15 11:44:28 -06:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:04:19 -06:00
|
|
|
long* CurrentState::getPoint() {
|
|
|
|
long currentPoint[3] = {x, y, z};
|
2014-05-25 17:20:00 -06:00
|
|
|
return currentPoint;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:04:19 -06:00
|
|
|
void CurrentState::setX(long newX) {
|
2014-05-15 15:46:47 -06:00
|
|
|
x = newX;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:04:19 -06:00
|
|
|
void CurrentState::setY(long newY) {
|
2014-05-15 15:46:47 -06:00
|
|
|
y = newY;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:04:19 -06:00
|
|
|
void CurrentState::setZ(long newZ) {
|
2014-05-15 15:46:47 -06:00
|
|
|
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() {
|
2014-07-23 15:58:39 -06:00
|
|
|
Serial.print("R82");
|
2014-07-23 01:46:21 -06:00
|
|
|
Serial.print(" X");
|
2014-05-15 15:46:47 -06:00
|
|
|
Serial.print(x);
|
2014-07-23 01:46:21 -06:00
|
|
|
Serial.print(" Y");
|
2014-05-15 15:46:47 -06:00
|
|
|
Serial.print(y);
|
2014-07-23 01:46:21 -06:00
|
|
|
Serial.print(" Z");
|
|
|
|
Serial.print(z);
|
2016-09-09 11:18:16 -06:00
|
|
|
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() {
|
2014-07-23 15:58:39 -06:00
|
|
|
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]);
|
2016-09-09 11:18:16 -06:00
|
|
|
Serial.print("\r\n");
|
2014-07-23 01:46:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void CurrentState::print() {
|
|
|
|
printPosition();
|
|
|
|
printEndStops();
|
2014-05-15 15:46:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|