Nordic Thingy:52
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
m_ui.h
1 /*
2  Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form, except as embedded into a Nordic
12  Semiconductor ASA integrated circuit in a product or a software update for
13  such product, must reproduce the above copyright notice, this list of
14  conditions and the following disclaimer in the documentation and/or other
15  materials provided with the distribution.
16 
17  3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  contributors may be used to endorse or promote products derived from this
19  software without specific prior written permission.
20 
21  4. This software, with or without modification, must only be used with a
22  Nordic Semiconductor ASA integrated circuit.
23 
24  5. Any software provided in binary form under this license must not be reverse
25  engineered, decompiled, modified and/or disassembled.
26 
27  THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29  OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30  DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
48 #ifndef __M_UI_H__
49 #define __M_UI_H__
50 
51 #include "app_error.h"
52 #include "m_ble.h"
53 #include "nrf_drv_twi.h"
54 
55 #define DEFAULT_LED_INTENSITY_PERCENT 20
56 #define DEFAULT_LED_ON_TIME_MS 35
57 #define DEFAULT_LED_OFF_TIME_MS 3500
58 #define DEFAULT_LED_FADE_IN_TIME 2000
59 #define DEFAULT_LED_FADE_OUT_TIME 500
60 
61 
63 enum
64 {
65  M_IU_STATUS_CODE_SUCCESS = NRF_SUCCESS,
67 };
68 
71 #define UI_CONFIG_DEFAULT_CONNECTED \
72 { \
73  .mode = BLE_UIS_LED_MODE_BREATHE, \
74  .data = \
75  { \
76  .mode_breathe = \
77  { \
78  .color_mix = (uint8_t)DRV_EXT_LIGHT_COLOR_CYAN, \
79  .intensity = DEFAULT_LED_INTENSITY_PERCENT, \
80  .delay = DEFAULT_LED_OFF_TIME_MS \
81  } \
82  } \
83 }
84 
87 #define UI_CONFIG_DEFAULT_DISCONNECTED \
88 { \
89  .mode = BLE_UIS_LED_MODE_BREATHE, \
90  .data = \
91  { \
92  .mode_breathe = \
93  { \
94  .color_mix = (uint8_t)DRV_EXT_LIGHT_COLOR_BLUE, \
95  .intensity = DEFAULT_LED_INTENSITY_PERCENT, \
96  .delay = DEFAULT_LED_OFF_TIME_MS \
97  } \
98  } \
99 }
100 
103 #define UI_CONFIG_DEFAULT_ERROR \
104 { \
105  .mode = BLE_UIS_LED_MODE_BREATHE, \
106  .data = \
107  { \
108  .mode_breathe = \
109  { \
110  .color_mix = (uint8_t)DRV_EXT_LIGHT_COLOR_RED, \
111  .intensity = DEFAULT_LED_INTENSITY_PERCENT, \
112  .delay = DEFAULT_LED_OFF_TIME_MS / 4 \
113  } \
114  } \
115 }
116 
119 #define SEQUENCE_DEFAULT_VALUES \
120 { \
121  .sequence_vals.on_time_ms = DEFAULT_LED_ON_TIME_MS, \
122  .sequence_vals.on_intensity = 0xFF, \
123  .sequence_vals.off_intensity = 0, \
124  .sequence_vals.fade_in_time_ms = DEFAULT_LED_FADE_IN_TIME, \
125  .sequence_vals.fade_out_time_ms = DEFAULT_LED_FADE_OUT_TIME, \
126 }
127 
130 typedef enum
131 {
132  M_UI_BLE_CONNECTED,
133  M_UI_BLE_DISCONNECTED,
134  M_UI_ERROR
136 
139 typedef struct
140 {
141  nrf_drv_twi_t const * p_twi_instance;
142 }m_ui_init_t;
143 
150 ret_code_t m_ui_init(m_ble_service_handle_t * p_handle, m_ui_init_t * p_params);
151 
164 ret_code_t m_ui_led_set(uint8_t r, uint8_t g, uint8_t b);
165 
174 ret_code_t m_ui_led_set_event(ui_led_events event_code);
175 #endif /*__THINGY_UI_H__*/
176