Naze32 clone with Frysky receiver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example3a.cpp 3.0KB

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