diff options
author | Tobias Jahnke <tjahnk@users.noreply.github.com> | 2017-11-02 10:12:37 +0100 |
---|---|---|
committer | Tobias Jahnke <tjahnk@users.noreply.github.com> | 2017-11-02 10:22:15 +0100 |
commit | 43034ac1a9b5dab3b945ef3fd5b3710751a97cd8 (patch) | |
tree | af10ae26ddd1b54687c76c73fca9ca7dafb575ee /MOST_UNICENS/hal_most_unicens.c | |
parent | b4b260d8ce7f2c7d499f91f56cc81bd8e3fc1892 (diff) |
Now supports initial request of sound card values
Diffstat (limited to 'MOST_UNICENS/hal_most_unicens.c')
-rw-r--r-- | MOST_UNICENS/hal_most_unicens.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/MOST_UNICENS/hal_most_unicens.c b/MOST_UNICENS/hal_most_unicens.c index b853d86..775f2c4 100644 --- a/MOST_UNICENS/hal_most_unicens.c +++ b/MOST_UNICENS/hal_most_unicens.c @@ -34,44 +34,48 @@ static int master_volume; static json_bool master_switch; static int pcm_volume[PCM_MAX_CHANNELS]; -static void unicens_request_card_values_cb(void *closure, int status, struct json_object *j_response) { +static void unicens_apply_card_value(void *closure, struct json_object *j_obj){ - json_object *j_obj; - int num_id; + int num_id = 0; int values[6]; - AFB_INFO("unicens_request_card_values_cb: closure=%p status=%d, res=%s", closure, status, json_object_to_json_string(j_response)); - - json_object_object_get_ex(j_response, "response", &j_obj); - - if (json_object_is_type(j_obj, json_type_object)) { - - } - else if (json_object_is_type(j_obj, json_type_array)) { - AFB_ERROR("unicens_request_card_values_cb: array not handled yet"); - return; - } - else { - AFB_ERROR("unicens_request_card_values_cb: unknown response type"); - return; + /* apply master volume */ + if (wrap_json_unpack(j_obj, "{s:i, s:[i!]}", "id", &num_id, "val", + &values[0]) + == 0) { + if (num_id == 1) { + AFB_NOTICE("unicens_apply_card_value: num_id: %d, value: %d", + num_id, + values[0]); + wrap_volume_master(values[0]); + return; + } } - + if (wrap_json_unpack(j_obj, "{s:i, s:[iiiiii!]}", "id", &num_id, "val", &values[0], &values[1], &values[2], &values[3], &values[4], &values[5]) == 0) { - AFB_NOTICE("unicens_request_card_values_cb: success, num id:%d", num_id); - } - else { - AFB_ERROR("unicens_request_card_values_cb: unpack failure"); - return; + if (num_id == 2) { + AFB_NOTICE("unicens_apply_card_value: success, num_id: %d", num_id); + wrap_volume_pcm(&values[0], 6); + return; + } } -#if 0 - if (num_id == 2) { - wrap_volume_pcm(&values[0], 6); - } -#endif + AFB_ERROR("unicens_apply_card_value: no card value applied"); +} + + +static void unicens_request_card_values_cb(void *closure, int status, struct json_object *j_response) { + + json_object *j_obj; + AFB_INFO("unicens_request_card_values_cb: closure=%p status=%d, res=%s", closure, status, json_object_to_json_string(j_response)); + + if (json_object_object_get_ex(j_response, "response", &j_obj)) { + + wrap_json_optarray_for_all(j_obj, &unicens_apply_card_value, NULL); + } } __attribute__ ((unused)) static void unicens_request_card_values(const char* dev_id) { @@ -209,7 +213,7 @@ STATIC int unicens_service_init() { } /* request of initial card values */ - /* unicens_request_card_values(ALSA_DEVICE_ID); */ + unicens_request_card_values(ALSA_DEVICE_ID); OnErrorExit: AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING done.."); |