an SPI interface the cmu pixy camera
Dependents: robotic_fish_ver_4_9_pixy UMO
pixy.h@0:1b99a0bee9e0, 2014-06-02 (annotated)
- Committer:
- sandwich
- Date:
- Mon Jun 02 21:02:09 2014 +0000
- Revision:
- 0:1b99a0bee9e0
- Child:
- 1:439c7574a5ee
tracks a single object currently
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 | 0:1b99a0bee9e0 | 4 | //a class to aid in SPI communication with the pixy camera |
sandwich | 0:1b99a0bee9e0 | 5 | |
sandwich | 0:1b99a0bee9e0 | 6 | //this details the object block format of returned data as described in |
sandwich | 0:1b99a0bee9e0 | 7 | //http://www.cmucam.org/projects/cmucam5/wiki/Pixy_Serial_Protocol |
sandwich | 0:1b99a0bee9e0 | 8 | |
sandwich | 0:1b99a0bee9e0 | 9 | struct objectBlock { |
sandwich | 0:1b99a0bee9e0 | 10 | short sync; //spi sync data |
sandwich | 0:1b99a0bee9e0 | 11 | short checksum; //the sum of everything BELOW this |
sandwich | 0:1b99a0bee9e0 | 12 | short signature; //signature number of detection |
sandwich | 0:1b99a0bee9e0 | 13 | short xcenter; //x center pixrl position of block |
sandwich | 0:1b99a0bee9e0 | 14 | short ycenter; //y center pixel position of block |
sandwich | 0:1b99a0bee9e0 | 15 | short width; //width of detection in pixels |
sandwich | 0:1b99a0bee9e0 | 16 | short height; //height of detection in pixels |
sandwich | 0:1b99a0bee9e0 | 17 | }; |
sandwich | 0:1b99a0bee9e0 | 18 | |
sandwich | 0:1b99a0bee9e0 | 19 | //blatantly stole this from their code |
sandwich | 0:1b99a0bee9e0 | 20 | struct Block |
sandwich | 0:1b99a0bee9e0 | 21 | { |
sandwich | 0:1b99a0bee9e0 | 22 | uint16_t signature; |
sandwich | 0:1b99a0bee9e0 | 23 | uint16_t x; |
sandwich | 0:1b99a0bee9e0 | 24 | uint16_t y; |
sandwich | 0:1b99a0bee9e0 | 25 | uint16_t width; |
sandwich | 0:1b99a0bee9e0 | 26 | uint16_t height; |
sandwich | 0:1b99a0bee9e0 | 27 | }; |
sandwich | 0:1b99a0bee9e0 | 28 | |
sandwich | 0:1b99a0bee9e0 | 29 | class pixySPI |
sandwich | 0:1b99a0bee9e0 | 30 | { |
sandwich | 0:1b99a0bee9e0 | 31 | private: |
sandwich | 0:1b99a0bee9e0 | 32 | SPI* spi; |
sandwich | 0:1b99a0bee9e0 | 33 | Serial* debug; |
sandwich | 0:1b99a0bee9e0 | 34 | //SPI spi(p5, p6, p7); // mosi, miso, sclk |
sandwich | 0:1b99a0bee9e0 | 35 | short sync; //the block signature. 16 bits |
sandwich | 0:1b99a0bee9e0 | 36 | short readTwoBytesLSB(); |
sandwich | 0:1b99a0bee9e0 | 37 | void readNBytes(char* buf, int num); |
sandwich | 0:1b99a0bee9e0 | 38 | public: |
sandwich | 0:1b99a0bee9e0 | 39 | pixySPI(PinName mosi,PinName miso,PinName sclk, Serial* ser); |
sandwich | 0:1b99a0bee9e0 | 40 | ~pixySPI(); |
sandwich | 0:1b99a0bee9e0 | 41 | Block getBlock(Serial* debug); |
sandwich | 0:1b99a0bee9e0 | 42 | char getRawData(); |
sandwich | 0:1b99a0bee9e0 | 43 | }; |