Improve color picker throttling
This commit is contained in:
parent
a390f09618
commit
e73188fa92
@ -262,6 +262,20 @@ DevicePageBase {
|
|||||||
id: colorPicker
|
id: colorPicker
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
property int pendingCommand: -1
|
||||||
|
|
||||||
|
property var queuedColor: null
|
||||||
|
|
||||||
|
function sendColor(color) {
|
||||||
|
var params = [];
|
||||||
|
var param1 = {};
|
||||||
|
param1["paramTypeId"] = root.colorActionType.paramTypes.get(0).id;
|
||||||
|
param1["value"] = color;
|
||||||
|
params.push(param1)
|
||||||
|
colorPicker.pendingCommand = engine.deviceManager.executeAction(root.device.id, root.colorActionType.id, params)
|
||||||
|
print("sent command", colorPicker.pendingCommand, color)
|
||||||
|
}
|
||||||
|
|
||||||
color: root.colorState ? root.colorState.value : "white"
|
color: root.colorState ? root.colorState.value : "white"
|
||||||
touchDelegate: Rectangle {
|
touchDelegate: Rectangle {
|
||||||
height: 15
|
height: 15
|
||||||
@ -283,19 +297,33 @@ DevicePageBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property var lastSentTime: new Date()
|
|
||||||
onColorChanged: {
|
Connections {
|
||||||
var currentTime = new Date();
|
target: engine.deviceManager
|
||||||
if (pressed && currentTime - lastSentTime > 200) {
|
onExecuteActionReply: {
|
||||||
var params = [];
|
print("action finished", JSON.stringify(params))
|
||||||
var param1 = {};
|
if (params.id === colorPicker.pendingCommand) {
|
||||||
param1["paramTypeId"] = root.colorActionType.paramTypes.get(0).id;
|
colorPicker.pendingCommand = -1;
|
||||||
param1["value"] = color;
|
if (colorPicker.queuedColor) {
|
||||||
params.push(param1)
|
colorPicker.sendColor(colorPicker.queuedColor);
|
||||||
engine.deviceManager.executeAction(root.device.id, root.colorActionType.id, params)
|
colorPicker.queuedColor = null
|
||||||
lastSentTime = currentTime
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onColorChanged: {
|
||||||
|
if (!pressed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pendingCommand != -1) {
|
||||||
|
queuedColor = color;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user