Nordic Thingy:52 v2.2.0
ble_tes.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 
52 #ifndef BLE_TES_H__
53 #define BLE_TES_H__
54 
55 #include "ble.h"
56 #include "ble_srv_common.h"
57 #include "app_util_platform.h"
58 #include <stdint.h>
59 #include <stdbool.h>
60 
61 #define BLE_UUID_TES_SERVICE 0x0200
62 #define BLE_TES_MAX_DATA_LEN (BLE_GATT_ATT_MTU_DEFAULT - 3)
64 #ifdef __GNUC__
65  #ifdef PACKED
66  #undef PACKED
67  #endif
68 
69  #define PACKED(TYPE) TYPE __attribute__ ((packed))
70 #endif
71 
72 typedef PACKED( struct
73 {
74  int8_t integer;
75  uint8_t decimal;
76 }) ble_tes_temperature_t;
77 
78 typedef PACKED( struct
79 {
80  int32_t integer;
81  uint8_t decimal;
82 }) ble_tes_pressure_t;
83 
84 typedef uint8_t ble_tes_humidity_t;
85 
86 typedef PACKED( struct
87 {
88  uint16_t eco2_ppm;
89  uint16_t tvoc_ppb;
90 }) ble_tes_gas_t;
91 
92 typedef PACKED( struct
93 {
94  uint16_t red;
95  uint16_t green;
96  uint16_t blue;
97  uint16_t clear;
98 }) ble_tes_color_t;
99 
100 typedef enum
101 {
102  GAS_MODE_250MS,
103  GAS_MODE_1S,
104  GAS_MODE_10S,
105  GAS_MODE_60S,
106 } ble_tes_gas_mode_t;
107 
108 typedef PACKED( struct
109 {
110  uint8_t led_red;
111  uint8_t led_green;
112  uint8_t led_blue;
113 }) ble_tes_color_config_t;
114 
115 typedef PACKED( struct
116 {
117  uint16_t temperature_interval_ms;
118  uint16_t pressure_interval_ms;
119  uint16_t humidity_interval_ms;
120  uint16_t color_interval_ms;
121  uint8_t gas_interval_mode;
122  ble_tes_color_config_t color_config;
123 }) ble_tes_config_t;
124 
125 #define BLE_TES_CONFIG_TEMPERATURE_INT_MIN 100
126 #define BLE_TES_CONFIG_TEMPERATURE_INT_MAX 60000
127 #define BLE_TES_CONFIG_PRESSURE_INT_MIN 50
128 #define BLE_TES_CONFIG_PRESSURE_INT_MAX 60000
129 #define BLE_TES_CONFIG_HUMIDITY_INT_MIN 100
130 #define BLE_TES_CONFIG_HUMIDITY_INT_MAX 60000
131 #define BLE_TES_CONFIG_COLOR_INT_MIN 200
132 #define BLE_TES_CONFIG_COLOR_INT_MAX 60000
133 #define BLE_TES_CONFIG_GAS_MODE_MIN 1
134 #define BLE_TES_CONFIG_GAS_MODE_MAX 3
135 
136 typedef enum
137 {
138  BLE_TES_EVT_NOTIF_TEMPERATURE,
139  BLE_TES_EVT_NOTIF_PRESSURE,
140  BLE_TES_EVT_NOTIF_HUMIDITY,
141  BLE_TES_EVT_NOTIF_GAS,
142  BLE_TES_EVT_NOTIF_COLOR,
143  BLE_TES_EVT_CONFIG_RECEIVED
144 }ble_tes_evt_type_t;
145 
146 /* Forward declaration of the ble_tes_t type. */
147 typedef struct ble_tes_s ble_tes_t;
148 
150 typedef void (*ble_tes_evt_handler_t) (ble_tes_t * p_tes,
151  ble_tes_evt_type_t evt_type,
152  uint8_t * p_data,
153  uint16_t length);
154 
160 typedef struct
161 {
162  ble_tes_temperature_t * p_init_temperature;
163  ble_tes_pressure_t * p_init_pressure;
164  ble_tes_humidity_t * p_init_humidity;
165  ble_tes_gas_t * p_init_gas;
166  ble_tes_color_t * p_init_color;
167  ble_tes_config_t * p_init_config;
170 
175 struct ble_tes_s
176 {
177  uint8_t uuid_type;
178  uint16_t service_handle;
179  ble_gatts_char_handles_t temperature_handles;
180  ble_gatts_char_handles_t pressure_handles;
181  ble_gatts_char_handles_t humidity_handles;
182  ble_gatts_char_handles_t gas_handles;
183  ble_gatts_char_handles_t color_handles;
184  ble_gatts_char_handles_t config_handles;
185  uint16_t conn_handle;
192 };
193 
204 uint32_t ble_tes_init(ble_tes_t * p_tes, const ble_tes_init_t * p_tes_init);
205 
216 void ble_tes_on_ble_evt(ble_tes_t * p_tes, ble_evt_t * p_ble_evt);
217 
228 uint32_t ble_tes_temperature_set(ble_tes_t * p_tes, ble_tes_temperature_t * p_data);
229 
239 uint32_t ble_tes_pressure_set(ble_tes_t * p_tes, ble_tes_pressure_t * p_data);
240 
250 uint32_t ble_tes_humidity_set(ble_tes_t * p_tes, ble_tes_humidity_t * p_data);
251 
261 uint32_t ble_tes_gas_set(ble_tes_t * p_tes, ble_tes_gas_t * p_data);
262 
272 uint32_t ble_tes_color_set(ble_tes_t * p_tes, ble_tes_color_t * p_data);
273 
274 #endif // BLE_TES_H__
275 
ble_gatts_char_handles_t humidity_handles
Definition: ble_tes.h:181
uint32_t ble_tes_init(ble_tes_t *p_tes, const ble_tes_init_t *p_tes_init)
Function for initializing the Thingy Environment Service.
uint32_t ble_tes_gas_set(ble_tes_t *p_tes, ble_tes_gas_t *p_data)
Function for setting the gas data.
uint32_t ble_tes_pressure_set(ble_tes_t *p_tes, ble_tes_pressure_t *p_data)
Function for setting the pressure.
ble_gatts_char_handles_t gas_handles
Definition: ble_tes.h:182
uint16_t conn_handle
Definition: ble_tes.h:185
bool is_temperature_notif_enabled
Definition: ble_tes.h:186
ble_gatts_char_handles_t color_handles
Definition: ble_tes.h:183
Thingy Environment Service initialization structure.
Definition: ble_tes.h:160
void ble_tes_on_ble_evt(ble_tes_t *p_tes, ble_evt_t *p_ble_evt)
Function for handling the Thingy Environment Service&#39;s BLE events.
void(* ble_tes_evt_handler_t)(ble_tes_t *p_tes, ble_tes_evt_type_t evt_type, uint8_t *p_data, uint16_t length)
Thingy Environment Service event handler type.
Definition: ble_tes.h:150
bool is_color_notif_enabled
Definition: ble_tes.h:190
uint32_t ble_tes_temperature_set(ble_tes_t *p_tes, ble_tes_temperature_t *p_data)
Function for setting the temperature.
Thingy Environment Service structure.
Definition: ble_tes.h:175
uint16_t service_handle
Definition: ble_tes.h:178
bool is_humidity_notif_enabled
Definition: ble_tes.h:188
ble_gatts_char_handles_t pressure_handles
Definition: ble_tes.h:180
uint8_t uuid_type
Definition: ble_tes.h:177
ble_tes_evt_handler_t evt_handler
Definition: ble_tes.h:168
ble_gatts_char_handles_t temperature_handles
Definition: ble_tes.h:179
uint32_t ble_tes_color_set(ble_tes_t *p_tes, ble_tes_color_t *p_data)
Function for setting the color data.
bool is_gas_notif_enabled
Definition: ble_tes.h:189
ble_tes_evt_handler_t evt_handler
Definition: ble_tes.h:191
bool is_pressure_notif_enabled
Definition: ble_tes.h:187
ble_gatts_char_handles_t config_handles
Definition: ble_tes.h:184
uint32_t ble_tes_humidity_set(ble_tes_t *p_tes, ble_tes_humidity_t *p_data)
Function for setting the humidity.