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: FatFileSystem mbed
ZMotionDetector.cpp@3:0ac64c4ca40f, 2012-01-17 (annotated)
- Committer:
- isonno
- Date:
- Tue Jan 17 13:45:17 2012 +0000
- Revision:
- 3:0ac64c4ca40f
- Parent:
- 0:6da5625a6946
LightSensor settings menu; more work (unsuccessful) on serial input from USB.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| isonno |
0:6da5625a6946 | 1 | // Motion detector support for the Zilog ePIR Motion Detection ZDots SBC |
| isonno |
0:6da5625a6946 | 2 | |
| isonno |
0:6da5625a6946 | 3 | #include "mbed.h" |
| isonno |
0:6da5625a6946 | 4 | #include "ZMotionDetector.h" |
| isonno |
0:6da5625a6946 | 5 | #include "HoldInterrupts.h" |
| isonno |
0:6da5625a6946 | 6 | |
| isonno |
0:6da5625a6946 | 7 | //const char NACK = 0x15; |
| isonno |
0:6da5625a6946 | 8 | const char ACK = 0x06; |
| isonno |
0:6da5625a6946 | 9 | |
| isonno |
0:6da5625a6946 | 10 | ZMotionDetector::ZMotionDetector( PinName ztx, PinName zrx ) |
| isonno |
0:6da5625a6946 | 11 | : fMDPort( ztx, zrx ) |
| isonno |
0:6da5625a6946 | 12 | {} |
| isonno |
0:6da5625a6946 | 13 | |
| isonno |
0:6da5625a6946 | 14 | bool |
| isonno |
0:6da5625a6946 | 15 | ZMotionDetector::IsMotionDetected() |
| isonno |
0:6da5625a6946 | 16 | { |
| isonno |
3:0ac64c4ca40f | 17 | // HoldInterrupts noir; |
| isonno |
0:6da5625a6946 | 18 | |
| isonno |
0:6da5625a6946 | 19 | fMDPort.putc('a'); // Read Motion status |
| isonno |
0:6da5625a6946 | 20 | return fMDPort.getc() == 'Y'; |
| isonno |
0:6da5625a6946 | 21 | } |
| isonno |
0:6da5625a6946 | 22 | |
| isonno |
0:6da5625a6946 | 23 | void |
| isonno |
0:6da5625a6946 | 24 | ZMotionDetector::SetExtendedRange( bool on ) |
| isonno |
0:6da5625a6946 | 25 | { |
| isonno |
0:6da5625a6946 | 26 | HoldInterrupts noir; |
| isonno |
0:6da5625a6946 | 27 | |
| isonno |
0:6da5625a6946 | 28 | fMDPort.putc('E'); |
| isonno |
0:6da5625a6946 | 29 | fMDPort.getc(); // Current value |
| isonno |
0:6da5625a6946 | 30 | fMDPort.putc( on ? 'Y' : 'N' ); |
| isonno |
0:6da5625a6946 | 31 | if (fMDPort.getc() != ACK) |
| isonno |
0:6da5625a6946 | 32 | printf("Error setting extended motion detector range\r\n"); |
| isonno |
0:6da5625a6946 | 33 | } |
| isonno |
0:6da5625a6946 | 34 | |
| isonno |
0:6da5625a6946 | 35 | void |
| isonno |
0:6da5625a6946 | 36 | ZMotionDetector::SetAsyncMode( bool on ) |
| isonno |
0:6da5625a6946 | 37 | { |
| isonno |
0:6da5625a6946 | 38 | HoldInterrupts noir; |
| isonno |
0:6da5625a6946 | 39 | |
| isonno |
0:6da5625a6946 | 40 | if (! on) |
| isonno |
0:6da5625a6946 | 41 | fMDPort.attach( NULL ); |
| isonno |
0:6da5625a6946 | 42 | fMDPort.putc('M'); |
| isonno |
0:6da5625a6946 | 43 | fMDPort.getc(); // Gets the current mode setting) |
| isonno |
0:6da5625a6946 | 44 | fMDPort.putc( on ? 'Y' : 'N' ); |
| isonno |
0:6da5625a6946 | 45 | if (fMDPort.getc() != ACK) |
| isonno |
0:6da5625a6946 | 46 | printf("Error setting motion detector async mode\r\n"); |
| isonno |
0:6da5625a6946 | 47 | else |
| isonno |
0:6da5625a6946 | 48 | if (on) |
| isonno |
0:6da5625a6946 | 49 | fMDPort.attach( this, &ZMotionDetector::Motion ); |
| isonno |
0:6da5625a6946 | 50 | } |
| isonno |
0:6da5625a6946 | 51 | |
| isonno |
0:6da5625a6946 | 52 | void |
| isonno |
0:6da5625a6946 | 53 | ZMotionDetector::Motion() |
| isonno |
0:6da5625a6946 | 54 | { |
| isonno |
0:6da5625a6946 | 55 | printf("Motion!!\r\n"); |
| isonno |
0:6da5625a6946 | 56 | } |