an SPI interface the cmu pixy camera

Dependents:   robotic_fish_ver_4_9_pixy UMO

Committer:
sandwich
Date:
Tue Jun 03 15:29:26 2014 +0000
Revision:
4:440e747935db
Parent:
2:fc86438b206f
Child:
5:f54759b26096
defined center image coordinates

Who changed what in which revision?

UserRevisionLine numberNew 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 4:440e747935db 6 #define CENTER_Y 200
sandwich 0:1b99a0bee9e0 7 //a class to aid in SPI communication with the pixy camera
sandwich 0:1b99a0bee9e0 8
sandwich 0:1b99a0bee9e0 9 //this details the object block format of returned data as described in
sandwich 0:1b99a0bee9e0 10 //http://www.cmucam.org/projects/cmucam5/wiki/Pixy_Serial_Protocol
sandwich 0:1b99a0bee9e0 11
sandwich 0:1b99a0bee9e0 12 //blatantly stole this from their code
sandwich 0:1b99a0bee9e0 13 struct Block
sandwich 0:1b99a0bee9e0 14 {
sandwich 0:1b99a0bee9e0 15 uint16_t signature;
sandwich 0:1b99a0bee9e0 16 uint16_t x;
sandwich 0:1b99a0bee9e0 17 uint16_t y;
sandwich 0:1b99a0bee9e0 18 uint16_t width;
sandwich 0:1b99a0bee9e0 19 uint16_t height;
sandwich 0:1b99a0bee9e0 20 };
sandwich 0:1b99a0bee9e0 21
sandwich 0:1b99a0bee9e0 22 class pixySPI
sandwich 0:1b99a0bee9e0 23 {
sandwich 0:1b99a0bee9e0 24 private:
sandwich 0:1b99a0bee9e0 25 SPI* spi;
sandwich 0:1b99a0bee9e0 26 Serial* debug;
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 2:fc86438b206f 31 Block* blocks; //where the blocks are stored
sandwich 2:fc86438b206f 32 int numBlocks; //amt
sandwich 0:1b99a0bee9e0 33 public:
sandwich 2:fc86438b206f 34 pixySPI(PinName mosi,PinName miso,PinName sclk, int nBlocks, Serial* ser);
sandwich 0:1b99a0bee9e0 35 ~pixySPI();
sandwich 2:fc86438b206f 36 void capture(); //fills in the blocks pointer
sandwich 0:1b99a0bee9e0 37 char getRawData();
sandwich 2:fc86438b206f 38 Block* getBlocks();
sandwich 2:fc86438b206f 39 int getNumBlocks();
sandwich 0:1b99a0bee9e0 40 };