Android 事情:使用命令 writeBuffer、write、byte[] 在 i2c 寄存器中写入许多字节
Android things: using commands writeBuffer, write, byte[] to write many bytes in i2c registers
我正在开发一个移动直流电机的应用程序,使用 android 东西。
在这个阶段我已经知道我必须处理哪些命令,但我不知道如何处理。 ()
下面的 i2c 示例来自指南 google 开发人员:
public void writeBuffer (I2cDevice device, byte [] buffer) throws IOException {
int count = device.write (buffer, buffer.length);
Log.d (TAG, "Wrote" + count + "bytes over I2C.");
}
我的问题(基于上面的代码)是:
1) 如何在缓冲区中写入(在 Kotlin 中)pio i2c I2C1 0x1B write-raw 0x46 128 0x05 0x00 0xD1 以作为参数传递给 writeBuffer 函数?
例如:var buffer = (new byte[] (byte) 0x46, 128, 0x05, 0x00, 0xD1, value.i2cValue.toByteArray()),无效。
我的最终项目基于以下项目:
https://github.com/Nilhcem/i2cfun-androidthings/tree/arduino_slave/app/src/main/java/com/nilhcem/androidthings/i2cfun
quote: 我知道 I2C1 和 0x1B 不是必需的,因为它们是在 I2cDevice 之前或在 I2cDevice 中传递的参数。
我解决了:val buffer = byteArrayOf(0x46, 128.toByte(), 0x05, 0x00, 0xD1.toByte()) and device?.write(buffer, buffer.size)
我正在开发一个移动直流电机的应用程序,使用 android 东西。
在这个阶段我已经知道我必须处理哪些命令,但我不知道如何处理。 (
下面的 i2c 示例来自指南 google 开发人员:
public void writeBuffer (I2cDevice device, byte [] buffer) throws IOException {
int count = device.write (buffer, buffer.length);
Log.d (TAG, "Wrote" + count + "bytes over I2C.");
}
我的问题(基于上面的代码)是:
1) 如何在缓冲区中写入(在 Kotlin 中)pio i2c I2C1 0x1B write-raw 0x46 128 0x05 0x00 0xD1 以作为参数传递给 writeBuffer 函数?
例如:var buffer = (new byte[] (byte) 0x46, 128, 0x05, 0x00, 0xD1, value.i2cValue.toByteArray()),无效。
我的最终项目基于以下项目: https://github.com/Nilhcem/i2cfun-androidthings/tree/arduino_slave/app/src/main/java/com/nilhcem/androidthings/i2cfun
quote: 我知道 I2C1 和 0x1B 不是必需的,因为它们是在 I2cDevice 之前或在 I2cDevice 中传递的参数。
我解决了:val buffer = byteArrayOf(0x46, 128.toByte(), 0x05, 0x00, 0xD1.toByte()) and device?.write(buffer, buffer.size)