stpihkal icon indicating copy to clipboard operation
stpihkal copied to clipboard

Add Youou Wand Vibrator documentation

Open qdot opened this issue 6 years ago • 0 comments

      // 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);

qdot avatar Feb 27 '19 06:02 qdot