Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/procedures/phone-iot/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const { setTimeout } = require("../../timers");
// R - rotation vector
// r - game rotation vector
// S - step counter
// s - set style (colors)
// T - add custom text field
// t - text field content
// U - add custom image box
Expand Down Expand Up @@ -587,6 +588,21 @@ Device.prototype.setImage = async function (device, args, clientId) {

throwIfErr(await response);
};
Device.prototype.setColor = async function (device, args, clientId) {
const { response, password } = this.rpcHeader("setcolor", clientId);
const id = parseId(args[0]);

const message = Buffer.alloc(18);
message.write("s", 0, 1);
message.writeBigInt64BE(common.gracefulPasswordParse(password), 1);
message.writeInt32BE(args[1], 9);
message.writeInt32BE(args[2], 13);
message[17] = id.length;

this.sendToDevice(Buffer.concat([message, id]));

throwIfErr(await response);
};
Device.prototype.setText = async function (device, args, clientId) {
const { response, password } = this.rpcHeader("settext", clientId);
const id = parseId(args[0]);
Expand Down Expand Up @@ -1212,6 +1228,7 @@ Device.prototype.onMessage = function (message) {
});
}
} else if (command === "H") this._sendControlResult("settext", message);
else if (command === "s") this._sendControlResult("setcolor", message);
else if (command === "e") this._sendControlResult("setlevel", message);
else if (command === "i") this._sendControlResult("setimage", message);
else if (command === "g") this._sendControlResult("addlabel", message);
Expand Down
14 changes: 14 additions & 0 deletions src/procedures/phone-iot/phone-iot.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,20 @@ if (PHONE_IOT_MODE === "native" || PHONE_IOT_MODE === "both") {
arguments[4] = _.merge({}, DEFAULTS, options);
return this._passToDevice("addRadioButton", arguments);
};
/**
* Sets the primary and secondary colors of an existing control that supports custom colors.
* Some controls only use one color (not two), in which case the secondary will be ignored.
*
* @category Display
* @param {Device} device id of the device
* @param {String} id id of the control to modify
* @param {Color} primary primary color to use
* @param {Color=} secondary secondary color to use
*/
PhoneIoT.prototype.setColor = function (device, id, primary, secondary) {
arguments[2] = secondary || this.getColor(0, 0, 0);
return this._passToDevice("setColor", arguments);
};
/**
* Sets the text content of the text-like control with the given ID.
* This can be used on any control that has text, such as a button, label, or text field.
Expand Down
1 change: 1 addition & 0 deletions test/procedures/phone-iot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe(utils.suiteName(__filename), function () {
["magnitude", ["vec"]],
["normalize", ["vec"]],
["setText", ["device", "id", "text"]],
["setColor", ["device", "id", "primary", "secondary"]],
["getText", ["device", "id"]],
["setCredentials", ["device", "password"]],
["getPressure", ["device"]],
Expand Down
Loading