Skip to content

Commit 8e06a61

Browse files
committed
feat(app/hmi-generic): Listen on events and play a notification sound
1 parent 9374c9e commit 8e06a61

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

applications/hmi-generic/app.c

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <main.h>
10+
#include <interfaces/event.h>
1011
#include "app.h"
1112

1213
#define MODULE_NAME "hmi"
@@ -47,10 +48,17 @@ static void com_task(void *p) {
4748
static void input_task(void *p) {
4849
App *self = p;
4950

50-
5151
while (true) {
52-
53-
vTaskDelay(1000);
52+
enum event_type type = EV_TYPE_NONE;
53+
enum event_code code = EV_CODE_NONE;
54+
int32_t value = 0;
55+
56+
if (self->input->vmt->listen(self->input, &type, &code, &value) == EV_RET_OK) {
57+
if (value == 1) {
58+
/* On key down. */
59+
self->speaker->vmt->start(self->speaker);
60+
}
61+
}
5462
}
5563
vTaskDelete(NULL);
5664
}
@@ -72,6 +80,19 @@ app_ret_t app_init(App *self) {
7280
return APP_RET_FAILED;
7381
}
7482

83+
/** @todo configure which input device to use. */
84+
self->input = NULL;
85+
if (iservicelocator_query_type_id(locator, ISERVICELOCATOR_TYPE_EVENT, 0, (Interface **)&self->input) != ISERVICELOCATOR_RET_OK) {
86+
u_log(system_log, LOG_TYPE_ERROR, U_LOG_MODULE_PREFIX("no suitable input device found"));
87+
return APP_RET_FAILED;
88+
}
89+
90+
self->speaker = NULL;
91+
if (iservicelocator_query_type_id(locator, ISERVICELOCATOR_TYPE_WAVEFORM_SINK, 0, (Interface **)&self->speaker) != ISERVICELOCATOR_RET_OK) {
92+
u_log(system_log, LOG_TYPE_ERROR, U_LOG_MODULE_PREFIX("no suitable speaker found"));
93+
return APP_RET_FAILED;
94+
}
95+
7596
xTaskCreate(com_task, "hmi-com", configMINIMAL_STACK_SIZE + 256, (void *)self, 1, &(self->com_task));
7697
if (self->com_task == NULL) {
7798
u_log(system_log, LOG_TYPE_ERROR, U_LOG_MODULE_PREFIX("cannot create application com task"));

applications/hmi-generic/app.h

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <interfaces/datagram.h>
1212
#include <interfaces/fb.h>
1313
#include <interfaces/i2c-bus.h>
14+
#include <interfaces/event.h>
15+
#include <interfaces/waveform-sink.h>
1416
#include <services/nbus2/nbus2.h>
1517

1618

@@ -24,6 +26,8 @@ typedef struct {
2426
TaskHandle_t input_task;
2527
Fb *fb;
2628
I2cBus *i2c;
29+
Event *input;
30+
WaveformSink *speaker;
2731
} App;
2832

2933

0 commit comments

Comments
 (0)