Index: denali.pro.user =================================================================== diff -u -r93dbee7bb0b6e799a602735d54c01aeebd0a2074 -r23eda7b49841f242485b70d0a96f4bdde50f71bc --- denali.pro.user (.../denali.pro.user) (revision 93dbee7bb0b6e799a602735d54c01aeebd0a2074) +++ denali.pro.user (.../denali.pro.user) (revision 23eda7b49841f242485b70d0a96f4bdde50f71bc) @@ -1,6 +1,6 @@ - + EnvironmentId Index: sources/device/DeviceController.cpp =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -r23eda7b49841f242485b70d0a96f4bdde50f71bc --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 23eda7b49841f242485b70d0a96f4bdde50f71bc) @@ -29,7 +29,6 @@ #include "ApplicationController.h" #include "FileHandler.h" #include "DeviceModels.h" -#include "DeviceError.h" // namespace using namespace Model; @@ -447,11 +446,11 @@ { // ----- initializing the member variable models _deviceBrightnessRequest ._data = vData; - _deviceBrightnessResponse._data.mBrightnessPercent = _deviceBrightnessRequest._data.mBrightness_old * 10; // set to old value in case of error + // ----- extract the required data - _deviceBrightnessRequest._data.mBrightness_val = vData.mBrightnessPercent / 10; // convert the GUI value(percent) to device value - LOG_EVENT(_deviceBrightnessRequest.toString()); + _deviceBrightnessRequest.setBrightnessSysVal(); + LOG_EVENT( _deviceBrightnessRequest.toString()); // ----- check that script exists. QString script; @@ -464,24 +463,6 @@ return; } - // ----- check the data is valid - // TODO : this should be in the model - if ( _deviceBrightnessRequest.mBrightness_min > _deviceBrightnessRequest._data.mBrightness_val || _deviceBrightnessRequest._data.mBrightness_val > _deviceBrightnessRequest.mBrightness_max ) { - checkError(DeviceError::eDevice_Scripts_Error_OutOfRange, _deviceBrightnessResponse); - return; - } - - // ----- check the value is in the list of correct resolution - // create the list of correct values - // TODO : this should be in the model - QList _allowableValues; - for ( quint8 i = _deviceBrightnessRequest.mBrightness_min; i <= _deviceBrightnessRequest.mBrightness_max; i += _deviceBrightnessRequest.mBrightness_res ) _allowableValues += i; - // check the value is in the list - if ( ! _allowableValues.contains(_deviceBrightnessRequest._data.mBrightness_val) ) { - checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Req, _deviceBrightnessResponse); - return; - } - // ----- run the process _processBrightness.start(script, QStringList() << QString::number(_deviceBrightnessRequest._data.mBrightness_val)); } @@ -500,21 +481,21 @@ void DeviceController::onProcessBrightnessExitCode(int vExitCode, QProcess::ExitStatus) { // TODO: Move this into the model. - _deviceBrightnessResponse._data.mBrightnessPercent = _deviceBrightnessRequest._data.mBrightness_old * 10; // set to old value in case of error + // _deviceBrightnessResponse._data.mBrightnessPercent = _deviceBrightnessRequest._data.mBrightness_old * 10; // set to old value in case of error if ( ! checkError(static_cast(vExitCode), _deviceBrightnessResponse, _deviceBrightnessResponse.toString()) ) { // has no error if (_deviceBrightnessRequest._data.mRead) { bool ok = false; int brightness = _processBrightness.readLine().toInt(&ok); if (ok) { - _deviceBrightnessResponse._data.mBrightnessPercent = brightness * 10; + _deviceBrightnessResponse.setBrightnessPercent(brightness); } else { checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Rsp,_deviceBrightnessResponse, _deviceBrightnessResponse.toString()); return; } } else { - _deviceBrightnessResponse._data.mBrightnessPercent = _deviceBrightnessRequest._data.mBrightness_val * 10; + _deviceBrightnessResponse.setBrightnessPercent(_deviceBrightnessRequest._data.mBrightness_val); _deviceBrightnessResponse._data.mMessage = _deviceBrightnessResponse.toString(); } LOG_EVENT(_deviceBrightnessResponse._data.mMessage); @@ -552,7 +533,6 @@ didAttributeResponse(model.data()); } - void DeviceController::onAttributeRequest(const DeviceBluetoothPairedQueryRequestData &) { // ----- check that script exists. Index: sources/device/DeviceError.h =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -r23eda7b49841f242485b70d0a96f4bdde50f71bc --- sources/device/DeviceError.h (.../DeviceError.h) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/device/DeviceError.h (.../DeviceError.h) (revision 23eda7b49841f242485b70d0a96f4bdde50f71bc) @@ -42,7 +42,8 @@ // The scripts can use the exit code of each commands they execute and the assumption is most of Linux commands exit codes are less than 1000. // so any error less that 1000 will be identified as device error - eDevice_Scripts_Error_Start = 1000 , // the script itself in system starts from 0 so give it enough gap + eDevice_Scripts_Error_Start = 1000, // the script itself in system starts from 0 so give it enough gap + eDevice_Scripts_Error_Unknown = 1000, eDevice_Scripts_Error_Status , eDevice_Scripts_Error_NotFound , 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; +} Index: sources/device/DeviceModels.h =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -r23eda7b49841f242485b70d0a96f4bdde50f71bc --- sources/device/DeviceModels.h (.../DeviceModels.h) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/device/DeviceModels.h (.../DeviceModels.h) (revision 23eda7b49841f242485b70d0a96f4bdde50f71bc) @@ -20,6 +20,7 @@ // Project #include "MAbstract.h" #include "types.h" +#include "DeviceError.h" // forward declarations @@ -87,15 +88,20 @@ // TODO : Merge the two models as they have much in common in this case. // On the CANBus it was separated since the type of data in send and receive was totally different. // But here it's the same. + // TODO: improve later - this has to be match with HW2UI in response + QMap UI2HW = { // has to map to keep the order + { 20, 1}, + { 40, 3}, + { 60, 5}, + { 80, 6}, + {100, 10}, + }; public: // TODO : these needs to be available in Views static const quint8 mBrightness_min = 2; static const quint8 mBrightness_max = 10; static const quint8 mBrightness_res = 2; - // TODO : Add these two as virtual in parent. - quint8 toDV (quint8) { return 0; /* Place Holder (/ 10) */ } - quint8 toUI (quint8) { return 0; /* Place Holder (* 10) */ } struct Data { quint8 mBrightness_old = mBrightness_min ; @@ -105,6 +111,8 @@ bool mRead = false; } _data; + Device::DeviceError::Scripts_Error_Enum setBrightnessSysVal(); + QString toString() { return MDeviceRequestBase::toString("DeviceBrightness", { _data.mBrightnessPercent }); } @@ -115,14 +123,25 @@ * \details The model for the device brightness value request. */ class MDeviceBrightnessResponse : public MDeviceResponseBase { + // TODO: improve later - this has to be match with UI2HW in request + QMap HW2UI = { // has to map to keep the order + { 1, 20}, + { 3, 40}, + { 5, 60}, + { 6, 80}, + { 10, 100}, + }; + public: struct Data : MDeviceResponseBase::Data { quint8 mBrightnessPercent = 0; } _data; QVariantList parameters () const override { return { _data.mBrightnessPercent }; } - QString infoText () const override { return QString("DeviceBrightness") ; } - Data data () const { return _data; } + QString infoText () const override { return QString("DeviceBrightness") ; } + Data data () const { return _data; } + + Device::DeviceError::Scripts_Error_Enum setBrightnessPercent(quint8 vSysVal); }; // ---------- MDeviceBluetoothPaired 'Reset' ---------- //