Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Zabka
Companion App Android
Commits
c05c72c6
Commit
c05c72c6
authored
Aug 16, 2019
by
Andreas Schildbach
Browse files
SetClockJob: Actually update the time, rather than blinking an LED.
parent
fa972779
Changes
2
Show whitespace changes
Inline
Side-by-side
app/src/main/java/de/ccc/events/badge/card10/Constants.kt
View file @
c05c72c6
...
...
@@ -32,3 +32,4 @@ val VIBRA_CHARACTERISTIC_UUID = UUID.fromString("4223020f-2342-2342-2342-2342234
val
ROCKETS_CHARACTERISTIC_UUID
=
UUID
.
fromString
(
"42230210-2342-2342-2342-234223422342"
)
val
SINGLE_LED_CHARACTERISTIC_UUID
=
UUID
.
fromString
(
"42230211-2342-2342-2342-234223422342"
)
val
LIGHT_SENSOR_CHARACTERISTIC_UUID
=
UUID
.
fromString
(
"422302f0-2342-2342-2342-234223422342"
)
val
TIME_CHARACTERISTIC_UUID
=
UUID
.
fromString
(
"42230201-2342-2342-2342-234223422342"
)
app/src/main/java/de/ccc/events/badge/card10/background/SetClockJob.kt
View file @
c05c72c6
...
...
@@ -30,7 +30,8 @@ import android.content.Context
import
androidx.work.Worker
import
androidx.work.WorkerParameters
import
de.ccc.events.badge.card10.CARD10_SERVICE_UUID
import
de.ccc.events.badge.card10.ROCKETS_CHARACTERISTIC_UUID
import
de.ccc.events.badge.card10.TIME_CHARACTERISTIC_UUID
import
java.nio.ByteBuffer
import
java.util.concurrent.CountDownLatch
import
java.util.concurrent.TimeUnit
...
...
@@ -45,7 +46,7 @@ class SetClockJob(context: Context, workerParameters: WorkerParameters) : Worker
try
{
val
gattLatch
=
CountDownLatch
(
1
);
var
writeLatch
:
CountDownLatch
?
=
null
var
rockets
Characteristic
:
BluetoothGattCharacteristic
?
=
null
var
time
Characteristic
:
BluetoothGattCharacteristic
?
=
null
val
callback
=
object
:
BluetoothGattCallback
()
{
override
fun
onConnectionStateChange
(
gatt
:
BluetoothGatt
,
status
:
Int
,
newState
:
Int
)
{
System
.
out
.
println
(
"=== doWork() onConnectionStateChange "
+
gatt
+
" / "
+
status
+
" / "
+
newState
)
...
...
@@ -56,7 +57,7 @@ class SetClockJob(context: Context, workerParameters: WorkerParameters) : Worker
override
fun
onServicesDiscovered
(
gatt
:
BluetoothGatt
,
status
:
Int
)
{
System
.
out
.
println
(
"=== doWork() onServicesDiscovered "
+
gatt
+
" / "
+
status
)
val
card10Service
=
gatt
.
getService
(
CARD10_SERVICE_UUID
)
rockets
Characteristic
=
card10Service
.
getCharacteristic
(
ROCKETS
_CHARACTERISTIC_UUID
)
time
Characteristic
=
card10Service
.
getCharacteristic
(
TIME
_CHARACTERISTIC_UUID
)
gattLatch
.
countDown
()
}
...
...
@@ -72,24 +73,14 @@ class SetClockJob(context: Context, workerParameters: WorkerParameters) : Worker
if
(!
gattLatch
.
await
(
1
,
TimeUnit
.
MINUTES
))
return
Result
.
retry
()
// TODO at this point update the clock, rather than blinking the LED
rocketsCharacteristic
?.
value
=
ubyteArrayOf
(
0xffu
,
0x00u
,
0x00u
).
toByteArray
()
if
(
gatt
.
writeCharacteristic
(
rocketsCharacteristic
))
{
writeLatch
=
CountDownLatch
(
1
)
if
(!
writeLatch
.
await
(
1
,
TimeUnit
.
MINUTES
))
return
Result
.
failure
()
System
.
out
.
println
(
"=== doWork() rocket flash on"
)
}
Thread
.
sleep
(
1000
)
rocketsCharacteristic
?.
value
=
ubyteArrayOf
(
0x00u
,
0x00u
,
0x00u
).
toByteArray
()
if
(
gatt
.
writeCharacteristic
(
rocketsCharacteristic
))
{
val
buffer
=
ByteBuffer
.
allocate
(
8
)
buffer
.
putLong
(
System
.
currentTimeMillis
())
timeCharacteristic
?.
value
=
buffer
.
array
()
if
(
gatt
.
writeCharacteristic
(
timeCharacteristic
))
{
writeLatch
=
CountDownLatch
(
1
)
if
(!
writeLatch
.
await
(
1
,
TimeUnit
.
MINUTES
))
return
Result
.
failure
()
System
.
out
.
println
(
"=== doWork()
rocket flash off
"
)
System
.
out
.
println
(
"=== doWork()
updated time
"
)
}
}
catch
(
x
:
Exception
)
{
x
.
printStackTrace
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment