an SPI interface the cmu pixy camera
Dependents: robotic_fish_ver_4_9_pixy UMO
pixy.h@6:4bf8d39fc5ce, 2014-06-05 (annotated)
- Committer:
- sandwich
- Date:
- Thu Jun 05 17:31:43 2014 +0000
- Revision:
- 6:4bf8d39fc5ce
- Parent:
- 5:f54759b26096
- Child:
- 7:e57b18779bf1
remembers the last best target when there are no current targets
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 | 4:440e747935db | 5 | #define CENTER_X 320 |
sandwich | 6:4bf8d39fc5ce | 6 | #define CENTER_Y 100 |
sandwich | 5:f54759b26096 | 7 | #define NUM_BLOCKS 10 |
sandwich | 0:1b99a0bee9e0 | 8 | //a class to aid in SPI communication with the pixy camera |
sandwich | 0:1b99a0bee9e0 | 9 | |
sandwich | 0:1b99a0bee9e0 | 10 | //this details the object block format of returned data as described in |
sandwich | 0:1b99a0bee9e0 | 11 | //http://www.cmucam.org/projects/cmucam5/wiki/Pixy_Serial_Protocol |
sandwich | 0:1b99a0bee9e0 | 12 | |
sandwich | 0:1b99a0bee9e0 | 13 | //blatantly stole this from their code |
sandwich | 0:1b99a0bee9e0 | 14 | struct Block |
sandwich | 0:1b99a0bee9e0 | 15 | { |
sandwich | 0:1b99a0bee9e0 | 16 | uint16_t signature; |
sandwich | 0:1b99a0bee9e0 | 17 | uint16_t x; |
sandwich | 0:1b99a0bee9e0 | 18 | uint16_t y; |
sandwich | 0:1b99a0bee9e0 | 19 | uint16_t width; |
sandwich | 0:1b99a0bee9e0 | 20 | uint16_t height; |
sandwich | 0:1b99a0bee9e0 | 21 | }; |
sandwich | 0:1b99a0bee9e0 | 22 | |
sandwich | 0:1b99a0bee9e0 | 23 | class pixySPI |
sandwich | 0:1b99a0bee9e0 | 24 | { |
sandwich | 0:1b99a0bee9e0 | 25 | private: |
sandwich | 5:f54759b26096 | 26 | SPI spi; |
sandwich | 0:1b99a0bee9e0 | 27 | //SPI spi(p5, p6, p7); // mosi, miso, sclk |
sandwich | 0:1b99a0bee9e0 | 28 | short sync; //the block signature. 16 bits |
sandwich | 0:1b99a0bee9e0 | 29 | short readTwoBytesLSB(); |
sandwich | 0:1b99a0bee9e0 | 30 | void readNBytes(char* buf, int num); |
sandwich | 5:f54759b26096 | 31 | Block blocks[NUM_BLOCKS]; //where the blocks are stored |
sandwich | 2:fc86438b206f | 32 | int numBlocks; //amt |
sandwich | 5:f54759b26096 | 33 | int bestX; |
sandwich | 5:f54759b26096 | 34 | int bestY; |
sandwich | 0:1b99a0bee9e0 | 35 | public: |
sandwich | 5:f54759b26096 | 36 | pixySPI(PinName mosi,PinName miso,PinName sclk, int nBlocks); |
sandwich | 0:1b99a0bee9e0 | 37 | ~pixySPI(); |
sandwich | 2:fc86438b206f | 38 | void capture(); //fills in the blocks pointer |
sandwich | 0:1b99a0bee9e0 | 39 | char getRawData(); |
sandwich | 2:fc86438b206f | 40 | Block* getBlocks(); |
sandwich | 2:fc86438b206f | 41 | int getNumBlocks(); |
sandwich | 5:f54759b26096 | 42 | int getBestX(); |
sandwich | 5:f54759b26096 | 43 | int getBestY(); |
sandwich | 0:1b99a0bee9e0 | 44 | }; |