35 #include "evt_sd_handler.h" 44 #include "hal_nop_delay.h" 45 #include "irq_msg_util.h" 46 #include "device_tick.h" 47 #include "pir_sense.h" 48 #include "hal_pin_analog_input.h" 49 #include "aa_aaa_battery_check.h" 50 #include "button_ui.h" 54 #include "app_error.h" 55 #include "out_pattern_gen.h" 56 #include "sensebe_ble.h" 57 #include "sensebe_tx_rx_mod.h" 58 #include "sensebe_store_config.h" 59 #include "dev_id_fw_ver.h" 62 #include "cam_trigger.h" 67 #define APP_DEVICE_NAME_CHAR 'S','e','n','s','e','B','e' 72 #define APP_UUID_COMPLETE 0x0a, 0xde, 0xfb, 0x07, 0x74, 0x83, 0x66, 0xb0, 0x0d, 0x48, 0xf5, 0x07, 0x60, 0xdc, 0x73, 0x3c 76 #define APP_ADV_DATA { \ 77 0x02, BLE_GAP_AD_TYPE_FLAGS, BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE, \ 78 sizeof(app_device_name) + 1, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, APP_DEVICE_NAME_CHAR, \ 79 0x11, BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE, APP_UUID_COMPLETE \ 84 #define APP_SCAN_RSP_DATA { \ 85 0x02, BLE_GAP_AD_TYPE_TX_POWER_LEVEL, 0 , \ 86 0x11, BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME, \ 87 'x', 'x','x', 'x', 'x', 'x' , 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', \ 88 0x04, BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA, 0 , 0 , 0 \ 93 #define WDT_PERIOD_MS 30100 99 #define SENSE_FAST_TICK_INTERVAL_MS 60 101 #define SENSE_SLOW_TICK_INTERVAL_MS 30000 104 #define ADV_FAST_TICK_INTERVAL_MS 60 106 #define ADV_SLOW_TICK_INTERVAL_MS 1100 109 #define CONN_FAST_TICK_INTERVAL_MS 60 111 #define CONN_SLOW_TICK_INTERVAL_MS 1100 114 #define CONN_TIMEOUT_MS (10*60*1000) 131 static uint32_t conn_count;
133 static sensebe_config_t sensebe_ble_default_config = {
134 .tssp_conf.oper_time.day_or_night = 1,
135 .tssp_conf.oper_time.threshold = 0b0000000,
136 .tssp_conf.detect_window = 100,
138 .tssp_conf.cam_oper.larger_value = 0,
139 .tssp_conf.cam_oper.smaller_value = 0,
140 .tssp_conf.cam_oper.pre_focus = 0,
141 .tssp_conf.intr_trig_timer = 15,
143 .timer_conf.oper_time.day_or_night = 1,
144 .timer_conf.oper_time.threshold = 0b0000000,
146 .timer_conf.cam_oper.larger_value = 0,
147 .timer_conf.cam_oper.smaller_value = 0,
148 .timer_conf.cam_oper.pre_focus = 0,
149 .timer_conf.timer_interval = 50,
153 .ir_tx_conf.oper_time.day_or_night = 1,
154 .ir_tx_conf.oper_time.threshold = 0b0000000,
155 .ir_tx_conf.is_enable = 1,
156 .ir_tx_conf.ir_tx_speed = 1,
157 .ir_tx_conf.ir_tx_pwr = 1,
162 sensebe_tx_rx_config_t default_sensebe_tx_rx_config =
165 .rx_detect_config.rx_en_pin = TSSP_RX_EN,
166 .rx_detect_config.rx_out_pin = TSSP_RX_OUT,
167 .rx_detect_config.focus_pin_no = JACK_FOCUS_PIN,
168 .rx_detect_config.trigger_pin_no = JACK_TRIGGER_PIN,
177 .sensebe_config = &sensebe_ble_default_config,
187 log_printf(
"WDT reset\n");
190 void prepare_init_ble_adv()
196 memcpy(&app_scan_rsp_data[23],
fw_ver_get(),
sizeof(fw_ver_t));
199 memcpy(&app_scan_rsp_data[5],
dev_id_get(),
sizeof(dev_id_t));
201 sensebe_ble_adv_data_t app_adv_data_struct =
203 .adv_data = app_adv_data,
204 .scan_rsp_data = app_scan_rsp_data,
218 static void ble_evt_handler(ble_evt_t * evt)
220 log_printf(
"ble evt %x\n", evt->header.evt_id);
221 switch (evt->header.evt_id)
223 case BLE_GAP_EVT_CONNECTED:
226 case BLE_GAP_EVT_DISCONNECTED:
229 case BLE_GAP_EVT_ADV_SET_TERMINATED:
232 case BLE_GAP_EVT_CONN_PARAM_UPDATE:
233 log_printf(
"sup time %d s, max intvl %d ms, min intvl %d ms, slave lat %d\n",
234 evt->evt.gap_evt.params.conn_param_update.conn_params.conn_sup_timeout/100,
235 (5*evt->evt.gap_evt.params.conn_param_update.conn_params.max_conn_interval)/4,
236 (5*evt->evt.gap_evt.params.conn_param_update.conn_params.min_conn_interval)/4,
237 evt->evt.gap_evt.params.conn_param_update.conn_params.slave_latency);
246 static void get_sensebe_config_t(sensebe_config_t *config)
258 log_printf(
"in %d\n", interval);
264 log_printf(
"Nxt Evt Hndlr : SENSING\n");
273 conn_count += interval;
290 log_printf(
"State change %d\n", new_state);
293 log_printf(
"new state same as current state\n");
302 sd_softdevice_disable();
303 log_printf(
"State Change : SENSING\n");
331 uint8_t is_sd_enabled;
332 sd_softdevice_is_enabled(&is_sd_enabled);
334 if(is_sd_enabled == 0)
339 prepare_init_ble_adv();
341 sensebe_sysinfo sysinfo;
342 memcpy(&sysinfo.id,
dev_id_get(),
sizeof(dev_id_t));
344 memcpy(&sysinfo.fw_ver,
fw_ver_get(),
sizeof(fw_ver_t));
383 log_printf(
"Act (0 = CROSS, 1= RELEASE) : %d\nStep : %d\n", act,step);
389 log_printf(
"fast\n");
410 NRF_POWER->GPREGRET = 0xB1;
411 log_printf(
"Trying to do system reset..!!");
412 uint8_t is_sd_enabled;
413 sd_softdevice_is_enabled(&is_sd_enabled);
414 if(is_sd_enabled == 0)
416 sd_nvic_SystemReset();
429 log_printf(
"slow\n");
453 hal_nop_delay_ms(600);
456 hal_nop_delay_ms(600);
468 log_printf(
"Reset because of ");
469 if(NRF_POWER->RESETREAS == 0)
471 log_printf(
"power on or brownout, ");
473 if(NRF_POWER->RESETREAS & POWER_RESETREAS_DIF_Msk)
475 log_printf(
"entering into debug interface from Sys OFF, ");
477 if(NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk)
479 log_printf(
"watchdog bite, ");
481 if(NRF_POWER->RESETREAS & POWER_RESETREAS_LOCKUP_Msk)
483 log_printf(
"CPU lockup, ");
485 if(NRF_POWER->RESETREAS & POWER_RESETREAS_OFF_Msk)
487 log_printf(
"wake up from SYS OFF by GPIO, ");
489 if(NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk)
491 log_printf(
"pin reset, ");
493 if(NRF_POWER->RESETREAS & POWER_RESETREAS_SREQ_Msk)
495 log_printf(
"software reset, ");
500 NRF_POWER->RESETREAS = (POWER_RESETREAS_DIF_Msk |
501 POWER_RESETREAS_DOG_Msk |
502 POWER_RESETREAS_LOCKUP_Msk |
503 POWER_RESETREAS_OFF_Msk |
504 POWER_RESETREAS_RESETPIN_Msk |
505 POWER_RESETREAS_SREQ_Msk);
508 #if DC_DC_CIRCUITRY == true //Defined in the board header file 509 NRF_POWER->DCDCEN = POWER_DCDCEN_DCDCEN_Enabled << POWER_DCDCEN_DCDCEN_Pos;
511 NRF_POWER->TASKS_LOWPWR = 1;
531 uint8_t is_sd_enabled;
532 sd_softdevice_is_enabled(&is_sd_enabled);
534 if(is_sd_enabled == 0)
553 log_printf(
"\n\nHello SenseBe World!\n");
567 irq_msg_callbacks cb =
void sensebe_ble_update_sysinfo(sensebe_sysinfo *sysinfo)
Updates the characteristic that stores the sysinfo.
uint8_t aa_aaa_battery_status()
Function to get battery status. It'll convert battery ADC value to 8bit.
sensebe_config_t * sensebe_tx_rx_last_config()
Function to get last config which is being used.
fw_ver_t * fw_ver_get(void)
Gets a pointer to the location where the Device ID is stored.
void boot_pwr_config(void)
Prints the reason for the last reset, enables the internal DC-DC converter if the board supports it a...
void load_last_config()
function to load previous sensepi configuration present in flash memory
void sensebe_ble_stack_init(void)
Function for initializing the BLE stack by enabling the SoftDevice and the BLE event interrupt.
BLE connection established with an app.
void sensebe_ble_service_init(void)
Create the Service and its characteristics for the SensePi device. There is a read-only characteristi...
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.
sense_states current_state
void sensebe_tx_rx_update_config(sensebe_config_t *update_sensebe_config)
Function to update SenseBe Rx configuration to config received over BLE.
void led_ui_loop_start(led_sequences seq, led_ui_priority_t priority)
Start a sequence to play repeatedly.
void sensebe_tx_rx_stop(void)
Function to disable detection for SenseBe Rx.
void sensebe_store_config_write(sensebe_config_t *latest_config)
Function to write the sensebe_config_t at address location received from get_next_location().
#define LEDS_ACTIVE_STATE
bool sensebe_store_config_is_memory_empty(void)
#define ADV_SLOW_TICK_INTERVAL_MS
void sensebe_tx_rx_start(void)
Function to enable detection for SenseBe Rx.
void state_change_handler(uint32_t new_state)
The handler that is called whenever the application transitions to a new state.
#define SENSEBE_RX_TX_SEL_PIN
void lfclk_init(lfclk_src_t lfclk_src)
Function to initialize the LF clock.
Use PIR sensor to sense motion based on the set configuration.
void sensebe_ble_disconn(void)
Disconnect the current active connection, if already connected.
Stucture for passing the configuration for initializing the Device Tick module.
void button_handler(button_ui_steps step, button_ui_action act)
Handler for all button related events.
#define MS_TIMER_TICKS_MS(ms)
void sensebe_ble_update_config(sensebe_config_t *config)
Updates the characteristic that stores the SensePi config.
void sensebe_ble_adv_start(void)
Function to start advertising.
#define APP_DEVICE_NAME_CHAR
void wdt_prior_reset_callback(void)
void device_tick_init(device_tick_cfg *cfg)
Initializes and starts the Device tick module. Provides a next interval event immediately....
#define CONN_FAST_TICK_INTERVAL_MS
void ms_timer_init(uint32_t irq_priority)
void led_ui_type_stop_all(led_ui_seq_t type)
Stop all sequence of a particular type.
dev_id_t * dev_id_get(void)
Gets a pointer to the location where the Device ID is stored.
sensebe_config_t * sensebe_store_config_get_last_config()
void sensebe_ble_gap_params_init(void)
Generic Access Profile initialization. The device name, and the preferred connection parameters are s...
BLE advertising to get connected to an app.
void sensebe_store_config_check_fw_ver()
Function to check the major number of firmware if latest major number \ firmware version is greater t...
void device_tick_process(void)
The function to be called whenever the SoC wakes up to see if more than half the time of the current ...
void irq_msg_init(irq_msg_callbacks *cb_ptr)
#define SENSE_SLOW_TICK_INTERVAL_MS
void sensebe_tx_rx_add_ticks(uint32_t interval)
Function to handle add tick event.
void leds_init(void)
Initialize and blink the LEDs momentarily. To be used at the start of the program.
void irq_msg_process(void)
#define PHOTODIODE_LIGHT_SENSE_EN
void device_tick_switch_mode(device_tick_mode mode)
Switches from the fast to slow mode or vice versa.
int main(void)
Function for application main entry.
void sensebe_ble_adv_init(sensebe_ble_adv_data_t *sensebe_ble_adv_data)
Function to initializing the advertising.
#define APP_SCAN_RSP_DATA
void hal_wdt_init(uint32_t period_ms, void(*wdt_timeout_handler)(void))
#define CONN_SLOW_TICK_INTERVAL_MS
#define SENSE_FAST_TICK_INTERVAL_MS
void sensebe_tx_rx_init(sensebe_tx_rx_config_t *sensebe_rx_detect_config)
Function to initialize the Rx detect module.
void next_interval_handler(uint32_t interval)
The next interval handler is used for providing a periodic tick to be used by the various modules of ...
void irq_msg_push(irq_msg_types pushed_msg, void *more_data)
#define PHOTODIODE_LIGHT_SENSE
#define ADV_FAST_TICK_INTERVAL_MS