aboutsummaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
Diffstat (limited to 'binding')
-rw-r--r--binding/binding.c3
-rw-r--r--binding/microphone/microphone.c125
-rw-r--r--binding/microphone/microphone.h3
3 files changed, 122 insertions, 9 deletions
diff --git a/binding/binding.c b/binding/binding.c
index 1d19fdb..7034e82 100644
--- a/binding/binding.c
+++ b/binding/binding.c
@@ -70,6 +70,9 @@ static const afb_verb_t verbs[] = {
{.verb = "amplifier_master_volume_set", .session = AFB_SESSION_NONE, .callback = amplifier_master_vol_set_api, .auth = NULL},
{.verb = "microphone_mode_set", .session = AFB_SESSION_NONE, .callback = microphone_mode_set_api, .auth = NULL},
{.verb = "microphone_doa_get", .session = AFB_SESSION_NONE, .callback = microphone_doa_get_api, .auth = NULL},
+ {.verb = "microphone_doa_set", .session = AFB_SESSION_NONE, .callback = microphone_led_dir_set_api, .auth = NULL},
+ {.verb = "microphone_static_color_set", .session = AFB_SESSION_NONE, .callback = microphone_static_ledcolor_set_api, .auth = NULL},
+ {.verb = "microphone_is_available", .session = AFB_SESSION_NONE, .callback = microphone_is_available_api, .auth = NULL},
{NULL}
};
diff --git a/binding/microphone/microphone.c b/binding/microphone/microphone.c
index 344fbd7..d6d22a7 100644
--- a/binding/microphone/microphone.c
+++ b/binding/microphone/microphone.c
@@ -25,6 +25,9 @@
#include "wrap-unicens.h"
#include "microphone.h"
+#define HB(value) ((uint8_t)((uint16_t)(value) >> 8))
+#define LB(value) ((uint8_t)((uint16_t)(value) & (uint16_t)0xFFU))
+
/*****************************************************************************
* types
*/
@@ -38,10 +41,11 @@ enum microphone_mode
MICROPHONE_MODE_ERROR = 4,
MICROPHONE_MODE_WAKING = 5,
MICROPHONE_MODE_ENDING = 6,
- MICROPHONE_MODE_CYLON = 7,
- MICROPHONE_MODE_RAINBOW = 8,
- MICROPHONE_MODE_WHEEL = 9,
- MICROPHONE_MODE_UNKNOWN = 10
+ MICROPHONE_MODE_STATIC = 7,
+ MICROPHONE_MODE_CYLON = 8,
+ MICROPHONE_MODE_RAINBOW = 9,
+ MICROPHONE_MODE_WHEEL = 10,
+ MICROPHONE_MODE_UNKNOWN = 11
};
/*****************************************************************************
@@ -57,12 +61,14 @@ static void microphone_doa_status(uint16_t data_sz, uint8_t *data_ptr);
*/
#define NODE_ID ((uint16_t)0x520U)
-#define MSG_ID_MODE 0x1001U
-#define MSG_ID_DOA 0x1003U
+#define MSG_ID_MODE 0x1001U /* set LED mode */
+#define MSG_ID_LED_DIR 0x1002U /* set LED direction*/
+#define MSG_ID_DOA 0x1003U /* get audio direction */
+#define MSG_ID_LED_COL 0x1006U /* set static LED color */
#define MSG_OP_SET 0x00U
#define MSG_OP_GET 0x01U
-#define MSG_MAX_PAYLOAD_SZ 2U
+#define MSG_MAX_PAYLOAD_SZ 10U
static uint8_t _tx_payload[MSG_MAX_PAYLOAD_SZ];
static bool _available = false;
static bool _doa_running = false;
@@ -74,7 +80,7 @@ static afb_req_t _req_doa_get = NULL;
extern void microphone_availablility_changed(uint16_t node_id, bool available) {
if (node_id == NODE_ID) {
- AFB_API_DEBUG(afbBindingRoot, "%s: amplifier new availability=%d", __func__, available);
+ AFB_API_DEBUG(afbBindingRoot, "%s: microphone new availability=%d", __func__, available);
_available = available;
_doa_running = false;
}
@@ -106,7 +112,7 @@ static int microphone_mode_set(enum microphone_mode mode) {
if (mode < MICROPHONE_MODE_UNKNOWN) {
_tx_payload[0] = MSG_OP_SET;
_tx_payload[1] = (uint8_t)mode;
- wrap_ucs_sendmessage_sync(NODE_ID, MSG_ID_MODE, _tx_payload, MSG_MAX_PAYLOAD_SZ);
+ wrap_ucs_sendmessage_sync(NODE_ID, MSG_ID_MODE, _tx_payload, 2U);
}
else {
AFB_API_NOTICE(afbBindingRoot, "%s: given mode is unknown", __func__);
@@ -151,6 +157,37 @@ static void microphone_doa_status(uint16_t data_sz, uint8_t *data_ptr) {
}
}
+static int microphone_led_direction_set(uint16_t direction) {
+ AFB_API_NOTICE(afbBindingRoot, "microphone_led_direction_set executed");
+ if (_available == false) {
+ AFB_API_NOTICE(afbBindingRoot, "%s: node is not available", __func__);
+ return -1;
+ }
+
+ _tx_payload[0] = MSG_OP_SET;
+ _tx_payload[1] = HB(direction);
+ _tx_payload[2] = LB(direction);
+ wrap_ucs_sendmessage_sync(NODE_ID, MSG_ID_LED_DIR, _tx_payload, 3U);
+
+ return 0;
+}
+
+static int microphone_static_ledcolor_set(uint8_t red, uint8_t green, uint8_t blue) {
+ AFB_API_NOTICE(afbBindingRoot, "microphone_static_led_color_set executed");
+ if (_available == false) {
+ AFB_API_NOTICE(afbBindingRoot, "%s: node is not available", __func__);
+ return -1;
+ }
+
+ _tx_payload[0] = MSG_OP_SET;
+ _tx_payload[1] = red;
+ _tx_payload[2] = green;
+ _tx_payload[3] = blue;
+ wrap_ucs_sendmessage_sync(NODE_ID, MSG_ID_LED_COL, _tx_payload, 4U);
+
+ return 0;
+}
+
/*****************************************************************************
* JSON API
*/
@@ -186,6 +223,9 @@ extern void microphone_mode_set_api(afb_req_t request) {
else if (strcmp(str_mode, "ending") == 0) {
mic_mode = MICROPHONE_MODE_ENDING;
}
+ else if (strcmp(str_mode, "static") == 0) {
+ mic_mode = MICROPHONE_MODE_STATIC;
+ }
else if (strcmp(str_mode, "cylon") == 0) {
mic_mode = MICROPHONE_MODE_CYLON;
}
@@ -220,3 +260,70 @@ extern void microphone_doa_get_api(afb_req_t request) {
_req_doa_get = afb_req_addref(request);
}
}
+
+extern void microphone_led_dir_set_api(afb_req_t request) {
+ int direction = 0;
+ struct json_object* j_obj = afb_req_json(request);
+
+ AFB_API_NOTICE(afbBindingRoot, "UNICENS-CONTROLLER: %s:%s", __func__, json_object_get_string(j_obj));
+
+ if (wrap_json_unpack(j_obj, "{s:i}", "value", &direction) == 0) {
+ AFB_API_NOTICE(afbBindingRoot, "UNICENS-CONTROLLER: decoded value=%d", direction);
+
+ if ((direction >= 0) && (direction < 360)) {
+ if (microphone_led_direction_set((uint16_t)direction) == 0) {
+ afb_req_success(request, NULL, NULL);
+ }
+ else {
+ afb_req_fail(request, "Call failed. Microphone not available?", NULL);
+ }
+ }
+ else {
+ afb_req_fail(request, "Argument 'value' not in range 0...359.", NULL);
+ }
+ }
+ else {
+ afb_req_fail(request, "Missing argument 'value'", NULL);
+ }
+}
+
+extern void microphone_static_ledcolor_set_api(afb_req_t request) {
+ int red, green, blue = 0;
+ struct json_object* j_obj = afb_req_json(request);
+
+ AFB_API_NOTICE(afbBindingRoot, "UNICENS-CONTROLLER: %s:%s", __func__, json_object_get_string(j_obj));
+
+ if (wrap_json_unpack(j_obj, "{s:i, s:i, s:i}", "red", &red, "green", &green, "blue", &blue) == 0) {
+ AFB_API_NOTICE(afbBindingRoot, "UNICENS-CONTROLLER: decoded rgb=%d,%d,%d", red, green, blue);
+
+ if ( (red >= 0) && (red <= 0xFF) && (green >= 0) && (green <= 0xFF) && (blue >= 0) && (blue <= 0xFF)) {
+ if (microphone_static_ledcolor_set((uint8_t)red, (uint8_t)green, (uint8_t)blue) == 0) {
+ afb_req_success(request, NULL, NULL);
+ }
+ else {
+ afb_req_fail(request, "Call failed. Microphone not available?", NULL);
+ }
+ }
+ else {
+ afb_req_fail(request, "Argument 'value' not in range 0..255.", NULL);
+ }
+ }
+ else {
+ afb_req_fail(request, "Error while parsing arguments.", NULL);
+ }
+}
+
+extern void microphone_is_available_api(afb_req_t request) {
+ struct json_object* j_obj = afb_req_json(request);
+ struct json_object* j_resp = json_object_new_object();
+
+ AFB_API_NOTICE(afbBindingRoot, "UNICENS-CONTROLLER: %s:%s", __func__, json_object_get_string(j_obj));
+
+ if (j_resp != NULL) {
+ wrap_json_pack(&j_resp, "{s:b}", "available", (int)_available);
+ afb_req_reply(request, j_resp, NULL, "response successful");
+ }
+ else {
+ afb_req_fail(request, "Cannot allocate response object.", NULL);
+ }
+}
diff --git a/binding/microphone/microphone.h b/binding/microphone/microphone.h
index 27ee4ea..bc9e7a9 100644
--- a/binding/microphone/microphone.h
+++ b/binding/microphone/microphone.h
@@ -26,3 +26,6 @@ extern void microphone_message_received(uint16_t node, uint16_t msg_id, uint16_t
/* JSON API */
extern void microphone_mode_set_api(afb_req_t request);
extern void microphone_doa_get_api(afb_req_t request);
+extern void microphone_led_dir_set_api(afb_req_t request);
+extern void microphone_static_ledcolor_set_api(afb_req_t request);
+extern void microphone_is_available_api(afb_req_t request);