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
Andy B-S
Companion App Android
Commits
8ca0e78b
Commit
8ca0e78b
authored
Aug 23, 2019
by
Stefan Zabka
Browse files
changed mood to personal state
parent
cc9015f6
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/ccc/events/badge/card10/common/ConnectionService.kt
View file @
8ca0e78b
...
...
@@ -31,9 +31,6 @@ import de.ccc.events.badge.card10.FILE_SERVICE_UUID
import
de.ccc.events.badge.card10.R
import
de.ccc.events.badge.card10.filetransfer.LowEffortService
import
de.ccc.events.badge.card10.time.Card10Service
import
java.lang.IllegalStateException
import
java.lang.NullPointerException
import
java.util.*
private
const
val
TAG
=
"ConnectionService"
...
...
@@ -127,9 +124,7 @@ object ConnectionService {
override
fun
onMtuChanged
(
gatt
:
BluetoothGatt
?,
newMtu
:
Int
,
status
:
Int
)
{
Log
.
d
(
TAG
,
"MTU changed to: $newMtu"
)
if
(
gatt
==
null
)
{
throw
IllegalStateException
()
}
checkNotNull
(
gatt
)
mtu
=
newMtu
-
3
// Very precise science
...
...
@@ -143,10 +138,8 @@ object ConnectionService {
characteristic
:
BluetoothGattCharacteristic
?,
status
:
Int
)
{
if
(
gatt
==
null
||
characteristic
==
null
)
{
throw
IllegalStateException
()
}
checkNotNull
(
gatt
)
checkNotNull
(
characteristic
)
connection
=
gatt
gattListeners
.
values
.
map
{
it
.
onCharacteristicWrite
(
characteristic
,
status
)
}
...
...
@@ -155,9 +148,8 @@ object ConnectionService {
override
fun
onCharacteristicChanged
(
gatt
:
BluetoothGatt
?,
characteristic
:
BluetoothGattCharacteristic
?)
{
connection
=
gatt
if
(
gatt
==
null
||
characteristic
==
null
)
{
throw
IllegalStateException
()
}
checkNotNull
(
gatt
)
checkNotNull
(
characteristic
)
gattListeners
.
values
.
map
{
it
.
onCharacteristicChanged
(
characteristic
)
}
}
...
...
app/src/main/java/de/ccc/events/badge/card10/mood/MoodFragment.kt
View file @
8ca0e78b
...
...
@@ -27,33 +27,33 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
de.ccc.events.badge.card10.PersonalState
import
de.ccc.events.badge.card10.R
import
de.ccc.events.badge.card10.common.ConnectionService
import
de.ccc.events.badge.card10.time.Card10Service
import
kotlinx.android.synthetic.main.mood_fragment.*
class
MoodFragment
:
Fragment
()
{
private
var
card10Service
:
Card10Service
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
card10Service
=
ConnectionService
.
card10Service
}
private
val
card10Service
=
ConnectionService
.
card10Service
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
mood_fragment
,
container
,
false
)
}
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
mood_good
.
setOnClickListener
{
card10Service
?.
setRocketValue
(
ubyteArrayOf
(
0xffu
,
0x00u
,
0x00u
).
toByteArray
())
mood_congress
.
setOnClickListener
{
card10Service
?.
setPersonalState
(
PersonalState
.
CHAOS
)
}
mood_chaos
.
setOnClickListener
{
card10Service
?.
setPersonalState
(
PersonalState
.
COMMUNICATION
)
}
mood_congress
.
setOnClickListener
{
card10Service
?.
setPersonalState
(
PersonalState
.
CAMP
)
}
mood_neutral
.
setOnClickListener
{
card10Service
?.
set
RocketValue
(
ubyteArrayOf
(
0x00u
,
0xffu
,
0x00u
).
toByteArray
()
)
no_contact
.
setOnClickListener
{
card10Service
?.
set
PersonalState
(
PersonalState
.
NO_CONTACT
)
}
mood_bad
.
setOnClickListener
{
card10Service
?.
set
RocketValue
(
ubyteArrayOf
(
0x00u
,
0x00u
,
0xffu
).
toByteArray
()
)
no_contact
.
setOnClickListener
{
card10Service
?.
set
PersonalState
(
PersonalState
.
NONE
)
}
}
}
app/src/main/java/de/ccc/events/badge/card10/time/Card10Service.kt
View file @
8ca0e78b
...
...
@@ -24,9 +24,7 @@ package de.ccc.events.badge.card10.time
import
android.bluetooth.BluetoothGattCharacteristic
import
android.bluetooth.BluetoothGattService
import
de.ccc.events.badge.card10.LEDS_ABOVE_CHARACTERISTIC_UUID
import
de.ccc.events.badge.card10.ROCKETS_CHARACTERISTIC_UUID
import
de.ccc.events.badge.card10.TIME_CHARACTERISTIC_UUID
import
de.ccc.events.badge.card10.*
import
de.ccc.events.badge.card10.common.ConnectionService
import
java.nio.ByteBuffer
...
...
@@ -35,12 +33,16 @@ class Card10Service(
)
{
private
val
timeCharacteristic
=
service
.
getCharacteristic
(
TIME_CHARACTERISTIC_UUID
)
private
val
rocketsCharacteristic
=
service
.
getCharacteristic
(
ROCKETS_CHARACTERISTIC_UUID
)
private
var
ledsAboveCharacteristic
=
service
.
getCharacteristic
(
LEDS_ABOVE_CHARACTERISTIC_UUID
)
private
val
ledsAboveCharacteristic
=
service
.
getCharacteristic
(
LEDS_ABOVE_CHARACTERISTIC_UUID
)
private
val
personalStateCharacteristic
=
service
.
getCharacteristic
(
PERSONAL_STATE_CHARACTERISTIC_UUID
)
init
{
timeCharacteristic
.
writeType
=
BluetoothGattCharacteristic
.
WRITE_TYPE_NO_RESPONSE
rocketsCharacteristic
.
writeType
=
BluetoothGattCharacteristic
.
WRITE_TYPE_NO_RESPONSE
ledsAboveCharacteristic
.
writeType
=
BluetoothGattCharacteristic
.
WRITE_TYPE_NO_RESPONSE
personalStateCharacteristic
.
writeType
=
BluetoothGattCharacteristic
.
WRITE_TYPE_NO_RESPONSE
}
fun
setTime
()
{
...
...
@@ -59,4 +61,10 @@ class Card10Service(
ledsAboveCharacteristic
.
value
=
value
ConnectionService
.
writeCharacteristic
(
ledsAboveCharacteristic
)
}
fun
setPersonalState
(
value
:
PersonalState
)
{
personalStateCharacteristic
.
value
=
ByteArray
(
1
)
personalStateCharacteristic
.
value
[
0
]
=
value
.
v
ConnectionService
.
writeCharacteristic
(
personalStateCharacteristic
)
}
}
\ No newline at end of file
app/src/main/res/layout/mood_fragment.xml
View file @
8ca0e78b
...
...
@@ -8,11 +8,15 @@
android:padding=
"16dp"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Mood"
/>
<Button
android:id=
"@+id/mood_good"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Good"
/>
<Button
android:id=
"@+id/mood_neutral"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Neutral"
/>
<Button
android:id=
"@+id/mood_bad"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Bad"
/>
android:layout_height=
"wrap_content"
android:text=
"@string/personal_state"
/>
<Button
android:id=
"@+id/mood_chaos"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/chaos"
/>
<Button
android:id=
"@+id/mood_communication"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/communication"
/>
<Button
android:id=
"@+id/mood_congress"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/congress"
/>
<Button
android:id=
"@+id/no_contact"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/no_contact"
/>
<Button
android:id=
"@+id/no_state"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/off"
/>
</LinearLayout>
app/src/main/res/values/strings.xml
View file @
8ca0e78b
...
...
@@ -44,4 +44,10 @@
<string
name=
"connection_error_generic"
>
Connection error
</string>
<string
name=
"connection_error_no_bonded_device"
>
No bonded card10s available
</string>
<string
name=
"personal_state"
>
Personal State
</string>
<string
name=
"chaos"
>
Chaos
</string>
<string
name=
"communication"
>
Communication
</string>
<string
name=
"congress"
>
Congress
</string>
<string
name=
"no_contact"
>
No Contact
</string>
<string
name=
"off"
>
Off
</string>
</resources>
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