35 #include "hal_clocks.h" 36 #include "hal_nop_delay.h" 39 #include "common_util.h" 47 #include "lsm_testing_ble.h" 48 #include "hal_pin_analog_input.h" 49 #include "simple_adc.h" 51 #define SMOKE_DETECT_PIN 2 53 #define ANI_SMOKE_PIN PIN_TO_ANALOG_INPUT(SMOKE_DETECT_PIN) 55 int16_t x_data, y_data, z_data;
57 static uint32_t my_sqrt (uint32_t num)
59 float xn, xm, flag, temp;
65 xn = (xm + (num / xm)) / 2;
76 return (uint32_t) temp;
79 bool compare_percent (uint32_t data, uint32_t ref,
float per)
81 if ((ref - (ref * per / 100)) <= data && data <= (ref + (ref * per / 100)))
91 uint32_t avg_uint32_x100 (uint32_t * p_arr, uint32_t no_of_entries)
95 for(uint32_t cnt = 0; cnt < no_of_entries; cnt++)
99 avg = add/no_of_entries;
100 return (uint32_t)(avg * 100);
103 static mod_ble_data_t ble_data;
105 void lsm_100ms_handler ()
108 LSM6DS3_read_accl_data (&x_data, &y_data, &z_data);
109 x_data = (LSM6DS3_accelData_in_g(x_data));
110 x_data = (x_data * ((x_data > 0) - (x_data < 0)));
111 y_data = (LSM6DS3_accelData_in_g(y_data) );
112 y_data = (y_data * ((y_data > 0) - (y_data < 0)));
113 z_data = (LSM6DS3_accelData_in_g(z_data) );
114 z_data = (z_data * ((z_data > 0) - (z_data < 0)));
117 void ms_timer_handler ()
119 static uint32_t curr_res_acce = 0;
120 static uint32_t max_res_acce = 0;
121 static uint32_t res_acce_loc = 0;
122 static uint32_t arr_smoke_val[10];
123 static uint32_t curr_avg_smoke_val_x100 = 0;
124 lsm_100ms_handler ();
125 curr_res_acce = my_sqrt ((x_data * x_data) + (y_data * y_data) + (z_data * z_data))/1000;
127 if(curr_res_acce > max_res_acce)
129 max_res_acce = curr_res_acce;
131 if(res_acce_loc == 9)
133 ble_data.avg_acce = max_res_acce;
135 curr_avg_smoke_val_x100 = avg_uint32_x100 (arr_smoke_val, 10);
136 ble_data.avg_smoke = curr_avg_smoke_val_x100 / 100;
138 lsm_ble_update_status_byte (&ble_data);
139 res_acce_loc = (res_acce_loc + 1) % 10;
146 static void rgb_led_init(
void)
154 static void rgb_led_cycle(
void)
159 hal_nop_delay_ms(250);
163 hal_nop_delay_ms(250);
167 hal_nop_delay_ms(250);
182 uint8_t is_sd_enabled;
183 sd_softdevice_is_enabled(&is_sd_enabled);
185 if(is_sd_enabled == 0)
204 log_printf(
"Hello World from LSM6D..!!\n");
210 lsm_ble_stack_init ();
211 lsm_ble_gap_params_init ();
213 lsm_ble_adv_start (on_connect);
214 lsm_ble_service_init ();
uint32_t simple_adc_get_value(simple_adc_gain_t gain, simple_adc_input_t pin)
This function initializes the SAADC peripheral, gets an ADC value and then deinitializes The function...
#define LEDS_ACTIVE_STATE
void lfclk_init(lfclk_src_t lfclk_src)
Function to initialize the LF clock.
Repeated call of the timer.
#define MS_TIMER_TICKS_MS(ms)
void ms_timer_init(uint32_t irq_priority)
void ms_timer_start(ms_timer_num id, ms_timer_mode mode, uint64_t ticks, void(*handler)(void))
int main(void)
Function for application main entry.