summaryrefslogtreecommitdiffstats
path: root/HAL-afb
diff options
context:
space:
mode:
authorTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-11 09:22:38 +0200
committerTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-16 16:00:50 +0200
commit3d4ecfd96e63d4fbc719e4be06e022a6811b0c1e (patch)
tree351064b91588e3d7b3c191bf93fe430c05f7d316 /HAL-afb
parenteb6b00b52432941cf081a3b511c70e758f6a7213 (diff)
MOST ALSA mixer controls now mapped to UNCENS I2C commands
Diffstat (limited to 'HAL-afb')
-rw-r--r--HAL-afb/hal-most-unicens/hal_most_unicens.c11
-rw-r--r--HAL-afb/hal-most-unicens/wrap_unicens.c2
-rw-r--r--HAL-afb/hal-most-unicens/wrap_volume.c53
-rw-r--r--HAL-afb/hal-most-unicens/wrap_volume.h2
4 files changed, 60 insertions, 8 deletions
diff --git a/HAL-afb/hal-most-unicens/hal_most_unicens.c b/HAL-afb/hal-most-unicens/hal_most_unicens.c
index ace9399..a5971fb 100644
--- a/HAL-afb/hal-most-unicens/hal_most_unicens.c
+++ b/HAL-afb/hal-most-unicens/hal_most_unicens.c
@@ -23,11 +23,11 @@
#include "wrap_unicens.h"
#include "wrap_volume.h"
+#define PCM_MAX_CHANNELS 6
+
static int master_volume;
static json_bool master_switch;
-static int pcm_volume[6];
-
-/*static uint8_t test[3] = {0x07,0x03,0xFF};*/
+static int pcm_volume[PCM_MAX_CHANNELS];
void unicens_master_vol_cb(halCtlsEnumT tag, alsaHalCtlMapT *control, void* handle, json_object *j_obj) {
@@ -35,9 +35,7 @@ void unicens_master_vol_cb(halCtlsEnumT tag, alsaHalCtlMapT *control, void* hand
if (wrap_json_unpack(j_obj, "[i!]", &master_volume) == 0) {
AFB_NOTICE("master_volume: %s, value=%d", j_str, master_volume);
- /*wrap_ucs_i2cwrite(0x270, test, 3);
- wrap_ucs_i2cwrite(0x271, test, 3);
- wrap_ucs_i2cwrite(0x272, test, 3);*/
+ wrap_volume_master(master_volume);
}
else {
AFB_NOTICE("master_volume: INVALID STRING %s", j_str);
@@ -63,6 +61,7 @@ void unicens_pcm_vol_cb(halCtlsEnumT tag, alsaHalCtlMapT *control, void* handle,
if (wrap_json_unpack(j_obj, "[iiiiii!]", &pcm_volume[0], &pcm_volume[1], &pcm_volume[2], &pcm_volume[3],
&pcm_volume[4], &pcm_volume[5]) == 0) {
AFB_NOTICE("pcm_vol: %s", j_str);
+ wrap_volume_pcm(pcm_volume, PCM_MAX_CHANNELS/*array size*/);
}
else {
AFB_NOTICE("pcm_vol: INVALID STRING %s", j_str);
diff --git a/HAL-afb/hal-most-unicens/wrap_unicens.c b/HAL-afb/hal-most-unicens/wrap_unicens.c
index 2bd1e91..0cac86b 100644
--- a/HAL-afb/hal-most-unicens/wrap_unicens.c
+++ b/HAL-afb/hal-most-unicens/wrap_unicens.c
@@ -191,7 +191,7 @@ OnErrorExit:
static void wrap_ucs_i2cwrite_cb(void *closure, int status, struct json_object *j_result) {
- AFB_NOTICE("wrap_ucs_i2cwrite_cb: closure=%p status=%d, res=%s", closure, status, json_object_to_json_string(j_result));
+ AFB_DEBUG("wrap_ucs_i2cwrite_cb: closure=%p status=%d, res=%s", closure, status, json_object_to_json_string(j_result));
if (closure) {
async_job_t *job_ptr = (async_job_t *)closure;
diff --git a/HAL-afb/hal-most-unicens/wrap_volume.c b/HAL-afb/hal-most-unicens/wrap_volume.c
index 438704f..cf70647 100644
--- a/HAL-afb/hal-most-unicens/wrap_volume.c
+++ b/HAL-afb/hal-most-unicens/wrap_volume.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <time.h>
+#include <assert.h>
#include <json-c/json.h>
#include <afb/afb-binding.h>
@@ -53,6 +54,19 @@ static void wrap_volume_service_cb(uint16_t timeout) {
NULL);
}
+/* Retrieves a new value adapted to a new maximum value. Minimum value is
+ * always zero. */
+static int wrap_volume_calculate(int value, int max_old, int max_new) {
+
+ if (value > max_old)
+ value = max_old;
+
+ value = (value * max_new) / max_old; /* calculate range: 0..255 */
+ assert(value <= max_new);
+
+ return value;
+}
+
extern int wrap_volume_init(void) {
uint8_t ret = 0U;
@@ -64,4 +78,41 @@ extern int wrap_volume_init(void) {
ret = lib_most_volume_init(&mv_init);
return ret * (-1);
-} \ No newline at end of file
+}
+
+extern int wrap_volume_master(int volume) {
+
+ int new_value, ret;
+
+ new_value = wrap_volume_calculate(volume, 100, 255);
+ ret = lib_most_volume_set(LIB_MOST_VOLUME_MASTER, (uint8_t)new_value);
+
+ if (ret != 0) {
+ AFB_ERROR("wrap_volume_master: volume library not ready.");
+ ret = ret * (-1); /* make return value negative */
+ }
+
+ return ret;
+}
+
+extern int wrap_volume_pcm(int *volume_ptr, int volume_sz) {
+
+ const int MAX_PCM_CHANNELS = 6;
+ int cnt, ret;
+ assert(volume_ptr != NULL);
+ assert(volume_sz <= MAX_PCM_CHANNELS);
+
+ for (cnt = 0; cnt < volume_sz; cnt ++) {
+
+ int new_value = wrap_volume_calculate(volume_ptr[cnt], 100, 255);
+ ret = lib_most_volume_set((enum lib_most_volume_channel_t)cnt, (uint8_t)new_value);
+
+ if (ret != 0) {
+ AFB_ERROR("wrap_volume_pcm: volume library not ready.");
+ ret = ret * (-1); /* make return value negative */
+ break;
+ }
+ }
+
+ return ret;
+}
diff --git a/HAL-afb/hal-most-unicens/wrap_volume.h b/HAL-afb/hal-most-unicens/wrap_volume.h
index b17bc26..3378540 100644
--- a/HAL-afb/hal-most-unicens/wrap_volume.h
+++ b/HAL-afb/hal-most-unicens/wrap_volume.h
@@ -21,3 +21,5 @@
#include <systemd/sd-event.h>
extern int wrap_volume_init(void);
+extern int wrap_volume_master(int volume);
+extern int wrap_volume_pcm(int *volume_ptr, int volume_sz);