Communication program for the chrobotics UM6 9-DOF IMU AHRS.

Dependencies:   MODSERIAL mbed

Committer:
lhiggs
Date:
Fri Sep 28 00:40:29 2012 +0000
Revision:
0:03c649c76388
A UM6 IMU AHRS INTERFACE

Who changed what in which revision?

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