An input/output controller for virtual pinball machines, with plunger position tracking, accelerometer-based nudge sensing, button input encoding, and feedback device control.
Dependencies: USBDevice mbed FastAnalogIn FastIO FastPWM SimpleDMA
tsl410r.cpp
00001 #if 0 00002 // this file is no longer used - the method bodies are no in the header, 00003 // which was necessary because of the change to a template class, which 00004 // itself was necessary because of the use of the FastIO library 00005 00006 #include "mbed.h" 00007 #include "tsl1410r.h" 00008 00009 template <PinName siPin, PinName clockPin> TSL1410R<siPin, clockPin>:: 00010 TSL1410R<siPin, clockPin>(PinName aoPort) : ao(aoPort) 00011 { 00012 // clear out power-on noise by clocking through all pixels twice 00013 clear(); 00014 clear(); 00015 } 00016 00017 template <PinName siPin, PinName clockPin> void TSL1410R<siPin, clockPin>::clear() 00018 { 00019 // clock in an SI pulse 00020 si = 1; 00021 clock = 1; 00022 clock = 0; 00023 si = 0; 00024 00025 // clock out all pixels 00026 for (int i = 0 ; i < nPix + 1 ; ++i) { 00027 clock = 1; 00028 clock = 0; 00029 } 00030 } 00031 00032 template <PinName siPin, PinName clockPin> void TSL1410R<siPin, clockPin>:: 00033 read(uint16_t *pix, int n, void (*cb)(void *ctx), void *cbctx, int cbcnt) 00034 { 00035 // start the next integration cycle by pulsing SI and one clock 00036 si = 1; 00037 clock = 1; 00038 clock = 0; 00039 si = 0; 00040 00041 // figure how many pixels to skip on each read 00042 int skip = nPix/n - 1; 00043 00044 // figure the callback interval 00045 int cbInterval = nPix; 00046 if (cb != 0) 00047 cbInterval = nPix/(cbcnt+1); 00048 00049 // read all of the pixels 00050 for (int src = 0, dst = 0 ; src < nPix ; ) 00051 { 00052 // figure the end of this callback interval 00053 int srcEnd = src + cbInterval; 00054 if (srcEnd > nPix) 00055 srcEnd = nPix; 00056 00057 // read one callback chunk of pixels 00058 for ( ; src < srcEnd ; ++src) 00059 { 00060 // read this pixel 00061 pix[dst++] = ao.read_u16(); 00062 00063 // clock in the next pixel 00064 clock = 1; 00065 clock = 0; 00066 00067 // clock skipped pixels 00068 for (int i = 0 ; i < skip ; ++i, ++src) 00069 { 00070 clock = 1; 00071 clock = 0; 00072 } 00073 } 00074 00075 // call the callback, if we're not at the last pixel 00076 if (cb != 0 && src < nPix) 00077 (*cb)(cbctx); 00078 } 00079 00080 // clock out one extra pixel to leave A1 in the high-Z state 00081 clock = 1; 00082 clock = 0; 00083 } 00084 00085 #endif /* 0 */
Generated on Fri Jul 15 2022 08:43:32 by 1.7.2