Skip to content
Snippets Groups Projects
Commit 56652f40 authored by Stefan Zabka's avatar Stefan Zabka
Browse files

changed mood to personal state

parent 4b2776d9
No related branches found
No related tags found
No related merge requests found
......@@ -50,12 +50,12 @@ val LEDS_POWERSAFE_CHARACTERISTIC_UUID = UUID.fromString("42230217-2342-2342-234
val FLASHLIGHT_CHARACTERISTIC_UUID = UUID.fromString("42230218-2342-2342-2342-234223422342")
val PERSONAL_STATE_CHARACTERISTIC_UUID = UUID.fromString("42230219-2342-2342-2342-234223422342")
enum class PersonalState(val v: Byte) {
enum class PersonalState(val v: Int) {
NONE(0x0000),
NO_CONTACT(0x0100.toByte()),
CHAOS(0x0200.toByte()),
COMMUNICATION(0x0300.toByte()),
CAMP(0x0400.toByte())
NO_CONTACT(0x0100),
CHAOS(0x0200),
COMMUNICATION(0x0300),
CAMP(0x0400)
}
val LEDS_ABOVE_CHARACTERISTIC_UUID = UUID.fromString("42230220-2342-2342-2342-234223422342")
......
......@@ -31,7 +31,7 @@ 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.util.*
private const val TAG = "ConnectionService"
......@@ -130,9 +130,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
......@@ -146,10 +144,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) }
......@@ -158,9 +154,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) }
}
......
......@@ -27,34 +27,34 @@ 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.*
@ExperimentalUnsignedTypes
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?.setRocketValue(ubyteArrayOf(0x00u, 0xffu, 0x00u).toByteArray())
no_contact.setOnClickListener{
card10Service?.setPersonalState(PersonalState.NO_CONTACT)
}
mood_bad.setOnClickListener{
card10Service?.setRocketValue(ubyteArrayOf(0x00u, 0x00u, 0xffu).toByteArray())
no_contact.setOnClickListener{
card10Service?.setPersonalState(PersonalState.NONE)
}
}
}
......@@ -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,13 @@ class Card10Service(
ledsAboveCharacteristic.value = value
ConnectionService.writeCharacteristic(ledsAboveCharacteristic)
}
fun setPersonalState(value: PersonalState) {
personalStateCharacteristic.value = ByteArray(2)
personalStateCharacteristic.value[0] = value.v.toByte()
personalStateCharacteristic.value[1] = (value.v shr 8).toByte()
println("=== Writing personal State array : ${personalStateCharacteristic.value[0]},${personalStateCharacteristic.value[1]} ")
ConnectionService.writeCharacteristic(personalStateCharacteristic)
}
}
\ No newline at end of file
......@@ -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>
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment