File tree Expand file tree Collapse file tree 5 files changed +46
-0
lines changed Expand file tree Collapse file tree 5 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ target_sources(app PRIVATE
11
11
src/main.c
12
12
src/buzzer.c
13
13
src/ledui.c
14
+ src/user_button.c
14
15
)
Original file line number Diff line number Diff line change 1
1
CONFIG_LOG=y
2
2
CONFIG_PWM=y
3
3
CONFIG_USER_ALERTS=y
4
+ CONFIG_USER_BUTTON_ACTIONS=y
Original file line number Diff line number Diff line change 2
2
#include <zephyr/logging/log.h>
3
3
#include <zephyr/drivers/pwm.h>
4
4
#include <user_alerts/user_alerts.h>
5
+ #include <user_button_actions/user_button_actions.h>
5
6
#include <morse_beep_codes.h>
6
7
7
8
LOG_MODULE_REGISTER (buzzer );
@@ -29,8 +30,20 @@ static struct user_alerts_channel _buzzer_ch = {
29
30
.pattern = NULL ,
30
31
};
31
32
33
+ void buzzer_btn_action_handler (struct user_button_actions_channel * ch )
34
+ {
35
+ if (ch -> result .code == eUSER_BUTTON_CLICK_AND_HOLD ) {
36
+ user_alerts_channel_play (& _buzzer_ch , & _croxel_inc_morse_beeps , true);
37
+ }
38
+ }
39
+
40
+ SLL_LISTENER_DEFINE_NODE (user_button_actions ,
41
+ buzzer_btn_action_listener ,
42
+ .handler = buzzer_btn_action_handler );
43
+
32
44
int play_bootup_buzzer_beeps (void )
33
45
{
46
+ SLL_LISTENER_ADD_NODE (user_button_actions , buzzer_btn_action_listener );
34
47
user_alerts_channel_init_timer (& _buzzer_ch );
35
48
user_alerts_channel_play (& _buzzer_ch , & _zephyr_morse_beeps , true);
36
49
return 0 ;
Original file line number Diff line number Diff line change 2
2
#include <zephyr/logging/log.h>
3
3
#include <user_alerts/user_alerts.h>
4
4
#include <zephyr/drivers/gpio.h>
5
+ #include <user_button_actions/user_button_actions.h>
5
6
6
7
LOG_MODULE_REGISTER (ledui );
7
8
@@ -56,10 +57,23 @@ static struct user_alerts_channel _bi_led_ch = {
56
57
.pattern = NULL ,
57
58
};
58
59
60
+ void led_btn_action_handler (struct user_button_actions_channel * ch )
61
+ {
62
+ if (ch -> result .code == eUSER_BUTTON_CLICK ) {
63
+ user_alerts_channel_play (& _bi_led_ch , & _btn_click_bi_led_pattern , true);
64
+ }
65
+ }
66
+
67
+ SLL_LISTENER_DEFINE_NODE (user_button_actions ,
68
+ led_btn_action_listener ,
69
+ .handler = led_btn_action_handler );
70
+
59
71
int play_bootup_led_blinks (void )
60
72
{
61
73
int err ;
62
74
75
+ SLL_LISTENER_ADD_NODE (user_button_actions , led_btn_action_listener );
76
+
63
77
err = gpio_is_ready_dt (& _bi_led_io .led1 );
64
78
if (!err ) {
65
79
LOG_ERR ("Led1 is not ready" );
Original file line number Diff line number Diff line change
1
+ #include <zephyr/kernel.h>
2
+ #include <zephyr/logging/log.h>
3
+ #include <user_button_actions/user_button_actions.h>
4
+
5
+ LOG_MODULE_REGISTER (user_button );
6
+
7
+ static struct user_button_actions_channel btn = {
8
+ .btn = GPIO_DT_SPEC_GET (DT_ALIAS (sw0 ), gpios ),
9
+ };
10
+
11
+ int user_button_setup (void )
12
+ {
13
+ user_button_actions_start_monitor (& btn );
14
+ return 0 ;
15
+ }
16
+
17
+ SYS_INIT (user_button_setup , APPLICATION , 99 );
You can’t perform that action at this time.
0 commit comments