Skip to content

Commit

Permalink
[CXRD-19] Added LED/Buzzer feedback on button actions
Browse files Browse the repository at this point in the history
- play led pattern on button click
- play croxel morse on button click_n_hold

Signed-off-by: Anuj Pathak <[email protected]>
  • Loading branch information
cx-anuj-pathak committed Jul 30, 2024
1 parent b8ddf29 commit dc50309
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ target_sources(app PRIVATE
src/main.c
src/buzzer.c
src/ledui.c
src/user_button.c
)
1 change: 1 addition & 0 deletions app/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_LOG=y
CONFIG_PWM=y
CONFIG_USER_ALERTS=y
CONFIG_USER_BUTTON_ACTIONS=y
13 changes: 13 additions & 0 deletions app/src/buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <zephyr/logging/log.h>
#include <zephyr/drivers/pwm.h>
#include <user_alerts/user_alerts.h>
#include <user_button_actions/user_button_actions.h>
#include <morse_beep_codes.h>

LOG_MODULE_REGISTER(buzzer);
Expand Down Expand Up @@ -29,8 +30,20 @@ static struct user_alerts_channel _buzzer_ch = {
.pattern = NULL,
};

void buzzer_btn_action_handler(struct user_button_actions_channel *ch)
{
if (ch->result.code == eUSER_BUTTON_CLICK_AND_HOLD) {
user_alerts_channel_play(&_buzzer_ch, &_croxel_inc_morse_beeps, true);
}
}

SLL_LISTENER_DEFINE_NODE(user_button_actions,
buzzer_btn_action_listener,
.handler = buzzer_btn_action_handler);

int play_bootup_buzzer_beeps(void)
{
SLL_LISTENER_ADD_NODE(user_button_actions, buzzer_btn_action_listener);
user_alerts_channel_init_timer(&_buzzer_ch);
user_alerts_channel_play(&_buzzer_ch, &_zephyr_morse_beeps, true);
return 0;
Expand Down
14 changes: 14 additions & 0 deletions app/src/ledui.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <zephyr/logging/log.h>
#include <user_alerts/user_alerts.h>
#include <zephyr/drivers/gpio.h>
#include <user_button_actions/user_button_actions.h>

LOG_MODULE_REGISTER(ledui);

Expand Down Expand Up @@ -56,10 +57,23 @@ static struct user_alerts_channel _bi_led_ch = {
.pattern = NULL,
};

void led_btn_action_handler(struct user_button_actions_channel *ch)
{
if (ch->result.code == eUSER_BUTTON_CLICK) {
user_alerts_channel_play(&_bi_led_ch, &_btn_click_bi_led_pattern, true);
}
}

SLL_LISTENER_DEFINE_NODE(user_button_actions,
led_btn_action_listener,
.handler = led_btn_action_handler);

int play_bootup_led_blinks(void)
{
int err;

SLL_LISTENER_ADD_NODE(user_button_actions, led_btn_action_listener);

err = gpio_is_ready_dt(&_bi_led_io.led1);
if (!err) {
LOG_ERR("Led1 is not ready");
Expand Down
17 changes: 17 additions & 0 deletions app/src/user_button.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <user_button_actions/user_button_actions.h>

LOG_MODULE_REGISTER(user_button);

static struct user_button_actions_channel btn = {
.btn = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios),
};

int user_button_setup(void)
{
user_button_actions_start_monitor(&btn);
return 0;
}

SYS_INIT(user_button_setup, APPLICATION, 99);

0 comments on commit dc50309

Please sign in to comment.