an SPI interface the cmu pixy camera
Dependents: robotic_fish_ver_4_9_pixy UMO
pixy.h@2:fc86438b206f, 2014-06-03 (annotated)
- Committer:
- sandwich
- Date:
- Tue Jun 03 15:09:31 2014 +0000
- Revision:
- 2:fc86438b206f
- Parent:
- 1:439c7574a5ee
- Child:
- 4:440e747935db
can track multiple objects
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandwich | 0:1b99a0bee9e0 | 1 | #pragma once |
sandwich | 0:1b99a0bee9e0 | 2 | #include "mbed.h" |
sandwich | 0:1b99a0bee9e0 | 3 | |
sandwich | 2:fc86438b206f | 4 | #define INVALID_BLOCK 20 |
sandwich | 0:1b99a0bee9e0 | 5 | //a class to aid in SPI communication with the pixy camera |
sandwich | 0:1b99a0bee9e0 | 6 | |
sandwich | 0:1b99a0bee9e0 | 7 | //this details the object block format of returned data as described in |
sandwich | 0:1b99a0bee9e0 | 8 | //http://www.cmucam.org/projects/cmucam5/wiki/Pixy_Serial_Protocol |
sandwich | 0:1b99a0bee9e0 | 9 | |
sandwich | 0:1b99a0bee9e0 | 10 | //blatantly stole this from their code |
sandwich | 0:1b99a0bee9e0 | 11 | struct Block |
sandwich | 0:1b99a0bee9e0 | 12 | { |
sandwich | 0:1b99a0bee9e0 | 13 | uint16_t signature; |
sandwich | 0:1b99a0bee9e0 | 14 | uint16_t x; |
sandwich | 0:1b99a0bee9e0 | 15 | uint16_t y; |
sandwich | 0:1b99a0bee9e0 | 16 | uint16_t width; |
sandwich | 0:1b99a0bee9e0 | 17 | uint16_t height; |
sandwich | 0:1b99a0bee9e0 | 18 | }; |
sandwich | 0:1b99a0bee9e0 | 19 | |
sandwich | 0:1b99a0bee9e0 | 20 | class pixySPI |
sandwich | 0:1b99a0bee9e0 | 21 | { |
sandwich | 0:1b99a0bee9e0 | 22 | private: |
sandwich | 0:1b99a0bee9e0 | 23 | SPI* spi; |
sandwich | 0:1b99a0bee9e0 | 24 | Serial* debug; |
sandwich | 0:1b99a0bee9e0 | 25 | //SPI spi(p5, p6, p7); // mosi, miso, sclk |
sandwich | 0:1b99a0bee9e0 | 26 | short sync; //the block signature. 16 bits |
sandwich | 0:1b99a0bee9e0 | 27 | short readTwoBytesLSB(); |
sandwich | 0:1b99a0bee9e0 | 28 | void readNBytes(char* buf, int num); |
sandwich | 2:fc86438b206f | 29 | Block* blocks; //where the blocks are stored |
sandwich | 2:fc86438b206f | 30 | int numBlocks; //amt |
sandwich | 0:1b99a0bee9e0 | 31 | public: |
sandwich | 2:fc86438b206f | 32 | pixySPI(PinName mosi,PinName miso,PinName sclk, int nBlocks, Serial* ser); |
sandwich | 0:1b99a0bee9e0 | 33 | ~pixySPI(); |
sandwich | 2:fc86438b206f | 34 | void capture(); //fills in the blocks pointer |
sandwich | 0:1b99a0bee9e0 | 35 | char getRawData(); |
sandwich | 2:fc86438b206f | 36 | Block* getBlocks(); |
sandwich | 2:fc86438b206f | 37 | int getNumBlocks(); |
sandwich | 0:1b99a0bee9e0 | 38 | }; |