zephyr-configurator/snippets/bluetooth/button/code1.txt

22 lines
498 B
Plaintext
Raw Permalink Normal View History

2023-09-08 11:28:04 +00:00
static void button_callback(const struct device *gpiob, struct gpio_callback *cb, uint32_t pins)
{
int err;
LOG_INF("Button pressed");
if (ble_conn) {
if (notify_enable) {
err = bt_gatt_notify(NULL, &stsensor_svc.attrs[4], &but_val, sizeof(but_val));
if (err) {
LOG_ERR("Notify error: %d", err);
} else {
LOG_INF("Send notify ok");
but_val = (but_val == 0) ? 0x100 : 0;
}
} else {
LOG_INF("Notify not enabled");
}
} else {
LOG_INF("BLE not connected");
}
}