Garmin queue (DIRTY)
This commit is contained in:
parent
0c6e305aea
commit
307343c2eb
1 changed files with 22 additions and 6 deletions
|
@ -5,8 +5,10 @@ import android.bluetooth.BluetoothAdapter
|
||||||
import android.bluetooth.BluetoothDevice
|
import android.bluetooth.BluetoothDevice
|
||||||
import android.bluetooth.BluetoothSocket
|
import android.bluetooth.BluetoothSocket
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import me.trevi.navparser.lib.NavigationData
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.SynchronousQueue
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
|
@ -23,6 +25,14 @@ class Garmin(
|
||||||
thread.start()
|
thread.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun send(data: IntArray) {
|
||||||
|
thread.enqueue(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun send(data: NavigationData) {
|
||||||
|
Log.d("SEND_DATA", "$data.remainingDistance.distance")
|
||||||
|
}
|
||||||
|
|
||||||
fun close() {
|
fun close() {
|
||||||
thread.close()
|
thread.close()
|
||||||
}
|
}
|
||||||
|
@ -34,6 +44,13 @@ class Garmin(
|
||||||
device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
|
device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val queue: SynchronousQueue<IntArray> = SynchronousQueue()
|
||||||
|
|
||||||
|
fun enqueue(data: IntArray) {
|
||||||
|
// queue.clear() // for immediate run
|
||||||
|
queue.put(data)
|
||||||
|
}
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
// Cancel discovery because it otherwise slows down the connection.
|
// Cancel discovery because it otherwise slows down the connection.
|
||||||
context.checkBt()
|
context.checkBt()
|
||||||
|
@ -41,10 +58,9 @@ class Garmin(
|
||||||
socket?.connect()
|
socket?.connect()
|
||||||
sleep(3000)
|
sleep(3000)
|
||||||
readAll()
|
readAll()
|
||||||
send(intArrayOf(1, 1, 0, 16))
|
while (true) {
|
||||||
send(intArrayOf(3, 0, 1, 10, 0, 10, 3))
|
queue.poll()?.let { send(it) }
|
||||||
send(intArrayOf(3, 0, 0, 9, 0, 9, 3))
|
}
|
||||||
send(intArrayOf(0x04, 0x01))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closes the client socket and causes the thread to finish.
|
// Closes the client socket and causes the thread to finish.
|
||||||
|
@ -66,8 +82,8 @@ class Garmin(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun send(hex: IntArray) {
|
fun send(data: IntArray) {
|
||||||
sendRaw(prepareData(hex))
|
sendRaw(prepareData(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendRaw(buff: IntArray) {
|
private fun sendRaw(buff: IntArray) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue