Appiko
sensebe_ble.h
1 /*
2  * sensebe_ble.h : BLE Support file for SenseBe application
3  * Copyright (C) 2019 Appiko
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
30 #ifndef APPLICATION_SENSEBE_BLE_H_
31 #define APPLICATION_SENSEBE_BLE_H_
32 
33 #include "stdint.h"
34 #include "stdbool.h"
35 #include "ble.h"
36 #include "dev_id_fw_ver.h"
37 
38 typedef struct
39 {
40  dev_id_t id;
41  uint8_t battery_status;
42  fw_ver_t fw_ver;
43 }__attribute__ ((packed)) sensebe_sysinfo ;
47 typedef enum
48 {
49  TIMER_ONLY,
53 
57 typedef struct
58 {
65  uint8_t day_or_night: 1;
67  uint8_t threshold: 7;
68 }__attribute__ ((packed)) oper_time_t;
69 
73 typedef struct
74 {
76  uint8_t pre_focus : 1;
102  uint8_t mode : 7;
103  uint16_t larger_value;
104  uint8_t smaller_value;
105 }__attribute__ ((packed)) cam_oper_t;
106 
110 typedef struct
111 {
113  oper_time_t oper_time;
115  uint16_t detect_window;
116  cam_oper_t cam_oper;
118  uint16_t intr_trig_timer;
119 }__attribute__ ((packed)) tssp_conf_t;
120 
124 typedef struct
125 {
127  uint16_t timer_interval;
129  oper_time_t oper_time;
130  cam_oper_t cam_oper;
131 }__attribute__ ((packed)) timer_conf_t;
132 
133 /***/
134 typedef struct
135 {
137  oper_time_t oper_time;
139  uint8_t is_enable: 1;
148  uint8_t ir_tx_speed: 2;
156  uint8_t ir_tx_pwr: 2;
157 }__attribute__ ((packed)) ir_tx_conf_t;
158 
162 typedef struct
163 {
165  trigger_conf_t trig_conf;
167  tssp_conf_t tssp_conf;
169  timer_conf_t timer_conf;
171  ir_tx_conf_t ir_tx_conf;
172 }__attribute__ ((packed)) sensebe_config_t ;
173 
174 typedef struct
175 {
176  uint8_t * adv_data;
177  uint16_t adv_len;
178  uint8_t * scan_rsp_data;
179  uint16_t scan_rsp_len;
180 }
181 sensebe_ble_adv_data_t;
182 
189 void sensebe_ble_init(void (*ble_sd_evt)(ble_evt_t * evt),
190  void (* config_update)(sensebe_config_t * cfg));
191 
196 void sensebe_ble_update_sysinfo(sensebe_sysinfo * sysinfo);
197 
202 void sensebe_ble_update_config(sensebe_config_t * config);
203 
207 void sensebe_ble_disconn(void);
208 
213 void sensebe_ble_stack_init(void);
214 
222 void sensebe_ble_service_init(void);
223 
228 void sensebe_ble_gap_params_init(void);
229 
235 void sensebe_ble_adv_init(sensebe_ble_adv_data_t * sensebe_ble_adv_data);
236 
240 void sensebe_ble_adv_start(void);
241 
242 #endif /* APPLICATION_SENSEBE_BLE_H_ */
243 
void sensebe_ble_update_sysinfo(sensebe_sysinfo *sysinfo)
Updates the characteristic that stores the sysinfo.
Definition: sensebe_ble.c:187
void sensebe_ble_stack_init(void)
Function for initializing the BLE stack by enabling the SoftDevice and the BLE event interrupt.
Definition: sensebe_ble.c:216
void sensebe_ble_service_init(void)
Create the Service and its characteristics for the SensePi device. There is a read-only characteristi...
Definition: sensebe_ble.c:251
void sensebe_ble_init(void(*ble_sd_evt)(ble_evt_t *evt), void(*config_update)(sensebe_config_t *cfg))
Initialize the handlers to pass the BLE SD events and the configuration received from the mobile app.
Definition: sensebe_ble.c:169
Strcture for Operation time.
Definition: sensepi_ble.h:38
void sensebe_ble_disconn(void)
Disconnect the current active connection, if already connected.
Definition: sensebe_ble.c:176
void sensebe_ble_update_config(sensebe_config_t *config)
Updates the characteristic that stores the SensePi config.
Definition: sensebe_ble.c:201
void sensebe_ble_adv_start(void)
Function to start advertising.
Definition: sensebe_ble.c:414
Trigger only on timer.
Definition: sensebe_ble.h:51
void sensebe_ble_gap_params_init(void)
Generic Access Profile initialization. The device name, and the preferred connection parameters are s...
Definition: sensebe_ble.c:346
Trigger only on motion detection.
Definition: sensebe_ble.h:52
void sensebe_ble_adv_init(sensebe_ble_adv_data_t *sensebe_ble_adv_data)
Function to initializing the advertising.
Definition: sensebe_ble.c:369
trigger_conf_t
Enum of all posiible modes of operation.
Definition: sensebe_ble.h:48