Convert spaces to tabs. Yay!

This commit is contained in:
Starbeamrainbowlabs 2017-03-02 18:49:20 +00:00
parent 86e35a494c
commit ad1bcba459
6 changed files with 104 additions and 109 deletions

View file

@ -38,11 +38,11 @@ public:
PixelBot();
~PixelBot();
/// <summary>
/// The current protocol version that this this PixelBot implementation understands.
/// Very important to avoid strange behavious when a PixelBot hasn't has it's code updated.
/// </summary>
static const unsigned short PROTOCOL_VERSION = 1;
/// <summary>
/// The current protocol version that this this PixelBot implementation understands.
/// Very important to avoid strange behavious when a PixelBot hasn't has it's code updated.
/// </summary>
static const unsigned short PROTOCOL_VERSION = 1;
/// <summary>
/// Listens for beacon pings that reveal the location of the PixelHub server.
@ -66,7 +66,7 @@ public:
/// Very useful if you want to do other things at the same time as handling commands from the PixelHub server.
/// </summary>
bool Tick();
private:
// ~~~ Manual Settings ~~~ //
char desiredRemoteRole[7] = { 's', 'e', 'r', 'v', 'e', 'r', '\0' };
@ -91,6 +91,5 @@ private:
// The TCP client to use as the PixelHub server transport connection.
WiFiClient tcpClient = WiFiClient();
};

View file

@ -4,7 +4,7 @@
PixelBotController::PixelBotController()
{
}
PixelBotController::~PixelBotController()
@ -14,52 +14,51 @@ PixelBotController::~PixelBotController()
unsigned long PixelBotController::GetTicksTravelled()
{
return ticksTravelled;
return ticksTravelled;
}
void PixelBotController::MoveDistance(int direction, int ticks)
{
for(int i = 0; i < ticks; i++) {
MoveTick(direction);
delay(tickDelay);
}
for(int i = 0; i < ticks; i++) {
MoveTick(direction);
delay(tickDelay);
}
}
void PixelBotController::MoveTick(int direction)
{
for(int i = 0; i < 8; i++)
{
switch(direction) {
case STOP:
return;
case FORWARDS:
sendTickPart(i,7-i);
break;
case BACKWARDS:
sendTickPart(7-i,i);
break;
case LEFT:
sendTickPart(7-i,7-i);
break;
case RIGHT:
sendTickPart(i,i);
break;
}
delayMicroseconds(motorSpeed);
}
ticksTravelled++;
for(int i = 0; i < 8; i++)
{
switch(direction) {
case STOP:
return;
case FORWARDS:
sendTickPart(i,7-i);
break;
case BACKWARDS:
sendTickPart(7-i,i);
break;
case LEFT:
sendTickPart(7-i,7-i);
break;
case RIGHT:
sendTickPart(i,i);
break;
}
delayMicroseconds(motorSpeed);
}
ticksTravelled++;
}
void PixelBotController::sendTickPart(int leftCode, int rightCode)
{
digitalWrite(lmotorPin1, bitRead(motorLookup[leftCode], 0));
digitalWrite(lmotorPin2, bitRead(motorLookup[leftCode], 1));
digitalWrite(lmotorPin3, bitRead(motorLookup[leftCode], 2));
digitalWrite(lmotorPin4, bitRead(motorLookup[leftCode], 3));
digitalWrite(rmotorPin1, bitRead(motorLookup[rightCode], 0));
digitalWrite(rmotorPin2, bitRead(motorLookup[rightCode], 1));
digitalWrite(rmotorPin3, bitRead(motorLookup[rightCode], 2));
digitalWrite(rmotorPin4, bitRead(motorLookup[rightCode], 3));
digitalWrite(lmotorPin1, bitRead(motorLookup[leftCode], 0));
digitalWrite(lmotorPin2, bitRead(motorLookup[leftCode], 1));
digitalWrite(lmotorPin3, bitRead(motorLookup[leftCode], 2));
digitalWrite(lmotorPin4, bitRead(motorLookup[leftCode], 3));
digitalWrite(rmotorPin1, bitRead(motorLookup[rightCode], 0));
digitalWrite(rmotorPin2, bitRead(motorLookup[rightCode], 1));
digitalWrite(rmotorPin3, bitRead(motorLookup[rightCode], 2));
digitalWrite(rmotorPin4, bitRead(motorLookup[rightCode], 3));
}

View file

