Only imu output

Dependencies:   Servo mbed

Fork of FYDP_Final2 by Mark Vandermeulen

Committer:
tntmarket
Date:
Wed Mar 25 09:58:50 2015 +0000
Revision:
5:d2e955a94940
Parent:
0:21019d94ad33
only imu output

Who changed what in which revision?

UserRevisionLine numberNew contents of line
majik 0:21019d94ad33 1 /*
majik 0:21019d94ad33 2 Copyright (c) 2011 Andy Kirkham
majik 0:21019d94ad33 3
majik 0:21019d94ad33 4 Permission is hereby granted, free of charge, to any person obtaining a copy
majik 0:21019d94ad33 5 of this software and associated documentation files (the "Software"), to deal
majik 0:21019d94ad33 6 in the Software without restriction, including without limitation the rights
majik 0:21019d94ad33 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
majik 0:21019d94ad33 8 copies of the Software, and to permit persons to whom the Software is
majik 0:21019d94ad33 9 furnished to do so, subject to the following conditions:
majik 0:21019d94ad33 10
majik 0:21019d94ad33 11 The above copyright notice and this permission notice shall be included in
majik 0:21019d94ad33 12 all copies or substantial portions of the Software.
majik 0:21019d94ad33 13
majik 0:21019d94ad33 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
majik 0:21019d94ad33 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
majik 0:21019d94ad33 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
majik 0:21019d94ad33 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
majik 0:21019d94ad33 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
majik 0:21019d94ad33 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
majik 0:21019d94ad33 20 THE SOFTWARE.
majik 0:21019d94ad33 21
majik 0:21019d94ad33 22 @file example3b.cpp
majik 0:21019d94ad33 23 @purpose Demos a simple filter.
majik 0:21019d94ad33 24 @version see ChangeLog.c
majik 0:21019d94ad33 25 @author Andy Kirkham
majik 0:21019d94ad33 26 */
majik 0:21019d94ad33 27
majik 0:21019d94ad33 28 /*
majik 0:21019d94ad33 29 This example shows how to use the new callback system. In the old system
majik 0:21019d94ad33 30 Mbed's FunctionPointer[1] type was used to store abd make calls to callbacks.
majik 0:21019d94ad33 31 However, that limits the callback function prototype to void func(void);
majik 0:21019d94ad33 32 which means we cannot pass parameters.
majik 0:21019d94ad33 33
majik 0:21019d94ad33 34 This latest version of MODSERIAL now uses its own callback object. This allows
majik 0:21019d94ad33 35 the passing of a pointer to a class that holds information about the MODSERIAL
majik 0:21019d94ad33 36 object making the callback. As of version 1.18 one critcal piece of information
majik 0:21019d94ad33 37 is passed, a pointer to the MODSERIAL object. This allows callbacks to use the
majik 0:21019d94ad33 38 MODSERIAL functions and data.
majik 0:21019d94ad33 39
majik 0:21019d94ad33 40 Additionally, since MODSERIAL and the callback parameter class MODSERIAL_IRQ_INFO
majik 0:21019d94ad33 41 are friends, MODSERIAL_IRQ_INFO can access the protected functions of MODSERIAL.
majik 0:21019d94ad33 42 This is used to ensure functions that can only be called during a callback
majik 0:21019d94ad33 43 can be invoked from a callback.
majik 0:21019d94ad33 44
majik 0:21019d94ad33 45 [1] http://mbed.org/projects/libraries/svn/mbed/trunk/FunctionPointer.h
majik 0:21019d94ad33 46 */
majik 0:21019d94ad33 47
majik 0:21019d94ad33 48
majik 0:21019d94ad33 49 #ifdef COMPILE_EXAMPLE3_CODE_MODSERIAL
majik 0:21019d94ad33 50
majik 0:21019d94ad33 51 #include "mbed.h"
majik 0:21019d94ad33 52 #include "MODSERIAL.h"
majik 0:21019d94ad33 53
majik 0:21019d94ad33 54 void rxCallback(MODSERIAL_IRQ_INFO *info) {
majik 0:21019d94ad33 55
majik 0:21019d94ad33 56 // Get the pointer to our MODSERIAL object that invoked this callback.
majik 0:21019d94ad33 57 MODSERIAL *pc = info->serial;
majik 0:21019d94ad33 58
majik 0:21019d94ad33 59 // info->serial points at the MODSERIAL instance so we can use it to call
majik 0:21019d94ad33 60 // any of the public MODSERIAL functions that are normally available. So
majik 0:21019d94ad33 61 // there's now no need to use the global version (pc in our case) inside
majik 0:21019d94ad33 62 // callback functions.
majik 0:21019d94ad33 63 char c = pc->rxGetLastChar(); // Where local pc variable is a pointer to the global MODSERIAL pc object.
majik 0:21019d94ad33 64
majik 0:21019d94ad33 65 // The following is rather daft but demos the point.
majik 0:21019d94ad33 66 // Don't allow the letter "A" go into the RX buffer.
majik 0:21019d94ad33 67 // Basically acts as a filter to remove the letter "A"
majik 0:21019d94ad33 68 // if it goes into the RX buffer.
majik 0:21019d94ad33 69 if (c == 'A') {
majik 0:21019d94ad33 70 // Note, we call the MODSERIAL_IRQ_INFO::rxDiscardLastChar() public function which
majik 0:21019d94ad33 71 // is permitted access to the protected version of MODSERIAL::rxDiscardLastChar()
majik 0:21019d94ad33 72 // within MODSERIAL (because they are friends). This ensures rxDiscardLastChar()
majik 0:21019d94ad33 73 // can only be called within an rxCallback function.
majik 0:21019d94ad33 74 info->rxDiscardLastChar();
majik 0:21019d94ad33 75 }
majik 0:21019d94ad33 76 }
majik 0:21019d94ad33 77
majik 0:21019d94ad33 78 #endif