Commit 8ca0e78b authored by Stefan Zabka's avatar Stefan Zabka

changed mood to personal state

parent cc9015f6
......@@ -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) }
}
......
......@@ -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?.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,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
......@@ -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>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment