Index: sources/device/DeviceModels.cpp =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -r23eda7b49841f242485b70d0a96f4bdde50f71bc --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 23eda7b49841f242485b70d0a96f4bdde50f71bc) @@ -18,7 +18,6 @@ #include // Project -#include "DeviceError.h" using namespace Model; @@ -119,3 +118,47 @@ lOut: return _data.mAccepted; } + +/*! + * \brief MDeviceBrightnessRequest::setBrightnessSysVal + * \details checks for the requested brightness percentage (in range and resolution) + * \return returns device script error enum and is 0 on no error + */ +Device::DeviceError::Scripts_Error_Enum MDeviceBrightnessRequest::setBrightnessSysVal() +{ + // _data.mBrightnessPercent = 200; + + // check range(min,max) + quint8 len = UI2HW.size(); + if ( ! len ) { + LOG_DEBUG("Empty UI2HW map"); + return Device::DeviceError::eDevice_Scripts_Error_Unknown; + } + quint8 min = UI2HW.begin() .key(); + quint8 max = (UI2HW.end () - 1).key(); + if ( ! ( min <= _data.mBrightnessPercent && _data.mBrightnessPercent <= max ) ) { + return Device::DeviceError::eDevice_Scripts_Error_OutOfRange; + } + + // check range(resolution) + if ( ! UI2HW.contains(_data.mBrightnessPercent) ) { + return Device::DeviceError::eDevice_Scripts_Error_Incorrect_Req; + } + + _data.mBrightness_val = UI2HW[_data.mBrightnessPercent]; + return Device::DeviceError::eDevice_OK; +} + +/*! + * \brief MDeviceBrightnessResponse::setBrightnessPercent + * \param vSysVal - updated the response with returned brightness system value + * \return returns device script error enum and is 0 on no error + */ +Device::DeviceError::Scripts_Error_Enum MDeviceBrightnessResponse::setBrightnessPercent(quint8 vSysVal) { + if ( ! HW2UI.contains( vSysVal ) ) { + return Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp; + } + + _data.mBrightnessPercent = HW2UI[ vSysVal ]; + return Device::DeviceError::eDevice_OK; +}