Nordic Thingy:52
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ble_tms.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 
58 #ifndef BLE_TMS_H__
59 #define BLE_TMS_H__
60 
61 #include "ble.h"
62 #include "ble_srv_common.h"
63 #include "app_util_platform.h"
64 #include <stdint.h>
65 #include <stdbool.h>
66 
67 #define BLE_UUID_TMS_SERVICE 0x0400
68 #define BLE_TMS_MAX_DATA_LEN (GATT_MTU_SIZE_DEFAULT - 3)
70 #ifdef __GNUC__
71  #ifdef PACKED
72  #undef PACKED
73  #endif
74 
75  #define PACKED(TYPE) TYPE __attribute__ ((packed))
76 #endif
77 
78 typedef PACKED( struct
79 {
80  int16_t x;
81  int16_t y;
82  int16_t z;
83 }) ble_tms_raw_accel_t;
84 
85 typedef PACKED( struct
86 {
87  int16_t x;
88  int16_t y;
89  int16_t z;
90 }) ble_tms_raw_gyro_t;
91 
92 typedef PACKED( struct
93 {
94  int16_t x;
95  int16_t y;
96  int16_t z;
97 }) ble_tms_raw_compass_t;
98 
99 typedef PACKED( struct
100 {
101  ble_tms_raw_accel_t accel;
102  ble_tms_raw_gyro_t gyro;
103  ble_tms_raw_compass_t compass;
104 }) ble_tms_raw_t;
105 
106 typedef PACKED( struct
107 {
108  uint8_t dir;
109  uint8_t cnt;
110 }) ble_tms_tap_t;
111 
112 typedef uint8_t ble_tms_orientation_t;
113 
114 typedef PACKED( struct
115 {
116  int32_t w;
117  int32_t x;
118  int32_t y;
119  int32_t z;
120 }) ble_tms_quat_t;
121 
122 typedef PACKED( struct
123 {
124  int32_t roll;
125  int32_t pitch;
126  int32_t yaw;
127 }) ble_tms_euler_t;
128 
129 typedef PACKED( struct
130 {
131  int16_t matrix[9];
132 }) ble_tms_rot_mat_t;
133 
134 typedef int32_t ble_tms_heading_t;
135 
136 typedef PACKED( struct
137 {
138  float x;
139  float y;
140  float z;
141 }) ble_tms_gravity_t;
142 
143 typedef PACKED( struct
144 {
145  uint32_t steps;
146  uint32_t time_ms;
147 }) ble_tms_pedo_t;
148 
149 typedef PACKED( struct
150 {
151  uint16_t pedo_interval_ms;
152  uint16_t temp_interval_ms;
153  uint16_t compass_interval_ms;
154  uint16_t motion_freq_hz;
155  uint8_t wake_on_motion;
156 }) ble_tms_config_t;
157 
158 #define BLE_TMS_CONFIG_PEDO_INT_MIN 100
159 #define BLE_TMS_CONFIG_PEDO_INT_MAX 5000
160 #define BLE_TMS_CONFIG_TEMP_INT_MIN 100
161 #define BLE_TMS_CONFIG_TEMP_INT_MAX 5000
162 #define BLE_TMS_CONFIG_COMP_INT_MIN 100
163 #define BLE_TMS_CONFIG_COMP_INT_MAX 5000
164 #define BLE_TMS_CONFIG_MPUF_MIN 1
165 #define BLE_TMS_CONFIG_MPUF_MAX 200
166 #define BLE_TMS_CONFIG_WOM_MIN 0
167 #define BLE_TMS_CONFIG_WOM_MAX 1
168 
169 typedef enum
170 {
171  BLE_TMS_EVT_CONFIG_RECEIVED,
172  BLE_TMS_EVT_NOTIF_TAP,
173  BLE_TMS_EVT_NOTIF_ORIENTATION,
174  BLE_TMS_EVT_NOTIF_QUAT,
175  BLE_TMS_EVT_NOTIF_PEDOMETER,
176  BLE_TMS_EVT_NOTIF_RAW,
177  BLE_TMS_EVT_NOTIF_EULER,
178  BLE_TMS_EVT_NOTIF_ROT_MAT,
179  BLE_TMS_EVT_NOTIF_HEADING,
180  BLE_TMS_EVT_NOTIF_GRAVITY,
181 }ble_tms_evt_type_t;
182 
183 /* Forward declaration of the ble_tms_t type. */
184 typedef struct ble_tms_s ble_tms_t;
185 
187 typedef void (*ble_tms_evt_handler_t) (ble_tms_t * p_tms,
188  ble_tms_evt_type_t evt_type,
189  uint8_t * p_data,
190  uint16_t length);
191 
197 typedef struct
198 {
199  ble_tms_config_t * p_init_config;
202 
207 struct ble_tms_s
208 {
209  uint8_t uuid_type;
210  uint16_t service_handle;
211  ble_gatts_char_handles_t config_handles;
212  ble_gatts_char_handles_t tap_handles;
213  ble_gatts_char_handles_t orientation_handles;
214  ble_gatts_char_handles_t quat_handles;
215  ble_gatts_char_handles_t pedo_handles;
216  ble_gatts_char_handles_t raw_handles;
217  ble_gatts_char_handles_t euler_handles;
218  ble_gatts_char_handles_t rot_mat_handles;
219  ble_gatts_char_handles_t heading_handles;
220  ble_gatts_char_handles_t gravity_handles;
221  uint16_t conn_handle;
232 };
233 
244 uint32_t ble_tms_init(ble_tms_t * p_wss, const ble_tms_init_t * p_tms_init);
245 
256 void ble_tms_on_ble_evt(ble_tms_t * p_wss, ble_evt_t * p_ble_evt);
257 
267 uint32_t ble_tms_tap_set(ble_tms_t * p_tms, ble_tms_tap_t * p_data);
268 
278 uint32_t ble_tms_orientation_set(ble_tms_t * p_tms, ble_tms_orientation_t * p_data);
279 
289 uint32_t ble_tms_quat_set(ble_tms_t * p_tms, ble_tms_quat_t * p_data);
290 
300 uint32_t ble_tms_pedo_set(ble_tms_t * p_tms, ble_tms_pedo_t * p_data);
301 
311 uint32_t ble_tms_raw_set(ble_tms_t * p_tms, ble_tms_raw_t * p_data);
312 
322 uint32_t ble_tms_euler_set(ble_tms_t * p_tms, ble_tms_euler_t * p_data);
323 
333 uint32_t ble_tms_rot_mat_set(ble_tms_t * p_tms, ble_tms_rot_mat_t * p_data);
334 
344 uint32_t ble_tms_heading_set(ble_tms_t * p_tms, ble_tms_heading_t * p_data);
345 
355 uint32_t ble_tms_gravity_set(ble_tms_t * p_tms, ble_tms_gravity_t * p_data);
356 
357 #endif // BLE_TMS_H__
358