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_MOST_UNICENS/ucs2-vol/inc/device_container.h | 1 + HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h | 5 +++++ HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/libmostvolume.h | 7 +++++++ HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/setup.h | 1 + .../HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp | 18 ++++++++++++++++++ HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp | 14 +++++++++----- .../HAL_MOST_UNICENS/ucs2-vol/src/libmostvolume.cpp | 13 +++++++++++++ HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/setup.cpp | 5 +++++ 8 files changed, 59 insertions(+), 5 deletions(-) (limited to 'HAL-afb/HAL_MOST_UNICENS/ucs2-vol') 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); +} -- cgit 1.2.3-korg