@ -8,35 +8,35 @@ class PixelBotController
public:
PixelBotController();
~PixelBotController();
static const int STOP = 0;
static const int FORWARDS = 1;
static const int BACKWARDS = 2;
static const int LEFT = 3;
static const int RIGHT = 4;
static const int STOP = 0;
static const int FORWARDS = 1;
static const int BACKWARDS = 2;
static const int LEFT = 3;
static const int RIGHT = 4;
void MoveDistance(int direction, int ticks);
void MoveDistance(int direction, int ticks);
void MoveTick(int direction);
unsigned long GetTicksTravelled();
unsigned long GetTicksTravelled();
private:
const int rmotorPin1 = 16;
const int rmotorPin2 = 5;
const int rmotorPin3 = 4;
const int rmotorPin4 = 0;
const int lmotorPin1 = 2;
const int lmotorPin2 = 14;
const int lmotorPin3 = 12;
const int lmotorPin4 = 13;
int motorLookup[8] = { 0b01000, 0b01100, 0b00100, 0b00110, 0b00010, 0b00011, 0b00001, 0b01001 };
int motorSpeed = 1200; // The speed at which the stepper motor accepts bits
unsigned long ticksTravelled = 0; // Number of steps travelled (including turns)
int ticksPerRevolution = 512; // Number of steps per full revolution of the wheels
int tickDelay = 1; // The delay in between ticks
const int rmotorPin1 = 16;
const int rmotorPin2 = 5;
const int rmotorPin3 = 4;
const int rmotorPin4 = 0;
const int lmotorPin1 = 2;
const int lmotorPin2 = 14;
const int lmotorPin3 = 12;
const int lmotorPin4 = 13;
int motorLookup[8] = { 0b01000, 0b01100, 0b00100, 0b00110, 0b00010, 0b00011, 0b00001, 0b01001 };
int motorSpeed = 1200; // The speed at which the stepper motor accepts bits
unsigned long ticksTravelled = 0; // Number of steps travelled (including turns)
int ticksPerRevolution = 512; // Number of steps per full revolution of the wheels
int tickDelay = 1; // The delay in between ticks
void sendTickPart(int leftCode, int rightCode);
void sendTickPart(int leftCode, int rightCode);
};

View file

@ -4,28 +4,27 @@
PixelMessage::PixelMessage()
{
}
PixelMessage::PixelMessage(byte* rawMessage) : PixelMessage()
{
// Casting solution from http://stackoverflow.com/a/300837/1460422
// Basically, it casts a byte* pointer reference to the start of the bit we want to extract
// into a void* (which is just a point that points to a specific point in memory without a
// specific type associated with it), which we then cast into a pointer of the type we
// actually want. This extra step is needed to get it to cast multiple consecutive bytes
// in the raw message into the type we want.
// With the casts done, we simply dereference the pointer to shove the value into the
// instance of this class that we're building.
ProtocolVersion = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage)));
MessageType = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage + 2)));
MessageId = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 4)));
MessageLength = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 8)));
// Casting solution from http://stackoverflow.com/a/300837/1460422
// Basically, it casts a byte* pointer reference to the start of the bit we want to extract
// into a void* (which is just a point that points to a specific point in memory without a
// specific type associated with it), which we then cast into a pointer of the type we
// actually want. This extra step is needed to get it to cast multiple consecutive bytes
// in the raw message into the type we want.
// With the casts done, we simply dereference the pointer to shove the value into the
// instance of this class that we're building.
ProtocolVersion = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage)));
MessageType = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage + 2)));
MessageId = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 4)));
MessageLength = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 8)));
// TODO: Sort out the payload here.
// TODO: Sort out the payload here.
}
PixelMessage::~PixelMessage()
{
}

View file

@ -6,25 +6,24 @@
struct PixelMessage
{
public:
PixelMessage();
PixelMessage(byte* rawMessage);
~PixelMessage();
PixelMessage();
PixelMessage(byte* rawMessage);
~PixelMessage();
/// <summary>
/// The length of the message header, in bytes.
/// The message header contains things like the protocol version, the payload length, and the message type.
/// </summary>
static const unsigned int MESSAGE_HEADER_LENGTH = 12;
// The protocol version associated with this message.
unsigned short ProtocolVersion = 1;
unsigned short MessageType = 1;
unsigned int MessageId = 0;
unsigned int MessageLength = 0;
/// <summary>
/// The length of the message header, in bytes.
/// The message header contains things like the protocol version, the payload length, and the message type.
/// </summary>
static const unsigned int MESSAGE_HEADER_LENGTH = 12;
//const byte* Payload;
// The protocol version associated with this message.
unsigned short ProtocolVersion = 1;
unsigned short MessageType = 1;
unsigned int MessageId = 0;
unsigned int MessageLength = 0;
//const byte* Payload;
private:
};

View file

@ -15,9 +15,9 @@ int findChar(char* str, char targetChar)
/*
int getPosition(const char *array, size_t size, char c)
{
const char* end = array + size;
const char* match = std::find(array, end, c);
return (end == match)? -1 : (match-array);
const char* end = array + size;
const char* match = std::find(array, end, c);
return (end == match)? -1 : (match-array);
}
*/
@ -29,4 +29,3 @@ void Utilities::PrintCharsAsHex(char* charArray, size_t length)
Serial.print(" ");
}
}