From c6b8384162c180e1efdad4eb67fc0992df437fba Mon Sep 17 00:00:00 2001 From: Pete Skeggs Date: Thu, 6 Jun 2024 15:53:25 -0700 Subject: [PATCH] samples: cellular: nrf_cloud_multi_service: Button press alert Extend the multi service sample by adding button handling. When the button is pressed, send an alert to the cloud. Signed-off-by: Pete Skeggs --- samples/cellular/nrf_cloud_multi_service/prj.conf | 1 + .../nrf_cloud_multi_service/src/application.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/samples/cellular/nrf_cloud_multi_service/prj.conf b/samples/cellular/nrf_cloud_multi_service/prj.conf index badde160d8a4..5da8ae42eff0 100644 --- a/samples/cellular/nrf_cloud_multi_service/prj.conf +++ b/samples/cellular/nrf_cloud_multi_service/prj.conf @@ -14,6 +14,7 @@ CONFIG_EVENTS=y CONFIG_PICOLIBC_IO_FLOAT=y CONFIG_RESET_ON_FATAL_ERROR=y CONFIG_NCS_SAMPLES_DEFAULTS=y +CONFIG_DK_LIBRARY=y # LED indication # Uncomment these to minimize LED state indication when power savings are necessary diff --git a/samples/cellular/nrf_cloud_multi_service/src/application.c b/samples/cellular/nrf_cloud_multi_service/src/application.c index d0ad956f0191..36904a3e4c5b 100644 --- a/samples/cellular/nrf_cloud_multi_service/src/application.c +++ b/samples/cellular/nrf_cloud_multi_service/src/application.c @@ -20,6 +20,7 @@ #include #include "location_tracking.h" #endif +#include #include "application.h" #include "temperature.h" #include "cloud_connection.h" @@ -322,6 +323,16 @@ static void test_counter_send(void) } } +static void button_handler(uint32_t button_state, uint32_t has_changed) +{ + if (has_changed & DK_BTN1_MSK) { + if ((button_state & DK_BTN1_MSK) == DK_BTN1_MSK) { + LOG_INF("Button pressed"); + (void)nrf_cloud_alert_send(ALERT_TYPE_MSG, 0, "Button pressed"); + } + } +} + static void print_reset_reason(void) { uint32_t reset_reason; @@ -352,6 +363,8 @@ void main_application_thread_fn(void) register_general_dev_msg_handler(handle_at_cmd_requests); } + dk_buttons_init(button_handler); + /* Wait for first connection before starting the application. */ (void)await_cloud_ready(K_FOREVER);