stpihkal
stpihkal copied to clipboard
Add Youou Wand Vibrator documentation
// Byte 2 seems to be a monotonically increasing packet id of some kind
// Speed seems to be 0-247 or so. Anything above that sets a pattern which
// isn't what we want here.
const maxValue = 247;
const speed = aMsg.Speed * maxValue;
const state = aMsg.Speed > 0 ? 1 : 0;
const cmdData = Buffer.from([0xaa, 0x55, this._packetId, 0x02, 0x03, 0x01,
speed, state]);
let crc = 0;
// Simple XOR of everything up to the 9th byte for CRC.
for (const byte of cmdData) {
crc = byte ^ crc;
}
const data = Buffer.concat([cmdData,
Buffer.from([crc, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])]);
this._packetId += 1;
if (this._packetId > 255) {
this._packetId = 0;
}
await this._device.WriteValue(data);
return new Messages.Ok(aMsg.Id);