an SPI interface the cmu pixy camera

Dependents:   robotic_fish_ver_4_9_pixy UMO

pixy.h

Committer:
sandwich
Date:
2014-06-02
Revision:
0:1b99a0bee9e0
Child:
1:439c7574a5ee

File content as of revision 0:1b99a0bee9e0:

#pragma once
#include "mbed.h"

//a class to aid in SPI communication with the pixy camera

//this details the object block format of returned data as described in
//http://www.cmucam.org/projects/cmucam5/wiki/Pixy_Serial_Protocol

struct objectBlock {
    short sync; //spi sync data
    short checksum; //the sum of everything BELOW this
    short signature; //signature number of detection
    short xcenter; //x center pixrl position of block
    short ycenter; //y center pixel position of block
    short width; //width of detection in pixels
    short height; //height of detection in pixels
};

//blatantly stole this from their code
struct Block 
{
  uint16_t signature;
  uint16_t x;
  uint16_t y;
  uint16_t width;
  uint16_t height;
};

class pixySPI
{
private:
    SPI* spi;
    Serial* debug;
    //SPI spi(p5, p6, p7); // mosi, miso, sclk
    short sync; //the block signature. 16 bits
    short readTwoBytesLSB();
    void readNBytes(char* buf, int num);
public:
    pixySPI(PinName mosi,PinName miso,PinName sclk, Serial* ser);
    ~pixySPI();
    Block getBlock(Serial* debug);
    char getRawData();
};