Untitled

Java:

public static byte[] reverse(byte[] arr)
{
    byte[] buf = new byte[arr.length];
    int len = arr.length;
    for (int i = 0; i < len; i++) {
        buf[i] = arr[len - 1 - i];
    }
    return buf;
}

public void set_facediff(float value) 
{
    byte[] buf = reverse(ByteBuffer.allocate(4).putFloat(value).array());
    byte[] cmd = new byte[1];
    cmd[0] = 0x00;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {
        bos.write(cmd);
        bos.write(buf);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    byte[] iobuf = bos.toByteArray();
    ioctl(ctx, iobuf);

}

public float get_facediff()
{
    float facediff = 0.0f;
    byte[] cmd = new byte[5];
    cmd[0] = 0x01;
    ioctl(ctx, cmd);

    byte[] b = reverse(Arrays.copyOfRange(cmd, 1,cmd.length));
    ByteBuffer buffer = ByteBuffer.wrap(b);
    facediff = buffer.getFloat();

    return facediff;
}

Python:

C:

Don't forget to flush the remaining bytes less than 16!

Last updated

Was this helpful?