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();
~PixelBot(); ~PixelBot();
/// <summary> /// <summary>
/// The current protocol version that this this PixelBot implementation understands. /// 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. /// Very important to avoid strange behavious when a PixelBot hasn't has it's code updated.
/// </summary> /// </summary>
static const unsigned short PROTOCOL_VERSION = 1; static const unsigned short PROTOCOL_VERSION = 1;
/// <summary> /// <summary>
/// Listens for beacon pings that reveal the location of the PixelHub server. /// Listens for beacon pings that reveal the location of the PixelHub server.
@ -93,4 +93,3 @@ private:
}; };

View file

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

View file

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

View file

@ -8,24 +8,23 @@ PixelMessage::PixelMessage()
} }
PixelMessage::PixelMessage(byte* rawMessage) : PixelMessage() PixelMessage::PixelMessage(byte* rawMessage) : PixelMessage()
{ {
// Casting solution from http://stackoverflow.com/a/300837/1460422 // 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 // 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 // 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 // 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 // actually want. This extra step is needed to get it to cast multiple consecutive bytes
// in the raw message into the type we want. // in the raw message into the type we want.
// With the casts done, we simply dereference the pointer to shove the value into the // With the casts done, we simply dereference the pointer to shove the value into the
// instance of this class that we're building. // instance of this class that we're building.
ProtocolVersion = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage))); ProtocolVersion = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage)));
MessageType = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage + 2))); MessageType = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage + 2)));
MessageId = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 4))); MessageId = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 4)));
MessageLength = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 8))); MessageLength = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 8)));
// TODO: Sort out the payload here. // TODO: Sort out the payload here.
} }
PixelMessage::~PixelMessage() PixelMessage::~PixelMessage()
{ {
} }

View file

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

View file

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