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.

79 lines
1.8 KiB

  1. /*
  2. Copyright 2017 Priyadi Iman Nurcahyo
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "outputselect.h"
  15. #if defined(PROTOCOL_LUFA)
  16. # include "lufa.h"
  17. #endif
  18. #ifdef MODULE_ADAFRUIT_BLE
  19. # include "adafruit_ble.h"
  20. #endif
  21. uint8_t desired_output = OUTPUT_DEFAULT;
  22. /** \brief Set Output
  23. *
  24. * FIXME: Needs doc
  25. */
  26. void set_output(uint8_t output) {
  27. set_output_user(output);
  28. desired_output = output;
  29. }
  30. /** \brief Set Output User
  31. *
  32. * FIXME: Needs doc
  33. */
  34. __attribute__((weak)) void set_output_user(uint8_t output) {}
  35. static bool is_usb_configured(void) {
  36. #if defined(PROTOCOL_LUFA)
  37. return USB_DeviceState == DEVICE_STATE_Configured;
  38. #endif
  39. }
  40. /** \brief Auto Detect Output
  41. *
  42. * FIXME: Needs doc
  43. */
  44. uint8_t auto_detect_output(void) {
  45. if (is_usb_configured()) {
  46. return OUTPUT_USB;
  47. }
  48. #ifdef MODULE_ADAFRUIT_BLE
  49. if (adafruit_ble_is_connected()) {
  50. return OUTPUT_BLUETOOTH;
  51. }
  52. #endif
  53. #ifdef BLUETOOTH_ENABLE
  54. return OUTPUT_BLUETOOTH; // should check if BT is connected here
  55. #endif
  56. return OUTPUT_NONE;
  57. }
  58. /** \brief Where To Send
  59. *
  60. * FIXME: Needs doc
  61. */
  62. uint8_t where_to_send(void) {
  63. if (desired_output == OUTPUT_AUTO) {
  64. return auto_detect_output();
  65. }
  66. return desired_output;
  67. }