an SPI interface the cmu pixy camera
Dependents: robotic_fish_ver_4_9_pixy UMO
Diff: pixy.cpp
- Revision:
- 8:a915c5eff55a
- Parent:
- 7:e57b18779bf1
- Child:
- 9:89b9d1a6457c
--- a/pixy.cpp Fri Jun 06 16:18:49 2014 +0000 +++ b/pixy.cpp Fri Jun 06 19:47:27 2014 +0000 @@ -37,7 +37,7 @@ } } -void pixySPI::capture(Mutex* mutex) +void pixySPI::capture() { memset(blocks, 0, numBlocks*sizeof(Block)); //destroy the old targets for (int i=0; i<numBlocks; ++i) { @@ -48,10 +48,18 @@ //first we need to detect the start of a block. They all start with 0xAA55 char frame[2]= {0,0}; //this is a 2 byte running frame of what is being recieved. It's like a first-in-last-out queue //debug->printf("looking for valid signature\n"); + Timer t; + t.start(); while (memcmp((char*)&sync, frame, 2)!=0) { frame[0]=frame[1]; //move byte down frame[1]=spi.write(0x00); //get next byte. + if (t.read_ms()>5) + { + t.stop(); + return; + } } + //printf("target\n\n"); spi.write(0x00); //ok so we got a valid signature //these didn't end up working @@ -71,10 +79,10 @@ //printf("found block\n"); if (blocks[0].signature!=INVALID_BLOCK) { - mutex->lock(); + //mutex->lock(); bestX=blocks[0].x; bestY=blocks[0].y; - mutex->unlock(); + //mutex->unlock(); } } return;