Skip to content

Commit

Permalink
Merge pull request #1 from bbilger/main
Browse files Browse the repository at this point in the history
  • Loading branch information
weliem authored Sep 3, 2021
2 parents 339457e + 91cc159 commit 6b40c47
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions blessed/src/main/java/com/welie/blessed/BluetoothBytesParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ class BluetoothBytesParser (
FORMAT_UINT16 -> return if (byteOrder == LITTLE_ENDIAN) unsignedBytesToInt(value[offset], value[offset + 1]) else unsignedBytesToInt(
value[offset + 1], value[offset]
)
FORMAT_UINT24 -> return if (byteOrder == LITTLE_ENDIAN) unsignedBytesToInt(
value[offset], value[offset + 1],
value[offset + 2], 0.toByte()
) else unsignedBytesToInt(
0.toByte(), value[offset + 2],
value[offset + 1], value[offset]
)
FORMAT_UINT32 -> return if (byteOrder == LITTLE_ENDIAN) unsignedBytesToInt(
value[offset], value[offset + 1],
value[offset + 2], value[offset + 3]
Expand All @@ -157,6 +164,17 @@ class BluetoothBytesParser (
value[offset]
), 16
)
FORMAT_SINT24 -> return if (byteOrder == LITTLE_ENDIAN) unsignedToSigned(
unsignedBytesToInt(
value[offset],
value[offset + 1], value[offset + 2], 0.toByte()
), 24
) else unsignedToSigned(
unsignedBytesToInt(
0.toByte(),
value[offset + 2], value[offset + 1], value[offset]
), 24
)
FORMAT_SINT32 -> return if (byteOrder == LITTLE_ENDIAN) unsignedToSigned(
unsignedBytesToInt(
value[offset],
Expand Down Expand Up @@ -335,6 +353,27 @@ class BluetoothBytesParser (
this.value[index++] = (tempValue shr 8 and 0xFF).toByte()
this.value[index] = (tempValue and 0xFF).toByte()
}
FORMAT_SINT24 -> {
tempValue = intToSignedBits(value, 24)
if (byteOrder == LITTLE_ENDIAN) {
this.value[index++] = (tempValue and 0xFF).toByte()
this.value[index++] = (tempValue shr 8 and 0xFF).toByte()
this.value[index] = (tempValue shr 16 and 0xFF).toByte()
} else {
this.value[index++] = (tempValue shr 16 and 0xFF).toByte()
this.value[index++] = (tempValue shr 8 and 0xFF).toByte()
this.value[index] = (tempValue and 0xFF).toByte()
}
}
FORMAT_UINT24 -> if (byteOrder == LITTLE_ENDIAN) {
this.value[index++] = (tempValue and 0xFF).toByte()
this.value[index++] = (tempValue shr 8 and 0xFF).toByte()
this.value[index] = (tempValue shr 16 and 0xFF).toByte()
} else {
this.value[index++] = (tempValue shr 16 and 0xFF).toByte()
this.value[index++] = (tempValue shr 8 and 0xFF).toByte()
this.value[index] = (tempValue and 0xFF).toByte()
}
FORMAT_SINT32 -> {
tempValue = intToSignedBits(tempValue, 32)
if (byteOrder == LITTLE_ENDIAN) {
Expand Down Expand Up @@ -638,6 +677,11 @@ class BluetoothBytesParser (
*/
const val FORMAT_UINT16 = 0x12

/**
* Characteristic value format type uint24
*/
const val FORMAT_UINT24 = 0x13

/**
* Characteristic value format type uint32
*/
Expand All @@ -653,6 +697,11 @@ class BluetoothBytesParser (
*/
const val FORMAT_SINT16 = 0x22

/**
* Characteristic value format type sint24
*/
const val FORMAT_SINT24 = 0x23

/**
* Characteristic value format type sint32
*/
Expand Down

0 comments on commit 6b40c47

Please sign in to comment.