2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
28 VERTICAL: (SERVO_RANGE.VERTICAL.MAX - SERVO_RANGE.VERTICAL.MIN) / 10,
29 HORIZONTAL: (SERVO_RANGE.HORIZONTAL.MAX - SERVO_RANGE.HORIZONTAL.MIN) / 10,
31 const CONTROL_TYPE_VERTICAL = "vertical";
32 const CONTROL_TYPE_HORIZONTAL = "horizontal";
34 var capabilityServoMotor = {
36 v: "/capability/audioVolume/main/0",
37 h: "/capability/switchLevel/main/0"
42 'update' : function() {
43 for (var item in this.href) {
44 ocfDevice.getRemoteRepresentation(this.href[item], this.onRepresentCallback);
48 'onRepresentCallback' : function(result, deviceHandle, uri, rcsJsonString) {
49 scplugin.log.debug(className, arguments.callee.name, result);
50 scplugin.log.debug(className, arguments.callee.name, uri);
52 if (result == "OCF_OK" || result == "OCF_RESOURCE_CHANGED" || result == "OCF_RES_ALREADY_SUBSCRIBED") {
53 if (uri == capabilityServoMotor.href.v) {
54 if(rcsJsonString["volume"] === undefined) return;
55 capabilityServoMotor.valueV = rcsJsonString["volume"];
56 } else if (uri == capabilityServoMotor.href.h) {
57 if(rcsJsonString["dimmingSetting"] === undefined) return;
58 capabilityServoMotor.valueH = rcsJsonString["dimmingSetting"];
63 'move' : function(type, value) {
66 scplugin.log.debug(className, arguments.callee.name, "Servo Motor type: " + type, "value: " + value);
68 if (type == CONTROL_TYPE_VERTICAL) {
69 setRcsJson["volume"] = value;
71 } else if (type == CONTROL_TYPE_HORIZONTAL) {
72 setRcsJson["dimmingSetting"] = value;
75 scplugin.log.debug(className, arguments.callee.name, "Servo Motor invalid type!");
78 ocfDevice.setRemoteRepresentation(href, setRcsJson, this.onRepresentCallback);
81 'moveDown' : function() {
82 var nextVal = this.valueV + SERVO_STEP.VERTICAL;
83 if (nextVal >= SERVO_RANGE.VERTICAL.MAX)
84 nextVal = SERVO_RANGE.VERTICAL.MAX;
86 this.move(CONTROL_TYPE_VERTICAL, nextVal);
89 'moveUp' : function() {
90 var nextVal = this.valueV - SERVO_STEP.VERTICAL;
91 if (nextVal <= SERVO_RANGE.VERTICAL.MIN)
92 nextVal = SERVO_RANGE.VERTICAL.MIN;
94 this.move(CONTROL_TYPE_VERTICAL, nextVal);
96 'moveLeft' : function() {
97 var nextVal = this.valueH + SERVO_STEP.HORIZONTAL;
98 if (nextVal >= SERVO_RANGE.HORIZONTAL.MAX)
99 nextVal = SERVO_RANGE.HORIZONTAL.MAX;
101 this.move(CONTROL_TYPE_HORIZONTAL, nextVal);
103 'moveRight' : function() {
104 var nextVal = this.valueH - SERVO_STEP.HORIZONTAL;
105 if (nextVal <= SERVO_RANGE.HORIZONTAL.MIN)
106 nextVal = SERVO_RANGE.HORIZONTAL.MIN;
108 this.move(CONTROL_TYPE_HORIZONTAL, nextVal);