A library for interfacing with the Pixy color recognition camera
Dependents: PixyCamera MbedOS_Robot_Team ManualControlFinal PlayBack ... more
Revision 3:66df7d295245, committed 2016-03-14
- Comitter:
- swilkins8
- Date:
- Mon Mar 14 18:53:43 2016 +0000
- Parent:
- 2:fa582d9d91b5
- Commit message:
- Completed comments/documentation for all classes
Changed in this revision
diff -r fa582d9d91b5 -r 66df7d295245 Pixy.h --- a/Pixy.h Mon Mar 14 17:50:40 2016 +0000 +++ b/Pixy.h Mon Mar 14 18:53:43 2016 +0000 @@ -7,22 +7,28 @@ #define X_CENTER ((PIXY_MAX_X-PIXY_MIN_X)/2) #define Y_CENTER ((PIXY_MAX_Y-PIXY_MIN_Y)/2) -/** The SPI interface for the Pixy camera - * Used for instantiating a Pixy object that interfaces via an SPI connection - * @param SPI* spi the pointer to the SPI connection - * @param Serial* serialOut the optional serial output pointer to print out Pixy camera data - * @param int arg an optional integer argument used for custom implementations of the Pixy library +/** The SPI Pixy interface for the Pixy camera * @code * #include "Pixy.h" * Serial serial(USBTX, USBRX); * SPI spi(p5, p6, p7); * PixySPI pixy(&spi, &serial); + * + * int main() { + * runPanTiltDemo(); + * } * @endcode */ class PixySPI : public TPixy<PixyInterfaceSPI> { public: + /** Constructor for the PixySPI class + * Instantiates a Pixy object that communicates via an SPI connection + * @param SPI* spi the pointer to the SPI connection + * @param Serial* serialOut the optional serial output pointer to print out Pixy camera data + * @param int arg an optional integer argument used for custom implementations of the Pixy library + */ PixySPI(SPI* spi, Serial* serialOut = NULL, uint16_t arg = PIXY_DEFAULT_ARGVAL) : TPixy<PixyInterfaceSPI>((new PixyInterfaceSPI(spi)), serialOut, arg) {} };
diff -r fa582d9d91b5 -r 66df7d295245 TPixy.h --- a/TPixy.h Mon Mar 14 17:50:40 2016 +0000 +++ b/TPixy.h Mon Mar 14 18:53:43 2016 +0000 @@ -48,8 +48,15 @@ CC_BLOCK }; +/** A structure for containing Block data + * signature the signature of the block + * x the x position of the block on the screen + * y the y position of the block on the screen + * width the width of the block on the screen + * height the height of the block on the screen + * angle the angle of the block + */ struct Block { - // print block structure! uint16_t signature; uint16_t x; uint16_t y; @@ -67,30 +74,52 @@ Serial* serial; Block *blocks; - /** Constructor for the TPixy object - * Creates a TPixy object with a given connection handler - * @param TPixyInterface* type the pointer to the interface connection handler - * @param Serial* serialOut the optional serial output pointer to print out Pixy camera data - * @param int arg an optional integer argument used for custom implementations of the Pixy library + /** Creates a TPixy object with a given connection handler + * @param type the pointer to the interface connection handler + * @param serialOut the optional serial output pointer to print out Pixy camera data + * @param arg an optional integer argument used for custom implementations of the Pixy library */ TPixy(TPixyInterface* type, Serial* serialOut = NULL, uint16_t arg = PIXY_DEFAULT_ARGVAL); ~TPixy(); - /** Printer for TPixy to print block information - * Prints the block out to the given serial port - * Block &ref the block to print + /** Prints the given Block out to the given serial port + * @param &block the Block to print + */ + void printBlock(Block &block); + /** Returns the number of Blocks found in the current view and updates all Blocks' info + * @param maxBlocks the maximum number of Blocks to search for + * @return the number of Blocks found + */ + uint16_t getBlocks(uint16_t maxBlocks = 1000); + /** Sets the PWM value of the Pixy servos + * @param s0 the value of the left servo + * @param s1 the value of the right servo + * @return the interface return value for sending the servo command */ - void printBlock(Block &); - uint16_t getBlocks(uint16_t maxBlocks = 1000); int8_t setServos(uint16_t s0, uint16_t s1); + /** Sets the brightness of the Pixy RGB LED + * @param brightness the brightness of the LED + * @return the interface return value for sending the brightness command + */ int8_t setBrightness(uint8_t brightness); + /** Sets the color of the Pixy RGB LED + * @param r the red color value + * @param g the green color value + * @param b the blue color value + */ int8_t setLED(uint8_t r, uint8_t g, uint8_t b); + /** Initializes the Pixy + */ void init(); private: TPixyInterface* link; BlockType blockType; + /** Returns if the Pixy is ready to receive/send a message + */ bool getStart(); + /** Resizes the block array to add an additional block + */ void resize(); bool skipStart; uint16_t blockCount; @@ -112,8 +141,6 @@ link->setArg(arg); } - - template <class TPixyInterface> void TPixy<TPixyInterface>::printBlock(Block &block) { int i, j; @@ -158,7 +185,7 @@ } else if (w == PIXY_START_WORD_CC && lastw == PIXY_START_WORD) { blockType = CC_BLOCK; return true; - } else if (w==PIXY_START_WORDX) { + } else if (w == PIXY_START_WORDX) { if (serial != NULL) { serial->printf("reorder"); }
diff -r fa582d9d91b5 -r 66df7d295245 TPixyInterface.h --- a/TPixyInterface.h Mon Mar 14 17:50:40 2016 +0000 +++ b/TPixyInterface.h Mon Mar 14 18:53:43 2016 +0000 @@ -29,14 +29,34 @@ #define PIXY_SYNC_BYTE_DATA 0x5b #define PIXY_BUF_SIZE 16 +/** An interface for communicating between the Pixy and a specific hardware interface + */ class TPixyInterface { public: + /** Creates a TPixyInterface + */ TPixyInterface() {} + /** Initializes a TPixyInterface + */ virtual void init() = 0; + /** Sends the given data to the Pixy with a given data length + * @param data the data to send + * @param len the length of the data to send + * @return the interface return signal + */ virtual int8_t send(uint8_t *data, uint8_t len) = 0; + /** Sets an argument for the interface to use + * @param arg the argument to use + */ virtual void setArg(uint16_t arg) = 0; + /** Reads a word from the interface + * @return the word read from the interface + */ virtual uint16_t getWord() = 0; + /** Reads a byte from the interface + * @return the byte read from the interface + */ virtual uint8_t getByte() = 0; }; @@ -55,15 +75,36 @@ bool write(BufType c); }; +/** An interface for communicating between the Pixy via an SPI interface + */ class PixyInterfaceSPI : TPixyInterface { public: SPI* spi; + /** Constructs a PixyInterfaceSPI object + * @param interface the SPI pointer + */ PixyInterfaceSPI(SPI* interface); + /** Initializes the PixyInterfaceSPI + */ virtual void init(); + /** Reads a word from the interface + * @return the word read from the interface + */ virtual uint16_t getWord(); + /** Reads a byte from the interface + * @return the byte read from the interface + */ virtual uint8_t getByte(); + /** Sends the given data to the Pixy with a given data length + * @param data the data to send + * @param len the length of the data to send + * @return the interface return signal + */ virtual int8_t send(uint8_t *data, uint8_t len); + /** Sets an argument for the interface to use [unused] + * @param arg the argument to use + */ virtual void setArg(uint16_t arg); private: