![](/media/cache/profiles/altb_JGUSAOG.jpg.50x50_q85.jpg)
SPI read Pixi Cam V1
Diff: TPixy.h
- Revision:
- 4:478d4d9193a1
- Parent:
- 3:66df7d295245
--- a/TPixy.h Mon Mar 14 18:53:43 2016 +0000 +++ b/TPixy.h Mon Aug 23 11:26:37 2021 +0000 @@ -71,7 +71,7 @@ template <class TPixyInterface> class TPixy { public: - Serial* serial; + BufferedSerial* serial; Block *blocks; /** Creates a TPixy object with a given connection handler @@ -79,7 +79,7 @@ * @param serialOut the optional serial output pointer to print out Pixy camera data * @param arg an optional integer argument used for custom implementations of the Pixy library */ - TPixy(TPixyInterface* type, Serial* serialOut = NULL, uint16_t arg = PIXY_DEFAULT_ARGVAL); + TPixy(TPixyInterface* type, BufferedSerial* serialOut = NULL, uint16_t arg = PIXY_DEFAULT_ARGVAL); ~TPixy(); /** Prints the given Block out to the given serial port @@ -132,7 +132,7 @@ } -template <class TPixyInterface> TPixy<TPixyInterface>::TPixy(TPixyInterface* type, Serial* serialOut, uint16_t arg) : serial(serialOut), link(type) +template <class TPixyInterface> TPixy<TPixyInterface>::TPixy(TPixyInterface* type, BufferedSerial* serialOut, uint16_t arg) : serial(serialOut), link(type) { skipStart = false; blockCount = 0; @@ -158,11 +158,11 @@ } } sig[j] = '\0'; - if (serial != NULL) { - serial->printf("CC block! sig: %s (%d decimal) x: %d y: %d width: %d height: %d angle %d\n", sig, block.signature, block.x, block.y, block.width, block.height, block.angle); + { + printf("CC block! sig: %s (%d decimal) x: %d y: %d width: %d height: %d angle %d\n", sig, block.signature, block.x, block.y, block.width, block.height, block.angle); } - } else {}// regular block. Note, angle is always zero, so no need to print - serial->printf("sig: %d x: %d y: %d width: %d height: %d\n", block.signature, block.x, block.y, block.width, block.height); + } //else {}// regular block. Note, angle is always zero, so no need to print + printf("sig: %d x: %d y: %d width: %d height: %d\n", block.signature, block.x, block.y, block.width, block.height); } template <class TPixyInterface> TPixy<TPixyInterface>::~TPixy() @@ -177,7 +177,7 @@ while(true) { w = link->getWord(); if (w == 0 && lastw == 0) { - wait_ms(10); + ThisThread::sleep_for(10); return false; } else if (w == PIXY_START_WORD && lastw == PIXY_START_WORD) { blockType = NORMAL_BLOCK; @@ -187,7 +187,7 @@ return true; } else if (w == PIXY_START_WORDX) { if (serial != NULL) { - serial->printf("reorder"); + printf("reorder"); } link->getByte(); // resync } @@ -209,25 +209,30 @@ if (!skipStart) { if (getStart() == false) { + printf("- 0 -\r\n"); return 0; } } else { skipStart = false; } - for(blockCount = 0; blockCount < maxBlocks && blockCount < PIXY_MAXIMUM_ARRAYSIZE;) { + for(blockCount = 0; blockCount < maxBlocks && blockCount < PIXY_MAXIMUM_ARRAYSIZE;) + { checksum = link->getWord(); if (checksum == PIXY_START_WORD) { // we've reached the beginning of the next frame skipStart = true; blockType = NORMAL_BLOCK; - if (serial != NULL) { - serial->printf("skip"); + if(1) { + printf("skip"); } + printf("- 1 -\r\n"); return blockCount; } else if (checksum == PIXY_START_WORD_CC) { skipStart = true; blockType = CC_BLOCK; + printf("- 2 -\r\n"); return blockCount; } else if (checksum == 0) { + printf("- 3 -\r\n"); return blockCount; } if (blockCount > blockArraySize) { @@ -250,7 +255,7 @@ } else { w = link->getWord(); if (serial != NULL) { - serial->printf("cs error"); + printf("cs error"); } } if (w == PIXY_START_WORD) { @@ -258,9 +263,11 @@ } else if (w == PIXY_START_WORD_CC) { blockType = CC_BLOCK; } else { + printf("- 4 -\r\n"); return blockCount; } } + printf("- 5 -\r\n"); return blockCount; }