Naze32 clone with Frysky receiver
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 example3b.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. void rxCallback(MODSERIAL_IRQ_INFO *info) {
  43. // Get the pointer to our MODSERIAL object that invoked this callback.
  44. MODSERIAL *pc = info->serial;
  45. // info->serial points at the MODSERIAL instance so we can use it to call
  46. // any of the public MODSERIAL functions that are normally available. So
  47. // there's now no need to use the global version (pc in our case) inside
  48. // callback functions.
  49. char c = pc->rxGetLastChar(); // Where local pc variable is a pointer to the global MODSERIAL pc object.
  50. // The following is rather daft but demos the point.
  51. // Don't allow the letter "A" go into the RX buffer.
  52. // Basically acts as a filter to remove the letter "A"
  53. // if it goes into the RX buffer.
  54. if (c == 'A') {
  55. // Note, we call the MODSERIAL_IRQ_INFO::rxDiscardLastChar() public function which
  56. // is permitted access to the protected version of MODSERIAL::rxDiscardLastChar()
  57. // within MODSERIAL (because they are friends). This ensures rxDiscardLastChar()
  58. // can only be called within an rxCallback function.
  59. info->rxDiscardLastChar();
  60. }
  61. }
  62. #endif