aboutsummaryrefslogtreecommitdiffstats
path: root/HAL-afb/HAL_MOST_UNICENS
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-08-23 10:54:30 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-08-23 10:54:30 +0200
commitd0dae04c2ae6e4219e0ebac205dd05fa7e9427cf (patch)
tree80c6fc84f56afedc4fb02a097ae3e464bd792828 /HAL-afb/HAL_MOST_UNICENS
parent606ccd2405a55eab4c909160c951c083bccd825d (diff)
Format: remove blank space at EOL
Change-Id: I786ac8d5be68bdf09d5bb6c883959d6e1963c1fe Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'HAL-afb/HAL_MOST_UNICENS')
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/CMakeLists.txt2
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/README.md2
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c48
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/CMakeLists.txt2
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h2
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h4
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp2
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp4
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp4
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c140
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/wrap_volume.c50
11 files changed, 130 insertions, 130 deletions
diff --git a/HAL-afb/HAL_MOST_UNICENS/CMakeLists.txt b/HAL-afb/HAL_MOST_UNICENS/CMakeLists.txt
index eb4d1d6..5935b72 100644
--- a/HAL-afb/HAL_MOST_UNICENS/CMakeLists.txt
+++ b/HAL-afb/HAL_MOST_UNICENS/CMakeLists.txt
@@ -33,7 +33,7 @@ PROJECT_TARGET_ADD(hal-most-unicens)
)
# Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
hal-interface
audio-common
ucs2-volume
diff --git a/HAL-afb/HAL_MOST_UNICENS/README.md b/HAL-afb/HAL_MOST_UNICENS/README.md
index a0cc190..4ce4261 100644
--- a/HAL-afb/HAL_MOST_UNICENS/README.md
+++ b/HAL-afb/HAL_MOST_UNICENS/README.md
@@ -42,7 +42,7 @@ card 2: ep022ch [Microchip MOST:2], device 0: ep02-2ch []
Subdevice #0: subdevice #0
```
-Choose the first sound card with 6 channels, e.g. if you see ```ep01-6ch``` just
+Choose the first sound card with 6 channels, e.g. if you see ```ep01-6ch``` just
take ```Microchip MOST:1```.
If you get messed up with card enumeration the following action may help:
diff --git a/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c b/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c
index 4405e61..2eb96b8 100644
--- a/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c
+++ b/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c
@@ -13,9 +13,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
-#define _GNU_SOURCE
+#define _GNU_SOURCE
#include <string.h>
#include "hal-interface.h"
#include "audio-common.h"
@@ -37,32 +37,32 @@ static int pcm_volume[PCM_MAX_CHANNELS];
void unicens_master_vol_cb(halCtlsTagT tag, alsaHalCtlMapT *control, void* handle, json_object *j_obj) {
const char *j_str = json_object_to_json_string(j_obj);
-
+
if (wrap_json_unpack(j_obj, "[i!]", &master_volume) == 0) {
AFB_NOTICE("master_volume: %s, value=%d", j_str, master_volume);
wrap_volume_master(master_volume);
}
else {
AFB_NOTICE("master_volume: INVALID STRING %s", j_str);
- }
+ }
}
void unicens_master_switch_cb(halCtlsTagT tag, alsaHalCtlMapT *control, void* handle, json_object *j_obj) {
const char *j_str = json_object_to_json_string(j_obj);
-
+
if (wrap_json_unpack(j_obj, "[b!]", &master_switch) == 0) {
AFB_NOTICE("master_switch: %s, value=%d", j_str, master_switch);
}
else {
AFB_NOTICE("master_switch: INVALID STRING %s", j_str);
- }
+ }
}
void unicens_pcm_vol_cb(halCtlsTagT tag, alsaHalCtlMapT *control, void* handle, json_object *j_obj) {
const char *j_str = json_object_to_json_string(j_obj);
-
+
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);
@@ -74,15 +74,15 @@ void unicens_pcm_vol_cb(halCtlsTagT tag, alsaHalCtlMapT *control, void* handle,
}
/* declare ALSA mixer controls */
-STATIC alsaHalMapT alsaHalMap[]= {
+STATIC alsaHalMapT alsaHalMap[]= {
{ .tag=Master_Playback_Volume, .cb={.callback=unicens_master_vol_cb, .handle=&master_volume}, .info="Sets master playback volume",
- .ctl={.numid=1, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=1, .minval=0, .maxval=100, .step=1, .value=50, .name="Master Playback Volume"}
+ .ctl={.numid=1, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=1, .minval=0, .maxval=100, .step=1, .value=50, .name="Master Playback Volume"}
},
/*{ .tag=Master_OnOff_Switch, .cb={.callback=unicens_master_switch_cb, .handle=&master_switch}, .info="Sets master playback switch",
- .ctl={.numid=2, .type=SND_CTL_ELEM_TYPE_BOOLEAN, .count=1, .minval=0, .maxval=1, .step=1, .value=1, .name="Master Playback Switch"}
+ .ctl={.numid=2, .type=SND_CTL_ELEM_TYPE_BOOLEAN, .count=1, .minval=0, .maxval=1, .step=1, .value=1, .name="Master Playback Switch"}
},*/
{ .tag=PCM_Playback_Volume, .cb={.callback=unicens_pcm_vol_cb, .handle=&pcm_volume}, .info="Sets PCM playback volume",
- .ctl={.numid=3, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=6, .minval=0, .maxval=100, .step=1, .value=100, .name="PCM Playback Volume"}
+ .ctl={.numid=3, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=6, .minval=0, .maxval=100, .step=1, .value=100, .name="PCM Playback Volume"}
},
{ .tag=EndHalCrlTag} /* marker for end of the array */
} ;
@@ -100,19 +100,19 @@ STATIC int unicens_service_init() {
int err = 0;
char *config_file = NULL;
AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING");
-
+
err = halServiceInit(afbBindingV2.api, &alsaHalSndCard);
if (err) {
AFB_ERROR("Cannot initialize ALSA soundcard.");
goto OnErrorExit;
- }
-
+ }
+
err= afb_daemon_require_api("UNICENS", 1);
if (err) {
AFB_ERROR("Failed to access UNICENS API");
goto OnErrorExit;
}
-
+
err = wrap_ucs_getconfig_sync(UCS2_CFG_PATH, &config_file);
if (err || (config_file == NULL)) {
AFB_ERROR("Failed to retrieve configuration");
@@ -121,46 +121,46 @@ STATIC int unicens_service_init() {
else {
AFB_NOTICE("Found configuration: %s", config_file);
}
-
+
err = wrap_ucs_subscribe_sync();
if (err) {
AFB_ERROR("Failed to subscribe to UNICENS binding");
goto OnErrorExit;
}
-
+
err = wrap_ucs_initialize_sync(config_file);
free(config_file);
config_file = NULL;
-
+
if (err) {
AFB_ERROR("Failed to initialize UNICENS binding");
goto OnErrorExit;
}
-
+
err = wrap_volume_init();
if (err) {
AFB_ERROR("Failed to initialize wrapper for volume library");
goto OnErrorExit;
}
-
+
OnErrorExit:
AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING done..");
return err;
}
-// This receive all event this binding subscribe to
+// This receive all event this binding subscribe to
PUBLIC void unicens_event_cb(const char *evtname, json_object *j_event) {
-
+
if (strncmp(evtname, "alsacore/", 9) == 0) {
halServiceEvent(evtname, j_event);
return;
}
-
+
if (strncmp(evtname, "UNICENS/", 8) == 0) {
AFB_NOTICE("unicens_event_cb: evtname=%s [msg=%s]", evtname, json_object_get_string(j_event));
return;
}
-
+
AFB_NOTICE("unicens_event_cb: UNHANDLED EVENT, evtname=%s [msg=%s]", evtname, json_object_get_string(j_event));
}
diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/CMakeLists.txt b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/CMakeLists.txt
index 8735677..c734639 100644
--- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/CMakeLists.txt
+++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/CMakeLists.txt
@@ -18,7 +18,7 @@
-# Define subproject targets
+# Define subproject targets
ADD_SUBDIRECTORY(src)
diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h
index 21fdbdc..5364662 100644
--- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h
+++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h
@@ -69,7 +69,7 @@ public:
bool RequiresUpdate(); // returns true if target is not actual value
// returns true if success, false if failed
// -> stop transmission
- bool FireUpdateMessage(lib_most_volume_writei2c_cb_t writei2c_fptr,
+ bool FireUpdateMessage(lib_most_volume_writei2c_cb_t writei2c_fptr,
lib_most_volume_writei2c_result_cb_t result_fptr,
void *result_user_ptr);// fires message & updates actual value
diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h
index 1d7249d..94d5a1c 100644
--- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h
+++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h
@@ -60,13 +60,13 @@ typedef void (*lib_most_volume_writei2c_result_cb_t)(uint8_t result, void *user_
* \return Returns \c 0 for success, other value on failure.
*/
typedef int (*lib_most_volume_writei2c_cb_t)(uint16_t node, uint8_t *data_ptr, uint8_t data_sz,
- lib_most_volume_writei2c_result_cb_t result_fptr,
+ lib_most_volume_writei2c_result_cb_t result_fptr,
void *result_user_ptr);
typedef struct lib_most_volume_init_ {
lib_most_volume_service_cb_t service_cb;
lib_most_volume_writei2c_cb_t writei2c_cb;
-
+
} lib_most_volume_init_t;
diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp
index cef25b1..40177fc 100644
--- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp
+++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp
@@ -112,7 +112,7 @@ void CDeviceContainer::Update()
{
return;
}
-
+
for (cnt = 0u; cnt < this->_values_sz; cnt++) /* just run one cycle */
{
IncrementProcIndex();
diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp
index b8c681e..5a74354 100644
--- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp
+++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp
@@ -93,14 +93,14 @@ bool CDeviceValue::RequiresUpdate()
return false;
}
-bool CDeviceValue::FireUpdateMessage(lib_most_volume_writei2c_cb_t writei2c_fptr,
+bool CDeviceValue::FireUpdateMessage(lib_most_volume_writei2c_cb_t writei2c_fptr,
lib_most_volume_writei2c_result_cb_t result_fptr,
void *result_user_ptr)
{
int ret;
ApplyMostValue(this->_target_value, _type, _tx_payload);
- ret = writei2c_fptr(this->_address, &_tx_payload[0], _tx_payload_sz,
+ ret = writei2c_fptr(this->_address, &_tx_payload[0], _tx_payload_sz,
result_fptr,
result_user_ptr);
diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp
index a90b5b1..72d2b04 100644
--- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp
+++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp
@@ -72,7 +72,7 @@ extern "C" uint8_t lib_most_volume_set(enum lib_most_volume_channel_t channel, u
}
extern "C" uint8_t lib_most_volume_service(void)
-{
+{
uint8_t success = 1U;
/*std::cerr << "lib_most_volume_service(): called" << std::endl;*/
@@ -81,6 +81,6 @@ extern "C" uint8_t lib_most_volume_service(void)
CSetup::GetInstance()->Update();
success = 0U;
}
-
+
return success;
}
diff --git a/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c b/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c
index dc82568..0923c26 100644
--- a/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c
+++ b/HAL-afb/HAL_MOST_UNICENS/wrap_unicens.c
@@ -13,9 +13,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
-#define _GNU_SOURCE
+#define _GNU_SOURCE
#define AFB_BINDING_VERSION 2
#include <string.h>
@@ -31,24 +31,24 @@ typedef struct async_job_ {
typedef struct parse_result_ {
int done;
- char *str_result;
-} parse_result_t;
+ char *str_result;
+} parse_result_t;
/* Subscribes to unicens2-binding events.
* \return Returns 0 if successful, otherwise != 0".
*/
extern int wrap_ucs_subscribe_sync() {
-
+
json_object *j_response, *j_query = NULL;
int err;
-
+
/* Build an empty JSON object */
err = wrap_json_pack(&j_query, "{}");
if (err) {
AFB_ERROR("Failed to create subscribe json object");
- goto OnErrorExit;
+ goto OnErrorExit;
}
-
+
err = afb_service_call_sync("UNICENS", "subscribe", j_query, &j_response);
if (err) {
AFB_ERROR("Fail subscribing to UNICENS events");
@@ -60,7 +60,7 @@ extern int wrap_ucs_subscribe_sync() {
}
json_object_put(j_query);
j_query = NULL;
-
+
OnErrorExit:
if (j_query)
json_object_put(j_query);
@@ -69,52 +69,52 @@ OnErrorExit:
/* Checks if name ends with a given letter. */
static int wrap_ucs_string_ends_with(const char *name, char letter) {
-
+
int result = 0;
size_t len = strlen(name);
-
+
if (len > 0) {
-
+
if (name[len] == letter) {
result = 1;
}
}
-
+
return result;
}
/* Callback for iteration through found files. Marks search as "done" as
- * soon as the search pattern "kit.xml" matches.
+ * soon as the search pattern "kit.xml" matches.
* \param closure User reference. Points to parse_result_t.
* \param j_obj Points to json object within array.
*/
static void wrap_ucs_find_xml_cb(void *closure, struct json_object *j_obj) {
-
+
const char *dir, *name;
parse_result_t *result;
-
+
if (!closure)
return;
-
- result = (parse_result_t *)closure;
+
+ result = (parse_result_t *)closure;
if (result->done)
return;
-
+
wrap_json_unpack(j_obj, "{s:s, s:s}", "dirpath", &dir, "basename", &name);
AFB_DEBUG("Found file: %s", name);
-
+
if(strstr(name, "kit.xml") != NULL) {
size_t sz = strlen(dir)+strlen(name)+10;
char * full_path = malloc(sz);
-
+
strncpy(full_path, dir, sz);
-
+
if (!wrap_ucs_string_ends_with(dir, '/'))
strncat(full_path, "/", sz);
-
+
strncat(full_path, name, sz);
AFB_DEBUG("Found XML file: %s", full_path);
-
+
result->done = 1;
result->str_result = full_path;
}
@@ -127,24 +127,24 @@ static void wrap_ucs_find_xml_cb(void *closure, struct json_object *j_obj) {
* \return Returns 0 if successful, otherwise != 0".
*/
extern int wrap_ucs_getconfig_sync(const char *config_path, char **file_found) {
-
+
int err = 0;
json_object *j_response, *j_query, *j_paths = NULL;
parse_result_t result = {.done = 0, .str_result = NULL};
-
+
*file_found = NULL;
-
+
/* Build JSON object to retrieve UNICENS configuration */
if ((config_path == NULL) || (strcmp(config_path, "") == 0))
err = wrap_json_pack(&j_query, "{}");
else
err = wrap_json_pack(&j_query, "{s:s}", "cfgpath", config_path);
-
+
if (err) {
AFB_ERROR("Failed to create listconfig json object");
- goto OnErrorExit;
+ goto OnErrorExit;
}
-
+
err = afb_service_call_sync("UNICENS", "listconfig", j_query, &j_response);
if (err) {
AFB_ERROR("Failed to call listconfig");
@@ -152,13 +152,13 @@ extern int wrap_ucs_getconfig_sync(const char *config_path, char **file_found) {
}
else {
AFB_DEBUG("UNICENS listconfig result, res=%s", json_object_to_json_string(j_response));
-
+
if (json_object_object_get_ex(j_response, "response", &j_paths)) {
-
+
AFB_DEBUG("UNICENS listconfig result, paths=%s", json_object_to_json_string(j_paths));
-
+
wrap_json_optarray_for_all(j_paths, &wrap_ucs_find_xml_cb, &result);
-
+
if (result.done) {
*file_found = strdup(result.str_result);
free(result.str_result);
@@ -169,12 +169,12 @@ extern int wrap_ucs_getconfig_sync(const char *config_path, char **file_found) {
err = -1;
}
}
-
+
json_object_put(j_response);
}
json_object_put(j_query);
j_query = NULL;
-
+
OnErrorExit:
if (j_query)
json_object_put(j_query);
@@ -183,22 +183,22 @@ OnErrorExit:
/* Initializes the unicens2-binding.
* \param file_name Path to XML configuration file or \c NULL for
- * first found file in default path.
+ * first found file in default path.
* \return Returns 0 if successful, otherwise != 0".
*/
extern int wrap_ucs_initialize_sync(const char *file_name) {
json_object *j_response, *j_query = NULL;
int err;
-
+
/* Build JSON object to initialize UNICENS */
- if (file_name != NULL)
+ if (file_name != NULL)
err = wrap_json_pack(&j_query, "{s:s}", "filename", file_name);
else
err = wrap_json_pack(&j_query, "{}");
-
+
if (err) {
AFB_ERROR("Failed to create initialize json object");
- goto OnErrorExit;
+ goto OnErrorExit;
}
err = afb_service_call_sync("UNICENS", "initialise", j_query, &j_response);
if (err) {
@@ -209,10 +209,10 @@ extern int wrap_ucs_initialize_sync(const char *file_name) {
AFB_NOTICE("Initialized UNICENS, res=%s", json_object_to_json_string(j_response));
json_object_put(j_response);
}
-
+
json_object_put(j_query);
j_query = NULL;
-
+
OnErrorExit:
if (j_query)
json_object_put(j_query);
@@ -221,7 +221,7 @@ OnErrorExit:
/* Write I2C command to a network node.
* \param node Node address
- * \param data_ptr Reference to command data
+ * \param data_ptr Reference to command data
* \param data_sz Size of the command data. Valid values: 1..32.
* \return Returns 0 if successful, otherwise != 0".
*/
@@ -233,22 +233,22 @@ extern int wrap_ucs_i2cwrite_sync(uint16_t node, uint8_t *data_ptr, uint8_t data
j_query = json_object_new_object();
j_array = json_object_new_array();
-
+
if (!j_query || !j_array) {
err = -1;
AFB_ERROR("Failed to create writei2c json objects");
- goto OnErrorExit;
- }
-
+ goto OnErrorExit;
+ }
+
for (cnt = 0U; cnt < data_sz; cnt++) {
json_object_array_add(j_array, json_object_new_int(data_ptr[cnt]));
}
-
+
json_object_object_add(j_query, "node", json_object_new_int(node));
json_object_object_add(j_query, "data", j_array);
-
+
err = afb_service_call_sync("UNICENS", "writei2c", j_query, &j_response);
-
+
if (err) {
AFB_ERROR("Failed to call writei2c_sync");
goto OnErrorExit;
@@ -257,40 +257,40 @@ extern int wrap_ucs_i2cwrite_sync(uint16_t node, uint8_t *data_ptr, uint8_t data
AFB_INFO("Called writei2c_sync, res=%s", json_object_to_json_string(j_response));
json_object_put(j_response);
}
-
+
json_object_put(j_query);
j_query = NULL;
OnErrorExit:
if (j_query)
json_object_put(j_query);
- return err;
+ return err;
}
/* ------------------ ASYNCHRONOUS API ---------------------------------------*/
static void wrap_ucs_i2cwrite_cb(void *closure, int status, struct json_object *j_result) {
-
+
AFB_INFO("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;
-
+
if (job_ptr->result_fptr)
job_ptr->result_fptr(0U, job_ptr->result_user_ptr);
-
+
free(closure);
}
}
/* Write I2C command to a network node.
* \param node Node address
- * \param data_ptr Reference to command data
+ * \param data_ptr Reference to command data
* \param data_sz Size of the command data. Valid values: 1..32.
* \return Returns 0 if successful, otherwise != 0".
*/
extern int wrap_ucs_i2cwrite(uint16_t node, uint8_t *data_ptr, uint8_t data_sz,
- wrap_ucs_result_cb_t result_fptr,
+ wrap_ucs_result_cb_t result_fptr,
void *result_user_ptr) {
json_object *j_query, *j_array = NULL;
@@ -300,31 +300,31 @@ extern int wrap_ucs_i2cwrite(uint16_t node, uint8_t *data_ptr, uint8_t data_sz,
j_query = json_object_new_object();
j_array = json_object_new_array();
-
+
if (!j_query || !j_array) {
err = -1;
AFB_ERROR("Failed to create writei2c json objects");
- goto OnErrorExit;
- }
-
+ goto OnErrorExit;
+ }
+
for (cnt = 0U; cnt < data_sz; cnt++) {
json_object_array_add(j_array, json_object_new_int(data_ptr[cnt]));
}
-
+
json_object_object_add(j_query, "node", json_object_new_int(node));
json_object_object_add(j_query, "data", j_array);
-
+
job_ptr = malloc(sizeof(async_job_t));
-
+
if (!job_ptr) {
err = -1;
AFB_ERROR("Failed to create async job object");
- goto OnErrorExit;
+ goto OnErrorExit;
}
-
+
job_ptr->result_fptr = result_fptr;
job_ptr->result_user_ptr = result_user_ptr;
-
+
afb_service_call("UNICENS", "writei2c", j_query, wrap_ucs_i2cwrite_cb, job_ptr);
err = 0;
j_query = NULL;
@@ -332,5 +332,5 @@ extern int wrap_ucs_i2cwrite(uint16_t node, uint8_t *data_ptr, uint8_t data_sz,
OnErrorExit:
if (j_query)
json_object_put(j_query);
- return err;
+ return err;
}
diff --git a/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c b/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c
index cf70647..8087a04 100644
--- a/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c
+++ b/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c
@@ -13,9 +13,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
-#define _GNU_SOURCE
+#define _GNU_SOURCE
#define AFB_BINDING_VERSION 2
#include <string.h>
@@ -31,88 +31,88 @@
static int wrap_volume_service_timeout_cb(sd_event_source* source,
uint64_t timer __attribute__((__unused__)),
void *userdata __attribute__((__unused__))) {
-
+
uint8_t ret;
sd_event_source_unref(source);
ret = lib_most_volume_service();
-
+
if (ret != 0U) {
AFB_ERROR("lib_most_volume_service returns %d", ret);
}
-
+
return 0;
}
static void wrap_volume_service_cb(uint16_t timeout) {
uint64_t usec;
sd_event_now(afb_daemon_get_event_loop(), CLOCK_BOOTTIME, &usec);
- sd_event_add_time( afb_daemon_get_event_loop(), NULL, CLOCK_MONOTONIC,
- usec + (timeout*1000),
- 250,
- wrap_volume_service_timeout_cb,
+ sd_event_add_time( afb_daemon_get_event_loop(), NULL, CLOCK_MONOTONIC,
+ usec + (timeout*1000),
+ 250,
+ wrap_volume_service_timeout_cb,
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;
lib_most_volume_init_t mv_init;
-
+
mv_init.writei2c_cb = &wrap_ucs_i2cwrite;
mv_init.service_cb = wrap_volume_service_cb;
-
+
ret = lib_most_volume_init(&mv_init);
-
+
return ret * (-1);
}
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;
}