From 38435931877c81cbc7b5023c2e78c77e8e13edfd Mon Sep 17 00:00:00 2001 From: Rafal Galka Date: Wed, 25 Mar 2015 11:16:42 +0100 Subject: [PATCH] [Notification] LED implementation Change-Id: I69788dbf129c40ce0e1f08d13f7474c0b7017762 --- src/notification/notification.gyp | 3 +- src/notification/notification_api.js | 66 +++++++++++++++++++++++ src/notification/notification_instance.cc | 26 +++++++++ src/notification/notification_instance.h | 5 ++ src/notification/notification_manager.cc | 44 ++++++++++++++- src/notification/notification_manager.h | 3 ++ 6 files changed, 145 insertions(+), 2 deletions(-) diff --git a/src/notification/notification.gyp b/src/notification/notification.gyp index 2d7e10d0..9c219a8c 100755 --- a/src/notification/notification.gyp +++ b/src/notification/notification.gyp @@ -24,7 +24,8 @@ ['tizen == 1', { 'variables': { 'packages': [ - 'notification' + 'notification', + 'capi-system-device', ] }, }], diff --git a/src/notification/notification_api.js b/src/notification/notification_api.js index 72834248..1b42396c 100644 --- a/src/notification/notification_api.js +++ b/src/notification/notification_api.js @@ -9,6 +9,27 @@ var validator_ = utils_.validator; var types_ = validator_.Types; var native_ = new xwalk.utils.NativeManager(extension); +function convertColorToInt(rgbaColor) { + var color = rgbaColor.length === 7 ? rgbaColor + 'ff' : rgbaColor; + var isLengthOk = color.length === 9; + var isHash = color.substr(0, 1) === '#'; + var hex = '0123456789abcdefABCDEF'; + var isHex = true; + var c = color.replace('#', ''); + + for (var i = 0; i < c.length; i++) { + if (hex.indexOf(c[i]) < 0) { + isHex = false; + } + } + + if (!isLengthOk || !isHash || !isHex) { + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, 'invalid value'); + } + + return parseInt('0x' + c); +} + var EditManager = function() { this.canEdit = false; }; @@ -39,6 +60,11 @@ var NotificationProgressType = { BYTE: 'BYTE' }; +var LEDCustomFlags = { + LED_CUSTOM_DUTY_ON: 'LED_CUSTOM_DUTY_ON', + LED_CUSTOM_DEFAULT: 'LED_CUSTOM_DEFAULT' +}; + function NotificationManager() {} @@ -168,6 +194,46 @@ NotificationManager.prototype.getAll = function() { return notifications; }; +/** + * Plays the custom effect of the service LED that is located to the front of a device. + * + * @param timeOn Number + * @param timeOff Number + * @param color String + * @param flags Array + */ +NotificationManager.prototype.playLEDCustomEffect = function(timeOn, timeOff, color, flags) { + var args = validator_.validateArgs(arguments, [ + {name: 'timeOn', type: types_.LONG}, + {name: 'timeOff', type: types_.LONG}, + {name: 'color', type: types_.STRING}, + {name: 'flags', type: types_.ARRAY, values: types_.STRING} + ]); + + for (var i = 0; i < args.flags.length; ++i) { + if (Object.keys(LEDCustomFlags).indexOf(args.flags[i]) < 0) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'invalid value'); + } + } + + args.color = convertColorToInt(args.color); + var result = native_.callSync('NotificationManager_playLEDCustomEffect', args); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } +}; + +/** + * Stops the custom effect of the service LED that is located to the front of a device. + */ +NotificationManager.prototype.stopLEDCustomEffect = function() { + var result = native_.callSync('NotificationManager_stopLEDCustomEffect'); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } +}; + + function NotificationInitDict(data) { var _iconPath = null; var _soundPath = null; diff --git a/src/notification/notification_instance.cc b/src/notification/notification_instance.cc index 3fa58c58..01790d1a 100644 --- a/src/notification/notification_instance.cc +++ b/src/notification/notification_instance.cc @@ -33,6 +33,10 @@ NotificationInstance::NotificationInstance() { REGISTER_SYNC("NotificationManager_getAll", NotificationManagerGetAll); REGISTER_SYNC("NotificationManager_post", NotificationManagerPost); REGISTER_SYNC("NotificationManager_removeAll", NotificationManagerRemoveAll); + REGISTER_SYNC("NotificationManager_playLEDCustomEffect", + NotificationManagerPlayLEDCustomEffect); + REGISTER_SYNC("NotificationManager_stopLEDCustomEffect", + NotificationManagerStopLEDCustomEffect); #undef REGISTER_SYNC manager_ = NotificationManager::GetInstance(); @@ -126,6 +130,28 @@ void NotificationInstance::NotificationManagerGetAll( ReportError(status, &out); } +void NotificationInstance::NotificationManagerPlayLEDCustomEffect( + const picojson::value& args, picojson::object& out) { + + PlatformResult status = manager_->PlayLEDCustomEffect(args.get()); + + if (status.IsSuccess()) + ReportSuccess(out); + else + ReportError(status, &out); +} + +void NotificationInstance::NotificationManagerStopLEDCustomEffect( + const picojson::value& /*args*/, picojson::object& out) { + + PlatformResult status = manager_->StopLEDCustomEffect(); + + if (status.IsSuccess()) + ReportSuccess(out); + else + ReportError(status, &out); +} + #undef CHECK_EXIST } // namespace notification diff --git a/src/notification/notification_instance.h b/src/notification/notification_instance.h index 958e7941..425668e2 100644 --- a/src/notification/notification_instance.h +++ b/src/notification/notification_instance.h @@ -31,6 +31,11 @@ class NotificationInstance : public common::ParsedInstance { picojson::object& out); void NotificationManagerGetAll(const picojson::value& args, picojson::object& out); + + void NotificationManagerPlayLEDCustomEffect(const picojson::value& args, + picojson::object& out); + void NotificationManagerStopLEDCustomEffect(const picojson::value& args, + picojson::object& out); }; } // namespace notification diff --git a/src/notification/notification_manager.cc b/src/notification/notification_manager.cc index e18d9772..ffd1c3b0 100644 --- a/src/notification/notification_manager.cc +++ b/src/notification/notification_manager.cc @@ -4,8 +4,9 @@ #include "notification/notification_manager.h" -#include #include +#include +#include #include "common/converter.h" #include "common/logger.h" @@ -140,5 +141,46 @@ PlatformResult NotificationManager::GetAll(picojson::array& out) { return PlatformResult(ErrorCode::NO_ERROR); } +PlatformResult NotificationManager::PlayLEDCustomEffect( + const picojson::object& args) { + LOGGER(DEBUG) << "entered"; + + int timeOn = FromJson(args, "timeOn"); + int timeOff = FromJson(args, "timeOff"); + unsigned int color = FromJson(args, "color"); + + auto& flags = FromJson(args, "flags"); + unsigned int platformFlags = 0; + for (auto flag : flags) { + std::string flagStr = JsonCast(flag); + if (flagStr == "LED_CUSTOM_DEFAULT") + platformFlags |= LED_CUSTOM_DEFAULT; + else if (flagStr == "LED_CUSTOM_DUTY_ON") + platformFlags |= LED_CUSTOM_DUTY_ON; + } + + int ret; + ret = device_led_play_custom(timeOn, timeOff, color, platformFlags); + if (ret != DEVICE_ERROR_NONE) { + LOGGER(ERROR) << "Cannot play LED custom effect: " << ret; + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot play LED custom effect"); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult NotificationManager::StopLEDCustomEffect() { + LOGGER(DEBUG) << "entered"; + + int ret = DEVICE_ERROR_NONE; + ret = device_led_stop_custom(); + if (ret != DEVICE_ERROR_NONE) { + LOGGER(ERROR) << "Cannot stop LED custom effect: " << ret; + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot stop LED custom effect"); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + } // namespace notification } // namespace extension diff --git a/src/notification/notification_manager.h b/src/notification/notification_manager.h index 9d977e85..53bf0438 100644 --- a/src/notification/notification_manager.h +++ b/src/notification/notification_manager.h @@ -26,6 +26,9 @@ class NotificationManager { picojson::object& out); common::PlatformResult GetAll(picojson::array& out); + common::PlatformResult PlayLEDCustomEffect(const picojson::object& args); + common::PlatformResult StopLEDCustomEffect(); + private: NotificationManager(); virtual ~NotificationManager(); -- 2.34.1