-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.c
112 lines (93 loc) · 3.55 KB
/
ui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Copyright (c) 2020 Open Ring Project, All rights reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "app_util.h"
#include "ui.h"
#include "main.h"
#include "ble_config.h"
#include "bsp_btn_ble.h"
#include "nrf_log.h"
// UI/UX?
#if defined(DEFAULT_UI_ENABLED) && DEFAULT_UI_ENABLED == 1
static BSP_EVT_HANDLERS(handlers);
void default_ui$indication_set(bsp_indication_t indication) {
ret_code_t err_code = bsp_indication_set(indication);
APP_ERROR_CHECK(err_code);
}
void default_ui$sleep_mode_prepare() {
UI_INDICATION_SET(BSP_INDICATE_IDLE);
//TODO: needed? need a button to go with this, also with continuous measurements what
// happens if we go to sleep
// Prepare wakeup buttons.
ret_code_t err_code = bsp_btn_ble_sleep_mode_prepare();
APP_ERROR_CHECK(err_code);
}
void default_ui$on_bsp_event_disconnect(bsp_event_t event) {
DISPATCH_EVT(handlers, event);
}
void default_ui$on_bsp_event_whitelist_off(bsp_event_t event) {
DISPATCH_EVT(handlers, event);
}
void default_ui$on_bsp_event_key_0(bsp_event_t event) {
DISPATCH_EVT(handlers, event);
}
void default_ui$on_bsp_event_sleep() {
sleep_mode_enter();
}
// @brief Function for handling events from the BSP module.
// * BSP = Board Support Package
// *
// * @param[in] event Event generated by button press.
void default_ui$on_bsp_evt(bsp_event_t event)
{
ret_code_t err_code;
switch (event)
{
case BSP_EVENT_SLEEP:
UI_ON_BSP_EVENT_SLEEP(event);
break;
case BSP_EVENT_DISCONNECT:
UI_ON_BSP_EVENT_DISCONNECT(event);
break;
case BSP_EVENT_WHITELIST_OFF:
UI_ON_BSP_EVENT_WHITELIST_OFF(event);
break;
case BSP_EVENT_KEY_0:
UI_ON_BSP_EVENT_KEY_0(event);
break;
default:
break;
}
}
// @brief Function for initializing buttons and leds.
// this is mainly needed for the dev kit
//
// @param[out] p_erase_bonds Will be true if the clear bonding button was pressed to wake the application up.
// TODO: possible to stick into a service manager?
// board controller?
void default_ui$init(bool * p_erase_bonds) {
NRF_LOG_INFO("UI init...");
ret_code_t err_code;
bsp_event_t startup_event;
err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, UI_ON_BSP_EVENT);
APP_ERROR_CHECK(err_code);
err_code = bsp_btn_ble_init(NULL, &startup_event);
APP_ERROR_CHECK(err_code);
*p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
}
#endif //DEFAULT_UI_ENABLED