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_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 301000 99 #define SENSE_FAST_TICK_INTERVAL_MS 60 101 #define SENSE_SLOW_TICK_INTERVAL_MS 300000 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 = {
135 .cam_trigs[RADIO_ALL].pre_focus = 1,
136 .cam_trigs[RADIO_ALL].larger_value = 30,
137 .cam_trigs[RADIO_ALL].smaller_value = 0,
140 .timer_conf.oper_time.day_or_night = 1,
141 .timer_conf.oper_time.threshold = 0b0000000,
143 .cam_trigs[TIMER_ALL].larger_value = 0,
144 .cam_trigs[TIMER_ALL].smaller_value = 0,
145 .cam_trigs[TIMER_ALL].pre_focus = 0,
146 .timer_conf.timer_interval = 50,
150 .ir_tx_conf.oper_time.day_or_night = 1,
151 .ir_tx_conf.oper_time.threshold = 0b0000000,
152 .ir_tx_conf.is_enable = 1,
153 .ir_tx_conf.ir_tx_speed = 1,
154 .ir_tx_conf.ir_tx_pwr = 2,
161 sensebe_tx_config_t default_sensebe_tx_rx_config =
164 .cam_config.focus_pin_no = JACK_FOCUS_PIN,
165 .cam_config.trigger_pin_no = JACK_TRIGGER_PIN,
174 .sensebe_config = &sensebe_ble_default_config,
183 log_printf(
"WDT reset\n");
186 void prepare_init_ble_adv()
192 memcpy(&app_scan_rsp_data[23],
fw_ver_get(),
sizeof(fw_ver_t));
195 memcpy(&app_scan_rsp_data[5],
dev_id_get(),
sizeof(dev_id_t));
197 sensebe_ble_adv_data_t app_adv_data_struct =
199 .adv_data = app_adv_data,
200 .scan_rsp_data = app_scan_rsp_data,
214 static void ble_evt_handler(ble_evt_t * evt)
216 log_printf(
"ble evt %x\n", evt->header.evt_id);
217 switch (evt->header.evt_id)
219 case BLE_GAP_EVT_CONNECTED:
222 case BLE_GAP_EVT_DISCONNECTED:
225 case BLE_GAP_EVT_ADV_SET_TERMINATED:
228 case BLE_GAP_EVT_CONN_PARAM_UPDATE:
229 log_printf(
"sup time %d s, max intvl %d ms, min intvl %d ms, slave lat %d\n",
230 evt->evt.gap_evt.params.conn_param_update.conn_params.conn_sup_timeout/100,
231 (5*evt->evt.gap_evt.params.conn_param_update.conn_params.max_conn_interval)/4,
232 (5*evt->evt.gap_evt.params.conn_param_update.conn_params.min_conn_interval)/4,
233 evt->evt.gap_evt.params.conn_param_update.conn_params.slave_latency);
242 static void get_sensebe_config_t(sensebe_config_t *config)
254 log_printf(
"in %d\n", interval);
260 log_printf(
"Nxt Evt Hndlr : SENSING\n");
269 conn_count += interval;
286 log_printf(
"State change %d\n", new_state);
289 log_printf(
"new state same as current state\n");
298 sd_softdevice_disable();
299 log_printf(
"State Change : SENSING\n");
327 uint8_t is_sd_enabled;
328 sd_softdevice_is_enabled(&is_sd_enabled);
330 if(is_sd_enabled == 0)
335 prepare_init_ble_adv();
337 sensebe_sysinfo sysinfo;
338 memcpy(&sysinfo.id,
dev_id_get(),
sizeof(dev_id_t));
340 memcpy(&sysinfo.fw_ver,
fw_ver_get(),
sizeof(fw_ver_t));
379 log_printf(
"Act (0 = CROSS, 1= RELEASE) : %d\nStep : %d\n", act,step);
385 log_printf(
"fast\n");
406 NRF_POWER->GPREGRET = 0xB1;
407 log_printf(
"Trying to do system reset..!!");
408 uint8_t is_sd_enabled;
409 sd_softdevice_is_enabled(&is_sd_enabled);
410 if(is_sd_enabled == 0)
412 sd_nvic_SystemReset();
425 log_printf(
"slow\n");
449 hal_nop_delay_ms(600);
452 hal_nop_delay_ms(600);
464 log_printf(
"Reset because of ");
465 if(NRF_POWER->RESETREAS == 0)
467 log_printf(
"power on or brownout, ");
469 if(NRF_POWER->RESETREAS & POWER_RESETREAS_DIF_Msk)
471 log_printf(
"entering into debug interface from Sys OFF, ");
473 if(NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk)
475 log_printf(
"watchdog bite, ");
477 if(NRF_POWER->RESETREAS & POWER_RESETREAS_LOCKUP_Msk)
479 log_printf(
"CPU lockup, ");
481 if(NRF_POWER->RESETREAS & POWER_RESETREAS_OFF_Msk)
483 log_printf(
"wake up from SYS OFF by GPIO, ");
485 if(NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk)
487 log_printf(
"pin reset, ");
489 if(NRF_POWER->RESETREAS & POWER_RESETREAS_SREQ_Msk)
491 log_printf(
"software reset, ");
496 NRF_POWER->RESETREAS = (POWER_RESETREAS_DIF_Msk |
497 POWER_RESETREAS_DOG_Msk |
498 POWER_RESETREAS_LOCKUP_Msk |
499 POWER_RESETREAS_OFF_Msk |
500 POWER_RESETREAS_RESETPIN_Msk |
501 POWER_RESETREAS_SREQ_Msk);
504 #if DC_DC_CIRCUITRY == true //Defined in the board header file 505 NRF_POWER->DCDCEN = POWER_DCDCEN_DCDCEN_Enabled << POWER_DCDCEN_DCDCEN_Pos;
507 NRF_POWER->TASKS_LOWPWR = 1;
527 uint8_t is_sd_enabled;
528 sd_softdevice_is_enabled(&is_sd_enabled);
530 if(is_sd_enabled == 0)
549 log_printf(
"\n\nHello SenseBe World!\n");
563 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.
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