Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: USBDevice mbed FastAnalogIn FastIO FastPWM SimpleDMA
Diff: TSL1410R/tsl410r.cpp
- Revision:
- 14:df700b22ca08
- Parent:
- 6:cc35eb643e8f
- Child:
- 17:ab3cec0c8bf4
--- a/TSL1410R/tsl410r.cpp Sat Sep 13 23:47:32 2014 +0000
+++ b/TSL1410R/tsl410r.cpp Fri Sep 26 20:51:02 2014 +0000
@@ -24,7 +24,7 @@
}
}
-void TSL1410R::read(uint16_t *pix, int n)
+void TSL1410R::read(uint16_t *pix, int n, void (*cb)(void *ctx), void *cbctx, int cbcnt)
{
// start the next integration cycle by pulsing SI and one clock
si = 1;
@@ -34,22 +34,41 @@
// figure how many pixels to skip on each read
int skip = nPix/n - 1;
+
+ // figure the callback interval
+ int cbInterval = nPix;
+ if (cb != 0)
+ cbInterval = nPix/(cbcnt+1);
- // read the pixels
- for (int src = 0, dst = 0 ; src < nPix ; ++src)
+ // read all of the pixels
+ for (int src = 0, dst = 0 ; src < nPix ; )
{
- // read this pixel
- pix[dst++] = ao.read_u16();
+ // figure the end of this callback interval
+ int srcEnd = src + cbInterval;
+ if (srcEnd > nPix)
+ srcEnd = nPix;
- // clock in the next pixel
- clock = 1;
- clock = 0;
+ // read one callback chunk of pixels
+ for ( ; src < srcEnd ; ++src)
+ {
+ // read this pixel
+ pix[dst++] = ao.read_u16();
- // clock skipped pixels
- for (int i = 0 ; i < skip ; ++i, ++src) {
+ // clock in the next pixel
clock = 1;
clock = 0;
+
+ // clock skipped pixels
+ for (int i = 0 ; i < skip ; ++i, ++src)
+ {
+ clock = 1;
+ clock = 0;
+ }
}
+
+ // call the callback, if we're not at the last pixel
+ if (cb != 0 && src < nPix)
+ (*cb)(cbctx);
}
// clock out one extra pixel to leave A1 in the high-Z state