summaryrefslogtreecommitdiffstats
path: root/HAL-afb/HAL_MOST_UNICENS/ucs2-vol
diff options
context:
space:
mode:
Diffstat (limited to 'HAL-afb/HAL_MOST_UNICENS/ucs2-vol')
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_container.h1
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/inc/device_value.h13
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp11
-rw-r--r--HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp66
4 files changed, 56 insertions, 35 deletions
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 b7f373c..9fabdb5 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
@@ -45,7 +45,6 @@ private:
void RequestService(uint16_t timeout);
void IncrementProcIndex(void);
void HandleI2cResult(uint8_t result);
-
static void OnI2cResult(uint8_t result, void *obj_ptr);
uint16_t _idx_processing;
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 6311346..bc8f142 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
@@ -73,23 +73,28 @@ public:
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;}
+ void SetAvailable(bool active){this->_is_available = active; _actual_value = 0x01u;}
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[]);
+ void HandleI2cResult(uint8_t result);
+ static void OnI2cResult(uint8_t result, void *obj_ptr);
- bool _is_initial; // ensure first update
- bool _is_available; // related node is available
+ bool _is_available; // related node is available
+ bool _is_busy; // do not update while busy
DeviceValueType _type; // determines the remote i2c command
uint16_t _key; // lookup key
uint16_t _address; // target node/group address
uint8_t _target_value; // desired value
+ uint8_t _transmitted_value;// value pending during transmission
uint8_t _actual_value; // value set and confirmed via network
uint8_t _tx_payload[20];
uint8_t _tx_payload_sz;
+
+ lib_most_volume_writei2c_result_cb_t _result_fptr;
+ void *_result_user_ptr;
};
#endif /* DEVICEPROPERTY_H */
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 4c99c89..f8b1961 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
@@ -24,7 +24,7 @@
#include <stddef.h>
#include "device_container.h"
-#define DEVCONT_TIME_RETRIGGER (uint16_t)100U
+#define DEVCONT_TIME_RETRIGGER (uint16_t)30U
#define DEVCONT_TIME_NOW (uint16_t)0U
#define DEVCONT_TIME_STOP (uint16_t)0xFFFFU
@@ -123,13 +123,14 @@ void CDeviceContainer::Update()
&OnI2cResult,
this))
{
- /*Clb_RegisterI2CResultCB(&OnI2cResult, this);*/
this->_tx_busy = true;
+ error = false;
break;
}
else
{
error = true;
+ break;
}
}
}
@@ -142,9 +143,11 @@ void CDeviceContainer::Update()
void CDeviceContainer::HandleI2cResult(uint8_t result)
{
- DEVCONT_UNUSED(result);
this->_tx_busy = false;
- this->RequestService(DEVCONT_TIME_NOW);
+ if (result == 0)
+ this->RequestService(DEVCONT_TIME_NOW);
+ else
+ this->RequestService(DEVCONT_TIME_RETRIGGER);
}
void CDeviceContainer::OnI2cResult(uint8_t result, void *obj_ptr)
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 b5f5679..7103192 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
@@ -20,7 +20,7 @@
* Please contact Microchip for further information.
*
*/
-
+#include <stddef.h>
#include "device_value.h"
#include "setup.h"
@@ -34,11 +34,14 @@
CDeviceValue::CDeviceValue(uint16_t address, DeviceValueType type, uint16_t key)
{
- this->_is_initial = true;
this->_is_available = false;
+ this->_is_busy = false;
this->_address = address;
this->_target_value = 0x01u;
this->_actual_value = 0x01u;
+
+ this->_result_fptr = NULL;
+ this->_result_user_ptr = NULL;
this->_type = type;
this->_key = key;
@@ -86,7 +89,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->_is_available && (this->_target_value != this->_actual_value))
+ if (this->_is_available && !this->_is_busy && (this->_target_value != this->_actual_value))
{
return true;
}
@@ -101,34 +104,45 @@ bool CDeviceValue::FireUpdateMessage(lib_most_volume_writei2c_cb_t writei2c_fptr
int ret = -1;
ApplyMostValue(this->_target_value, _type, _tx_payload);
- if (this->_is_available)
+ if (this->_is_available && !this->_is_busy)
{
ret = writei2c_fptr(this->_address, &_tx_payload[0], _tx_payload_sz,
- result_fptr,
- result_user_ptr);
+ &OnI2cResult,
+ this);
+
+ if (ret == 0)
+ {
+ this->_transmitted_value = this->_target_value;
+ this->_is_busy = true;
+ this->_result_fptr = result_fptr;
+ this->_result_user_ptr = result_user_ptr;
+ return true;
+ }
}
- if (ret == 0)
+ return false;
+}
+
+void CDeviceValue::HandleI2cResult(uint8_t result)
+{
+ if (result == 0)
{
- // Clb_RegisterI2CResultCB(OnI2cResult, this);
- // mark value as set!
- this->_actual_value = this->_target_value;
- return true;
+ /* transmission succeeded - now apply transmitted value */
+ this->_actual_value = this->_transmitted_value;
}
-
- return false;
+
+ if (this->_result_fptr)
+ {
+ /* notify container */
+ this->_result_fptr(result, this->_result_user_ptr);
+ }
+
+ this->_result_fptr = NULL;
+ this->_result_user_ptr = NULL;
+ this->_is_busy = false;
}
-#if 0
- ret = Ucs_I2c_WritePort( CSetup::GetInstance()->RetrieveUnicensInst(),
- this->_address,
- 0x0F00u, /* i2c port handle */
- UCS_I2C_DEFAULT_MODE, /* 0 */
- 0u, /* block count */
- 0x2Au, /* i2c slave address */
- 0x03E8u, /* timeout 1000 milliseconds */
- _tx_payload_sz, /* data length */
- &_tx_payload[0], /* data pointer */
- &Clb_OnWriteI2CPortResult
- );
-#endif
+void CDeviceValue::OnI2cResult(uint8_t result, void *obj_ptr)
+{
+ ((CDeviceValue*)obj_ptr)->HandleI2cResult(result);
+}