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