Library for LinkSprite Y201 JPEG serial camera.
Diff: Y201.cpp
- Revision:
- 5:df71c00b97d8
- Parent:
- 4:6e575c19681f
- Child:
- 7:d7ed03291f0a
- Child:
- 9:fbd80a803857
--- a/Y201.cpp Tue Jul 17 16:35:35 2012 +0000
+++ b/Y201.cpp Wed Jul 18 11:06:49 2012 +0000
@@ -20,15 +20,27 @@
putc(0x0A); // Interval LSB
int nread = 0;
if(waitFor(readFileAck,readFileAckLen)) {
- Thread::wait(1);
+ //Thread::wait(1);
+ Timer t;
+ t.start();
while(nread<readLen) {
if(readable()) {
uint8_t c = getc();
+ // fprintf(stdout, "[%02x]", c);
readBuffer[nread] = c;
nread++;
+ t.reset();
+ }
+ else
+ {
+ if(t.read_ms()>3000)
+ {
+ fprintf(stdout, "Blocked!\n Missed %d bytes over %d\nLast byte read is %02x\n", readLen - nread, readLen, readBuffer[nread-1]);
+ return false;
+ }
}
}
- Thread::wait(1);
+ //Thread::wait(1);
} else {
return false;
}
@@ -37,8 +49,9 @@
bool Y201::waitFor(const int *seq, const int seqLen) {
int spos = 0;
- long timeout = 100000000;
- long timer = 0;
+ long timeout = 100;
+ Timer timer;
+ timer.start();
while(spos<seqLen) {
if(readable()) {
int c = getc();
@@ -48,9 +61,7 @@
return false;
}
} else {
- if(timer<timeout) {
- timer++;
- } else {
+ if(timer.read_ms()>timeout) {
return false;
}
}
@@ -60,8 +71,9 @@
bool Y201::waitForInt(int bytes, int *fileSize) {
int spos = 0;
- long timeout = 1000000000;
- long timer = 0;
+ long timeout = 100;
+ Timer timer;
+ timer.start();
*fileSize = 0;
while(spos<bytes) {
if(readable()) {
@@ -75,9 +87,7 @@
spos++;
} else {
- if(timer<timeout) {
- timer++;
- } else {
+ if(timer.read_ms()>timeout) {
return false;
}
}



