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  uint8_t board_sel;
44 }__attribute__ ((packed)) sensebe_sysinfo ;
48 typedef enum
49 {
50  TIMER_ONLY,
54 
58 typedef enum
59 {
60  LIGHTNING,
61  FAST,
62  NORM,
65 
69 typedef struct
70 {
77  uint8_t day_or_night: 1;
79  uint8_t threshold: 7;
80 }__attribute__ ((packed)) oper_time_t;
81 
85 typedef struct
86 {
88  uint8_t pre_focus : 1;
114  uint8_t mode : 7;
115  uint16_t larger_value;
116  uint8_t smaller_value;
117 }__attribute__ ((packed)) cam_oper_t;
118 
122 typedef enum
123 {
124  TIMER_ALL,
125 
126 // MOTION_ALL, //at rx side
127 
128  RADIO_ALL, //at tx side
129 
130 // TIMER_DAY,
131 // TIMER_NIGHT,
132 
133 // MOTION_DAY,
134 // MOTION_NIGHT,
135 
136 // RADIO_DAY,
137 // RADIO_NIGHT,
138  MAX_TRIGGERS,
140 
144 typedef struct
145 {
147  uint16_t timer_interval;
149  oper_time_t oper_time;
150 }__attribute__ ((packed)) timer_conf_t;
151 
152 /***/
153 typedef struct
154 {
156  oper_time_t oper_time;
158  uint8_t is_enable: 1;
167  uint8_t ir_tx_speed: 2;
175  uint8_t ir_tx_pwr: 2;
176 }__attribute__ ((packed)) ir_tx_conf_t;
177 
181 typedef struct
182 {
184  trigger_conf_t trig_conf;
186  cam_oper_t cam_trigs[MAX_TRIGGERS];
188  device_speed_t speed;
190  timer_conf_t timer_conf;
192  ir_tx_conf_t ir_tx_conf;
193 }__attribute__ ((packed)) sensebe_config_t ;
194 
195 typedef struct
196 {
197  uint8_t * adv_data;
198  uint16_t adv_len;
199  uint8_t * scan_rsp_data;
200  uint16_t scan_rsp_len;
201 }
202 sensebe_ble_adv_data_t;
203 
210 void sensebe_ble_init(void (*ble_sd_evt)(ble_evt_t * evt),
211  void (* config_update)(sensebe_config_t * cfg));
212 
217 void sensebe_ble_update_sysinfo(sensebe_sysinfo * sysinfo);
218 
223 void sensebe_ble_update_config(sensebe_config_t * config);
224 
228 void sensebe_ble_disconn(void);
229 
234 void sensebe_ble_stack_init(void);
235 
243 void sensebe_ble_service_init(void);
244 
249 void sensebe_ble_gap_params_init(void);
250 
256 void sensebe_ble_adv_init(sensebe_ble_adv_data_t * sensebe_ble_adv_data);
257 
261 void sensebe_ble_adv_start(void);
262 
263 #endif /* APPLICATION_SENSEBE_BLE_H_ */
264 
void sensebe_ble_update_sysinfo(sensebe_sysinfo *sysinfo)
Updates the characteristic that stores the sysinfo.
Definition: sensebe_ble.c:187
ir_tx_conf_t ir_tx_conf
Definition: sensebe_ble.h:192
Lightning mode.
Definition: sensebe_ble.h:61
Normal mode.
Definition: sensebe_ble.h:63
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
Fast mode.
Definition: sensebe_ble.h:62
cam_trig_ls_t
Enum to store the list of camera triggers possible.
Definition: sensebe_ble.h:122
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
uint8_t ir_tx_speed
To decide the time between 2 signals for IR transmitter. @TIME 0 5ms\ 1 25ms\ 2 50ms\ 3 100ms.
Definition: sensebe_ble.h:167
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
device_speed_t
Enum to select operation speed for Device.
Definition: sensebe_ble.h:58
uint8_t ir_tx_pwr
Definition: sensebe_ble.h:175
uint8_t is_enable
Definition: sensebe_ble.h:158
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