James Cameron / pixy

Fork of pixy by Arcadie Cracan

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Pixy.h Source File

Pixy.h

00001 #ifndef TUIASI_PIXY_H
00002 #define TUIASI_PIXY_H
00003 
00004 #include "mbed.h"
00005 #include "PixyLinkSPI.h"
00006 #include "PixyLinkI2C.h"
00007 #include "PixyLinkUART.h"
00008 
00009 struct Block {
00010     void print(Serial &pc) {
00011         pc.printf("sig: %d x: %d y: %d width: %d height: %d\n", signature, x, y, width, height);
00012     };
00013     uint16_t signature;
00014     uint16_t x;
00015     uint16_t y;
00016     uint16_t width;
00017     uint16_t height;
00018 };
00019 
00020 class Pixy
00021 {
00022 public:
00023     enum LinkType {SPI, I2C, UART};
00024     Pixy(LinkType linkType, PinName mosi_sda_tx, PinName miso_scl_rx, PinName sclk = NC);
00025     ~Pixy();
00026     uint16_t getBlocks(uint16_t maxBlocks=1000);
00027     int8_t setServos(uint16_t s0, uint16_t s1);
00028     void setAddress(uint8_t addr);
00029     void setSerialOutput(Serial *pc);
00030 
00031     Block *blocks;
00032 
00033 private:
00034     static const uint8_t PIXY_INITIAL_ARRAYSIZE = 30;
00035     static const uint8_t PIXY_MAXIMUM_ARRAYSIZE = 130;
00036     static const uint16_t PIXY_START_WORD = 0xaa55;
00037     static const uint16_t PIXY_START_WORDX = 0x55aa;
00038     static const uint8_t PIXY_DEFAULT_ADDR = 0x54;  // I2C
00039 
00040     bool getStart();
00041     void resize();
00042 
00043     bool skipStart;
00044     uint16_t blockCount;
00045     uint16_t blockArraySize;
00046 
00047     PixyLink *m_link;
00048     Serial *pc;
00049 };
00050 #endif //TUIASI_PIXY_H