Nordic Thingy:52 v2.2.0
ble_uis.h
Go to the documentation of this file.
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 
62 #ifndef BLE_UIS_H__
63 #define BLE_UIS_H__
64 
65 #include <stdint.h>
66 #include <stdbool.h>
67 #include "ble.h"
68 #include "ble_srv_common.h"
69 #include "app_util_platform.h"
70 
71 #define BLE_UIS_UUID_BASE {{0x42, 0x00, 0x74, 0xA9, 0xFF, 0x52, 0x10, 0x9B, 0x33, 0x49, 0x35, 0x9B, 0x00, 0x00, 0x68, 0xEF}}
72 
73 #define BLE_UIS_UUID_SERVICE 0x0300
74 #define BLE_UIS_UUID_LED_CHAR 0x0301
75 #define BLE_UIS_UUID_BUTTON_CHAR 0x0302
76 #define BLE_UIS_UUID_PIN_CHAR 0x0303
78 #ifdef __GNUC__
79  #ifdef PACKED
80  #undef PACKED
81  #endif
82 
83  #define PACKED(TYPE) TYPE __attribute__ ((packed))
84 #endif
85 
88 typedef enum
89 {
95 
96 #define BLE_UIS_LED_MODE_MIN BLE_UIS_LED_MODE_OFF
97 #define BLE_UIS_LED_MODE_MAX BLE_UIS_LED_MODE_BREATHE_ONE_SHOT
99 #define BLE_UIS_LED_MODE_OFF_LENGTH 1
100 #define BLE_UIS_LED_MODE_CONST_LENGTH 4
101 #define BLE_UIS_LED_MODE_BREATHE_LENGTH 5
102 #define BLE_UIS_LED_MODE_BREATHE_ONE_SHOT_LENGTH 3
104 #define BLE_UIS_LED_COLOR_MIX_MIN 1
105 #define BLE_UIS_LED_COLOR_MIX_MAX 7
106 #define BLE_UIS_LED_INTENSITY_MIN 1
107 #define BLE_UIS_LED_INTENSITY_MAX 100
108 #define BLE_UIS_LED_DELAY_MIN 50
109 #define BLE_UIS_LED_DELAY_MAX 10000
113 typedef PACKED( union
114 {
115  PACKED( struct
116  {
117  uint8_t r;
118  uint8_t g;
119  uint8_t b;
120  })mode_const;
121  PACKED( struct
122  {
123  uint8_t color_mix;
124  uint8_t intensity;
125  uint16_t delay;
126  })mode_breathe;
127  PACKED( struct
128  {
129  uint8_t color_mix;
130  uint8_t intensity;
131  })mode_breathe_one_shot;
132 }) ble_uis_led_data_t;
133 
136 typedef PACKED( struct
137 {
138  ble_uis_led_mode_t mode;
139  ble_uis_led_data_t data;
140 }) ble_uis_led_t;
141 
144 typedef PACKED( struct
145 {
146  uint8_t mos_1;
147  uint8_t mos_2;
148  uint8_t mos_3;
149  uint8_t mos_4;
150 }) ble_uis_pin_t;
151 
154 typedef struct ble_uis_s ble_uis_t;
155 
158 typedef void (*ble_uis_led_write_handler_t) (ble_uis_t * p_uis, ble_uis_led_t * rgb);
159 
162 typedef void (*ble_uis_pin_write_handler_t) (ble_uis_t * p_uis, ble_uis_pin_t * pin);
163 
167 typedef struct
168 {
169  ble_uis_pin_t init_pin;
170  ble_uis_led_t * p_init_led;
174 
177 struct ble_uis_s
178 {
179  uint16_t service_handle;
180  ble_gatts_char_handles_t led_char_handles;
181  ble_gatts_char_handles_t pin_char_handles;
182  ble_gatts_char_handles_t button_char_handles;
183  uint8_t uuid_type;
184  uint16_t conn_handle;
185  bool is_button_notif_enabled;
188 };
189 
199 uint32_t ble_uis_init(ble_uis_t * p_uis, const ble_uis_init_t * p_uis_init);
200 
208 void ble_uis_on_ble_evt(ble_uis_t * p_uis, ble_evt_t * p_ble_evt);
209 
217 uint32_t ble_uis_on_button_change(ble_uis_t * p_uis, uint8_t buttons_state);
218 
219 #endif // BLE_UIS_H__
220 
void(* ble_uis_pin_write_handler_t)(ble_uis_t *p_uis, ble_uis_pin_t *pin)
Declaring the pin write handler.
Definition: ble_uis.h:162
ble_uis_led_write_handler_t led_write_handler
Definition: ble_uis.h:171
Definition: ble_uis.h:91
LED Button Service init structure. This structure contains all options and data needed for initializa...
Definition: ble_uis.h:167
ble_gatts_char_handles_t led_char_handles
Definition: ble_uis.h:180
ble_uis_pin_write_handler_t pin_write_handler
Definition: ble_uis.h:172
uint16_t service_handle
Definition: ble_uis.h:179
ble_uis_led_mode_t
The available LED operation modes.
Definition: ble_uis.h:88
uint32_t ble_uis_on_button_change(ble_uis_t *p_uis, uint8_t buttons_state)
Function for sending a button state notification.
LED Button Service structure. This structure contains various status information for the service...
Definition: ble_uis.h:177
void ble_uis_on_ble_evt(ble_uis_t *p_uis, ble_evt_t *p_ble_evt)
Function for handling the application&#39;s BLE stack events.
ble_gatts_char_handles_t pin_char_handles
Definition: ble_uis.h:181
Definition: ble_uis.h:92
ble_uis_led_write_handler_t led_write_handler
Definition: ble_uis.h:186
Definition: ble_uis.h:93
ble_uis_pin_write_handler_t pin_write_handler
Definition: ble_uis.h:187
ble_gatts_char_handles_t button_char_handles
Definition: ble_uis.h:182
void(* ble_uis_led_write_handler_t)(ble_uis_t *p_uis, ble_uis_led_t *rgb)
Declaring the LED write handler.
Definition: ble_uis.h:158
uint8_t uuid_type
Definition: ble_uis.h:183
uint32_t ble_uis_init(ble_uis_t *p_uis, const ble_uis_init_t *p_uis_init)
Function for initializing the LED Button Service.
Definition: ble_uis.h:90
uint16_t conn_handle
Definition: ble_uis.h:184