From c3d250fbc63c05d7f0ad5c4d95d725a16f3cece4 Mon Sep 17 00:00:00 2001 From: Tobias Jahnke Date: Mon, 21 Aug 2017 17:01:54 +0200 Subject: forwarding node availability to volume lib --- HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c | 23 ++++++++++++++++------ .../ucs2-vol/inc/device_container.h | 1 + .../HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h | 5 +++++ .../HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h | 7 +++++++ HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/setup.h | 1 + .../ucs2-vol/src/device_container.cpp | 18 +++++++++++++++++ .../HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp | 14 ++++++++----- .../ucs2-vol/src/libmostvolume.cpp | 13 ++++++++++++ HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/setup.cpp | 5 +++++ HAL-afb/HAL_MOST_UNICENS/wrap_volume.c | 14 +++++++++++++ HAL-afb/HAL_MOST_UNICENS/wrap_volume.h | 1 + 11 files changed, 91 insertions(+), 11 deletions(-) diff --git a/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c b/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c index 2eb96b8..031c5b8 100644 --- a/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c +++ b/HAL-afb/HAL_MOST_UNICENS/hal_most_unicens.c @@ -76,13 +76,13 @@ void unicens_pcm_vol_cb(halCtlsTagT tag, alsaHalCtlMapT *control, void* handle, /* declare ALSA mixer controls */ 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=CTL_AUTO, .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=CTL_AUTO, .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=CTL_AUTO, .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 */ } ; @@ -157,11 +157,22 @@ PUBLIC void unicens_event_cb(const char *evtname, json_object *j_event) { } if (strncmp(evtname, "UNICENS/", 8) == 0) { - AFB_NOTICE("unicens_event_cb: evtname=%s [msg=%s]", evtname, json_object_get_string(j_event)); + //AFB_NOTICE("unicens_event_cb: evtname=%s, event=%s", evtname, json_object_get_string(j_event)); + if (strcmp(evtname, "UNICENS/node-availibility") == 0) { + + int node; + int available; + if (wrap_json_unpack(j_event, "{s:i,s:b}", "node", &node, "available", &available) == 0) { + AFB_NOTICE("Node-Availability: node=0x%03X, available=%d", node, available); + wrap_volume_node_avail(node, available); + } + + } + return; } - - AFB_NOTICE("unicens_event_cb: UNHANDLED EVENT, evtname=%s [msg=%s]", evtname, json_object_get_string(j_event)); + + AFB_NOTICE("unicens_event_cb: UNHANDLED EVENT, evtname=%s, event=%s", evtname, json_object_get_string(j_event)); } /* API prefix should be unique for each snd card */ diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_container.h b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_container.h index 5e3b753..b7f373c 100644 --- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_container.h +++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_container.h @@ -39,6 +39,7 @@ public: void SetValue(uint16_t key, uint8_t value); void ClearValues(); void Update(); + void ChangeNodeAvailable(uint16_t address, bool available); private: void RequestService(uint16_t timeout); 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 5364662..6311346 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 @@ -72,12 +72,17 @@ public: 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 + + void SetAvailable(bool active){this->_is_available = active;} + bool IsAvailable() {return this->_is_available;} + uint16_t GetAddress() {return this->_address;} private: void HandleI2cResult(uint8_t result); void ApplyMostValue(uint8_t value, DeviceValueType type, uint8_t tx_payload[]); bool _is_initial; // ensure first update + bool _is_available; // related node is available DeviceValueType _type; // determines the remote i2c command uint16_t _key; // lookup key uint16_t _address; // target node/group address 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 94d5a1c..1147993 100644 --- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h +++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h @@ -90,6 +90,13 @@ extern uint8_t lib_most_volume_exit(void); */ extern uint8_t lib_most_volume_set(enum lib_most_volume_channel_t channel, uint8_t volume); +/** Must be called when the availability of a node has changed + * \param address The node address + * \param available Availability: 0 - not available, 1 - available + * \return '0' on success, otherwise value >'0'. + */ +extern uint8_t lib_most_volume_node_available(uint16_t address, uint8_t available); + /** Shall be called either cyclically (e.g. 50ms -> polling) or after "timeout" * when "service_fptr" is fired (-> event triggered). * \return '0' on success, otherwise value >'0'. diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/setup.h b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/setup.h index 63bc0e2..e7cda01 100644 --- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/setup.h +++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/setup.h @@ -37,6 +37,7 @@ public: void Configure(lib_most_volume_init_t *init_ptr); void SetVolume(enum lib_most_volume_channel_t channel, uint8_t volume); void Update(); + void SetNodeAvailable(uint16_t address, bool available); private: CDeviceValue _volume_amp_270_m; 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 40177fc..4c99c89 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 @@ -164,3 +164,21 @@ void CDeviceContainer::RequestService(uint16_t timeout) } } } + +void CDeviceContainer::ChangeNodeAvailable(uint16_t address, bool available) +{ + uint16_t idx; + + for (idx = 0U; idx < this->_values_sz; idx++) + { + if (this->_values_pptr[idx]->GetAddress() == address) + { + this->_values_pptr[idx]->SetAvailable(available); + } + } + + if (available) + { + RequestService(DEVCONT_TIME_RETRIGGER); + } +} 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 5a74354..b5f5679 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 @@ -35,6 +35,7 @@ CDeviceValue::CDeviceValue(uint16_t address, DeviceValueType type, uint16_t key) { this->_is_initial = true; + this->_is_available = false; this->_address = address; this->_target_value = 0x01u; this->_actual_value = 0x01u; @@ -85,7 +86,7 @@ void CDeviceValue::ApplyMostValue(uint8_t value, DeviceValueType type, uint8_t t // returns true if target is not actual value bool CDeviceValue::RequiresUpdate() { - if (this->_target_value != this->_actual_value) + if (this->_is_available && (this->_target_value != this->_actual_value)) { return true; } @@ -97,12 +98,15 @@ 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; + int ret = -1; ApplyMostValue(this->_target_value, _type, _tx_payload); - ret = writei2c_fptr(this->_address, &_tx_payload[0], _tx_payload_sz, - result_fptr, - result_user_ptr); + if (this->_is_available) + { + ret = writei2c_fptr(this->_address, &_tx_payload[0], _tx_payload_sz, + result_fptr, + result_user_ptr); + } if (ret == 0) { 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 72d2b04..5eea3fd 100644 --- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp +++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp @@ -71,6 +71,19 @@ extern "C" uint8_t lib_most_volume_set(enum lib_most_volume_channel_t channel, u return success; } +extern uint8_t lib_most_volume_node_available(uint16_t address, uint8_t available) +{ + uint8_t success = 1U; + + if (_running) + { + CSetup::GetInstance()->SetNodeAvailable(address, available); + success = 0U; + } + + return success; +} + extern "C" uint8_t lib_most_volume_service(void) { uint8_t success = 1U; diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/setup.cpp b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/setup.cpp index 61b8a68..dd6675b 100644 --- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/setup.cpp +++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/setup.cpp @@ -87,3 +87,8 @@ void CSetup::Update() { _value_container.Update(); } + +void CSetup::SetNodeAvailable(uint16_t address, bool available) +{ + _value_container.ChangeNodeAvailable(address, available); +} diff --git a/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c b/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c index 8087a04..5bc1e84 100644 --- a/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c +++ b/HAL-afb/HAL_MOST_UNICENS/wrap_volume.c @@ -116,3 +116,17 @@ extern int wrap_volume_pcm(int *volume_ptr, int volume_sz) { return ret; } + +extern int wrap_volume_node_avail(int node, int available) { + + int ret; + ret = lib_most_volume_node_available((uint16_t)node, (uint8_t)available); + + if (ret != 0) { + AFB_ERROR("wrap_volume_node_avail: volume library not ready."); + ret = ret * (-1); /* make return value negative */ + } + + return ret; +} + diff --git a/HAL-afb/HAL_MOST_UNICENS/wrap_volume.h b/HAL-afb/HAL_MOST_UNICENS/wrap_volume.h index 3378540..099b70c 100644 --- a/HAL-afb/HAL_MOST_UNICENS/wrap_volume.h +++ b/HAL-afb/HAL_MOST_UNICENS/wrap_volume.h @@ -23,3 +23,4 @@ extern int wrap_volume_init(void); extern int wrap_volume_master(int volume); extern int wrap_volume_pcm(int *volume_ptr, int volume_sz); +extern int wrap_volume_node_avail(int node, int available); -- cgit 1.2.3-korg