diff --git a/src/procedures/phone-iot/device.js b/src/procedures/phone-iot/device.js index 9e089a2d..a34093a5 100644 --- a/src/procedures/phone-iot/device.js +++ b/src/procedures/phone-iot/device.js @@ -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 @@ -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]); @@ -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); diff --git a/src/procedures/phone-iot/phone-iot.js b/src/procedures/phone-iot/phone-iot.js index 56fe3553..9896e2d2 100644 --- a/src/procedures/phone-iot/phone-iot.js +++ b/src/procedures/phone-iot/phone-iot.js @@ -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. diff --git a/test/procedures/phone-iot.spec.js b/test/procedures/phone-iot.spec.js index 0973bf48..bdc98d71 100644 --- a/test/procedures/phone-iot.spec.js +++ b/test/procedures/phone-iot.spec.js @@ -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"]],