Hi everyone,
I completed tutorials and i tried to get a value from characteristic and i tried to do something extra. But i am encountering a problem which i could't understand. I will share my code with a screenshot.
1) I wrote "0x12" to characteristic on nRF Connect. LED 2 turned on and LED 3 turned off.
2) I wrote "0x13" to characteristic on nRF Connect. LED 3 turned on and LED 2 turned off.
3) I tried to see "button_value" 's value while i was debugging but it shows nothing. If i add "button_value = 0;" in main function, "button_value" seems in Watch 1 as "0x00". I changed button_value manually "0x01" while i was debugging and LED 4 start to toggle.
So, the program entering if condition but it is not changing "button_value" by doing nRF Connect.
P.S : timer_timeout_handler function is in main.c file.(i forgot to point out in screenshot)
i declared the variable "static int button_value;" in our_service.h
Event Funciton (in our_service.c):
void ble_our_service_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
ble_gatts_evt_write_t * p_evt_write;
ble_os_t * p_our_service =(ble_os_t *) p_context;
// OUR_JOB: Step 3.D Implement switch case handling BLE events related to our service.
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
p_our_service->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
break;
case BLE_GAP_EVT_DISCONNECTED:
p_our_service->conn_handle = BLE_CONN_HANDLE_INVALID;
break;
case BLE_GATTS_EVT_WRITE:
p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
if(p_evt_write->handle == p_our_service->char_handles_3.value_handle)
{
if(*p_evt_write->data == 0x12)
{
button_value = 1;
nrf_gpio_pin_clear(14);
nrf_gpio_pin_set(15);
}
else if(*p_evt_write->data == 0x13)
{
button_value = 0;
nrf_gpio_pin_clear(15);
nrf_gpio_pin_set(14);
}
}
break;
default:
// No implementation needed.
break;
}
}Time out handler function(in main.c):
static void timer_timeout_handler(void * p_context)
{
// OUR_JOB: Step 3.F, Update temperature and characteristic value.
int32_t temperature = 0;
sd_temp_get(&temperature);
voltage = 0;
voltage = saadc_measure();
if(voltage < 0)
voltage = 0;
our_temperature_characteristic_update(&m_our_service, &voltage);
our_temperature_characteristic_update_2(&m_our_service, &temperature);
// our_temperature_characteristic_update_3(&m_our_service, &button_value);
// nrf_gpio_pin_toggle(LED_4);
if(button_value == 1)
{
nrf_gpio_pin_clear(LED_4);
}
}
