summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2019-12-11 22:22:01 +0000
committerMatt Ranostay <matt.ranostay@konsulko.com>2019-12-14 11:48:38 -0800
commitbcfa8087eafcf4d96fc70eaa10afdce4dcfd3655 (patch)
treea769ad73afff343905e55ab68bb9b6313335e6e6 /binding
parent9b5ca97855494c9f9c4c80427400539d71c65759 (diff)
Initial steering wheel event support
Add initial basic support for next/previous events from signal composer, mapping them to seek forward/back. More work will be required to handle the issues around both mediaplayer and radio both being running and differentiating which should handle the events. Additionally, complete transition to binding version 3 to clean things up. Bug-AGL: SPEC-3046 Change-Id: I251fa461c96dba584a3fe0069bab4fd2e54701ad Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r--binding/CMakeLists.txt2
-rw-r--r--binding/radio-binding.c67
2 files changed, 65 insertions, 4 deletions
diff --git a/binding/CMakeLists.txt b/binding/CMakeLists.txt
index 8f5b43a..75b30bf 100644
--- a/binding/CMakeLists.txt
+++ b/binding/CMakeLists.txt
@@ -1,6 +1,6 @@
###########################################################################
# Copyright 2015, 2016, 2017 IoT.bzh
-# Copyright (C) 2018 Konsulko Group
+# Copyright (C) 2018, 2019 Konsulko Group
#
# author: Fulup Ar Foll <fulup@iot.bzh>
# contrib: Romain Forlot <romain.forlot@iot.bzh>
diff --git a/binding/radio-binding.c b/binding/radio-binding.c
index 1dae5da..de89207 100644
--- a/binding/radio-binding.c
+++ b/binding/radio-binding.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 Konsulko Group
+ * Copyright (C) 2017, 2019 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
#include <unistd.h>
#include <sys/types.h>
#include <json-c/json.h>
-
#include <afb/afb-binding.h>
#include "radio_impl.h"
@@ -37,6 +36,13 @@ static afb_event_t freq_event;
static afb_event_t scan_event;
static afb_event_t status_event;
+static const char *signalcomposer_events[] = {
+ "event.media.next",
+ "event.media.previous",
+ "event.media.mode",
+ NULL,
+};
+
static void freq_callback(uint32_t frequency, void *data)
{
json_object *jresp = json_object_new_object();
@@ -502,7 +508,40 @@ static const afb_verb_t verbs[]= {
{ }
};
-static int init()
+static void onevent(afb_api_t api, const char *event, struct json_object *object)
+{
+ json_object *tmp = NULL;
+ const char *uid;
+ const char *value;
+
+ json_object_object_get_ex(object, "uid", &tmp);
+ if (tmp == NULL)
+ return;
+
+ uid = json_object_get_string(tmp);
+ if (strncmp(uid, "event.media.", 12))
+ return;
+
+ json_object_object_get_ex(object, "value", &tmp);
+ if (tmp == NULL)
+ return;
+
+ value = json_object_get_string(tmp);
+ if (strncmp(value, "true", 4))
+ return;
+
+ if (!strcmp(uid, "event.media.next")) {
+ radio_impl_ops->scan_start(SCAN_FORWARD, scan_callback, NULL);
+ } else if (!strcmp(uid, "event.media.previous")) {
+ radio_impl_ops->scan_start(SCAN_BACKWARD, scan_callback, NULL);
+ } else if (!strcmp(uid, "event.media.mode")) {
+ // Do nothing ATM
+ } else {
+ AFB_WARNING("Unhandled signal-composer uid '%s'", uid);
+ }
+}
+
+static int init(afb_api_t api)
{
// Look for RTL-SDR USB adapter
radio_impl_ops = &rtlsdr_impl_ops;
@@ -522,6 +561,26 @@ static int init()
return rc;
}
+ rc = afb_daemon_require_api("signal-composer", 1);
+ if (rc) {
+ AFB_WARNING("unable to initialize signal-composer binding");
+ } else {
+ const char **tmp = signalcomposer_events;
+ json_object *args = json_object_new_object();
+ json_object *signals = json_object_new_array();
+
+ while (*tmp) {
+ json_object_array_add(signals, json_object_new_string(*tmp++));
+ }
+ json_object_object_add(args, "signal", signals);
+ if(json_object_array_length(signals)) {
+ afb_api_call_sync(api, "signal-composer", "subscribe",
+ args, NULL, NULL, NULL);
+ } else {
+ json_object_put(args);
+ }
+ }
+
// Initialize event structures
freq_event = afb_daemon_make_event("frequency");
scan_event = afb_daemon_make_event("station_found");
@@ -533,6 +592,8 @@ static int init()
const afb_binding_t afbBindingExport = {
.info = "radio service",
.api = "radio",
+ .specification = "Radio API",
.verbs = verbs,
+ .onevent = onevent,
.init = init,
};