Port of Arduino Pixy Cmucam5 library
Fork of pixy by
Pixy.h.orig@8:6cd36ded7c4e, 2016-03-13 (annotated)
- Committer:
- balsamfir
- Date:
- Sun Mar 13 14:23:33 2016 +0000
- Revision:
- 8:6cd36ded7c4e
- Parent:
- 6:f1c641be779e
Fixed block reading bug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
balsamfir | 6:f1c641be779e | 1 | #ifndef TUIASI_PIXY_H |
balsamfir | 6:f1c641be779e | 2 | #define TUIASI_PIXY_H |
balsamfir | 6:f1c641be779e | 3 | |
balsamfir | 6:f1c641be779e | 4 | #include "mbed.h" |
balsamfir | 6:f1c641be779e | 5 | #include "PixyLinkSPI.h" |
balsamfir | 6:f1c641be779e | 6 | #include "PixyLinkI2C.h" |
balsamfir | 6:f1c641be779e | 7 | #include "PixyLinkUART.h" |
balsamfir | 6:f1c641be779e | 8 | |
balsamfir | 6:f1c641be779e | 9 | struct Block { |
balsamfir | 6:f1c641be779e | 10 | void print(Serial &pc) { |
balsamfir | 6:f1c641be779e | 11 | pc.printf("sig: %d x: %d y: %d width: %d height: %d angle: %d \n\r", signature, x, y, width, height, angle); |
balsamfir | 6:f1c641be779e | 12 | }; |
balsamfir | 6:f1c641be779e | 13 | uint16_t type; |
balsamfir | 6:f1c641be779e | 14 | uint16_t signature; |
balsamfir | 6:f1c641be779e | 15 | uint16_t x; |
balsamfir | 6:f1c641be779e | 16 | uint16_t y; |
balsamfir | 6:f1c641be779e | 17 | uint16_t width; |
balsamfir | 6:f1c641be779e | 18 | uint16_t height; |
balsamfir | 6:f1c641be779e | 19 | int16_t angle; |
balsamfir | 6:f1c641be779e | 20 | }; |
balsamfir | 6:f1c641be779e | 21 | |
balsamfir | 6:f1c641be779e | 22 | class Pixy |
balsamfir | 6:f1c641be779e | 23 | { |
balsamfir | 6:f1c641be779e | 24 | public: |
balsamfir | 6:f1c641be779e | 25 | enum LinkType {SPI, I2C, UART}; |
balsamfir | 6:f1c641be779e | 26 | Pixy(LinkType linkType, PinName mosi_sda_tx, PinName miso_scl_rx, PinName sclk = NC); |
balsamfir | 6:f1c641be779e | 27 | ~Pixy(); |
balsamfir | 6:f1c641be779e | 28 | uint16_t getBlocks(uint16_t maxBlocks=1000); |
balsamfir | 6:f1c641be779e | 29 | int8_t setServos(uint16_t s0, uint16_t s1); |
balsamfir | 6:f1c641be779e | 30 | void setAddress(uint8_t addr); |
balsamfir | 6:f1c641be779e | 31 | void setSerialOutput(Serial *pc); |
balsamfir | 6:f1c641be779e | 32 | |
balsamfir | 6:f1c641be779e | 33 | Block *blocks; |
balsamfir | 6:f1c641be779e | 34 | |
balsamfir | 6:f1c641be779e | 35 | private: |
balsamfir | 6:f1c641be779e | 36 | static const uint8_t PIXY_INITIAL_ARRAYSIZE = 30; |
balsamfir | 6:f1c641be779e | 37 | static const uint8_t PIXY_MAXIMUM_ARRAYSIZE = 130; |
balsamfir | 6:f1c641be779e | 38 | static const uint16_t PIXY_START_WORD = 0xaa55; |
balsamfir | 6:f1c641be779e | 39 | static const uint16_t PIXY_START_WORD_CC = 0xaa56; |
balsamfir | 6:f1c641be779e | 40 | static const uint16_t PIXY_START_WORDX = 0x55aa; |
balsamfir | 6:f1c641be779e | 41 | static const uint8_t PIXY_DEFAULT_ADDR = 0x54; // I2C |
balsamfir | 6:f1c641be779e | 42 | |
balsamfir | 6:f1c641be779e | 43 | bool getStart(uint16_t *type); |
balsamfir | 6:f1c641be779e | 44 | void resize(); |
balsamfir | 6:f1c641be779e | 45 | |
balsamfir | 6:f1c641be779e | 46 | bool skipStart; |
balsamfir | 6:f1c641be779e | 47 | uint16_t blockCount; |
balsamfir | 6:f1c641be779e | 48 | uint16_t blockArraySize; |
balsamfir | 6:f1c641be779e | 49 | |
balsamfir | 6:f1c641be779e | 50 | PixyLink *m_link; |
balsamfir | 6:f1c641be779e | 51 | Serial *pc; |
balsamfir | 6:f1c641be779e | 52 | }; |
balsamfir | 6:f1c641be779e | 53 | #endif //TUIASI_PIXY_H |