JEK changes enabling proper recording of IMU/GPS datastrams - 02-APR-2013
Fork of GPS_Incremental by
MODSERIAL/example3a.cpp@9:b45feb91ba38, 2013-04-19 (annotated)
- Committer:
- jekain314
- Date:
- Fri Apr 19 16:21:27 2013 +0000
- Revision:
- 9:b45feb91ba38
- Parent:
- 0:c746ee34feae
update to allow better imu gps data collection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dannyman939 | 0:c746ee34feae | 1 | /* |
dannyman939 | 0:c746ee34feae | 2 | Copyright (c) 2011 Andy Kirkham |
dannyman939 | 0:c746ee34feae | 3 | |
dannyman939 | 0:c746ee34feae | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
dannyman939 | 0:c746ee34feae | 5 | of this software and associated documentation files (the "Software"), to deal |
dannyman939 | 0:c746ee34feae | 6 | in the Software without restriction, including without limitation the rights |
dannyman939 | 0:c746ee34feae | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
dannyman939 | 0:c746ee34feae | 8 | copies of the Software, and to permit persons to whom the Software is |
dannyman939 | 0:c746ee34feae | 9 | furnished to do so, subject to the following conditions: |
dannyman939 | 0:c746ee34feae | 10 | |
dannyman939 | 0:c746ee34feae | 11 | The above copyright notice and this permission notice shall be included in |
dannyman939 | 0:c746ee34feae | 12 | all copies or substantial portions of the Software. |
dannyman939 | 0:c746ee34feae | 13 | |
dannyman939 | 0:c746ee34feae | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dannyman939 | 0:c746ee34feae | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dannyman939 | 0:c746ee34feae | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dannyman939 | 0:c746ee34feae | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dannyman939 | 0:c746ee34feae | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dannyman939 | 0:c746ee34feae | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dannyman939 | 0:c746ee34feae | 20 | THE SOFTWARE. |
dannyman939 | 0:c746ee34feae | 21 | |
dannyman939 | 0:c746ee34feae | 22 | @file example3.cpp |
dannyman939 | 0:c746ee34feae | 23 | @purpose Demos a simple filter. |
dannyman939 | 0:c746ee34feae | 24 | @version see ChangeLog.c |
dannyman939 | 0:c746ee34feae | 25 | @author Andy Kirkham |
dannyman939 | 0:c746ee34feae | 26 | */ |
dannyman939 | 0:c746ee34feae | 27 | |
dannyman939 | 0:c746ee34feae | 28 | /* |
dannyman939 | 0:c746ee34feae | 29 | This example shows how to use the new callback system. In the old system |
dannyman939 | 0:c746ee34feae | 30 | Mbed's FunctionPointer[1] type was used to store abd make calls to callbacks. |
dannyman939 | 0:c746ee34feae | 31 | However, that limits the callback function prototype to void func(void); |
dannyman939 | 0:c746ee34feae | 32 | which means we cannot pass parameters. |
dannyman939 | 0:c746ee34feae | 33 | |
dannyman939 | 0:c746ee34feae | 34 | This latest version of MODSERIAL now uses its own callback object. This allows |
dannyman939 | 0:c746ee34feae | 35 | the passing of a pointer to a class that holds information about the MODSERIAL |
dannyman939 | 0:c746ee34feae | 36 | object making the callback. As of version 1.18 one critcal piece of information |
dannyman939 | 0:c746ee34feae | 37 | is passed, a pointer to the MODSERIAL object. This allows callbacks to use the |
dannyman939 | 0:c746ee34feae | 38 | MODSERIAL functions and data. |
dannyman939 | 0:c746ee34feae | 39 | |
dannyman939 | 0:c746ee34feae | 40 | Additionally, since MODSERIAL and the callback parameter class MODSERIAL_IRQ_INFO |
dannyman939 | 0:c746ee34feae | 41 | are friends, MODSERIAL_IRQ_INFO can access the protected functions of MODSERIAL. |
dannyman939 | 0:c746ee34feae | 42 | This is used to ensure functions that can only be called during a callback |
dannyman939 | 0:c746ee34feae | 43 | can be invoked from a callback. |
dannyman939 | 0:c746ee34feae | 44 | |
dannyman939 | 0:c746ee34feae | 45 | [1] http://mbed.org/projects/libraries/svn/mbed/trunk/FunctionPointer.h |
dannyman939 | 0:c746ee34feae | 46 | */ |
dannyman939 | 0:c746ee34feae | 47 | |
dannyman939 | 0:c746ee34feae | 48 | #ifdef COMPILE_EXAMPLE3_CODE_MODSERIAL |
dannyman939 | 0:c746ee34feae | 49 | |
dannyman939 | 0:c746ee34feae | 50 | #include "mbed.h" |
dannyman939 | 0:c746ee34feae | 51 | #include "MODSERIAL.h" |
dannyman939 | 0:c746ee34feae | 52 | |
dannyman939 | 0:c746ee34feae | 53 | DigitalOut led1(LED1); |
dannyman939 | 0:c746ee34feae | 54 | |
dannyman939 | 0:c746ee34feae | 55 | MODSERIAL pc(USBTX, USBRX); |
dannyman939 | 0:c746ee34feae | 56 | |
dannyman939 | 0:c746ee34feae | 57 | // The following callback is defined in example3b.cpp |
dannyman939 | 0:c746ee34feae | 58 | //! @see example3b.cpp |
dannyman939 | 0:c746ee34feae | 59 | void rxCallback(MODSERIAL_IRQ_INFO *info); |
dannyman939 | 0:c746ee34feae | 60 | |
dannyman939 | 0:c746ee34feae | 61 | int main() { |
dannyman939 | 0:c746ee34feae | 62 | |
dannyman939 | 0:c746ee34feae | 63 | int life_counter = 0; |
dannyman939 | 0:c746ee34feae | 64 | |
dannyman939 | 0:c746ee34feae | 65 | pc.baud(115200); |
dannyman939 | 0:c746ee34feae | 66 | |
dannyman939 | 0:c746ee34feae | 67 | pc.attach(&rxCallback, MODSERIAL::RxIrq); |
dannyman939 | 0:c746ee34feae | 68 | |
dannyman939 | 0:c746ee34feae | 69 | while(1) { |
dannyman939 | 0:c746ee34feae | 70 | // Echo back any chars we get except 'A' which is filtered by the rxCallback. |
dannyman939 | 0:c746ee34feae | 71 | if (pc.readable()) { |
dannyman939 | 0:c746ee34feae | 72 | pc.putc(pc.getc()); |
dannyman939 | 0:c746ee34feae | 73 | } |
dannyman939 | 0:c746ee34feae | 74 | |
dannyman939 | 0:c746ee34feae | 75 | // Toggle LED1 every so often to show we are alive. |
dannyman939 | 0:c746ee34feae | 76 | if (life_counter++ == 1000000) { |
dannyman939 | 0:c746ee34feae | 77 | life_counter = 0; |
dannyman939 | 0:c746ee34feae | 78 | led1 = !led1; |
dannyman939 | 0:c746ee34feae | 79 | } |
dannyman939 | 0:c746ee34feae | 80 | } |
dannyman939 | 0:c746ee34feae | 81 | } |
dannyman939 | 0:c746ee34feae | 82 | |
dannyman939 | 0:c746ee34feae | 83 | #endif |