Commit 56652f40 authored by Stefan Zabka's avatar Stefan Zabka
Browse files

changed mood to personal state

parent 4b2776d9
...@@ -50,12 +50,12 @@ val LEDS_POWERSAFE_CHARACTERISTIC_UUID = UUID.fromString("42230217-2342-2342-234 ...@@ -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 FLASHLIGHT_CHARACTERISTIC_UUID = UUID.fromString("42230218-2342-2342-2342-234223422342")
val PERSONAL_STATE_CHARACTERISTIC_UUID = UUID.fromString("42230219-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), NONE(0x0000),
NO_CONTACT(0x0100.toByte()), NO_CONTACT(0x0100),
CHAOS(0x0200.toByte()), CHAOS(0x0200),
COMMUNICATION(0x0300.toByte()), COMMUNICATION(0x0300),
CAMP(0x0400.toByte()) CAMP(0x0400)
} }
val LEDS_ABOVE_CHARACTERISTIC_UUID = UUID.fromString("42230220-2342-2342-2342-234223422342") 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 ...@@ -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.R
import de.ccc.events.badge.card10.filetransfer.LowEffortService import de.ccc.events.badge.card10.filetransfer.LowEffortService
import de.ccc.events.badge.card10.time.Card10Service import de.ccc.events.badge.card10.time.Card10Service
import java.util.*
private const val TAG = "ConnectionService" private const val TAG = "ConnectionService"
...@@ -130,9 +130,7 @@ object ConnectionService { ...@@ -130,9 +130,7 @@ object ConnectionService {
override fun onMtuChanged(gatt: BluetoothGatt?, newMtu: Int, status: Int) { override fun onMtuChanged(gatt: BluetoothGatt?, newMtu: Int, status: Int) {
Log.d(TAG, "MTU changed to: $newMtu") Log.d(TAG, "MTU changed to: $newMtu")
if (gatt == null) { checkNotNull(gatt)
throw IllegalStateException()
}
mtu = newMtu - 3 // Very precise science mtu = newMtu - 3 // Very precise science
...@@ -146,10 +144,8 @@ object ConnectionService { ...@@ -146,10 +144,8 @@ object ConnectionService {
characteristic: BluetoothGattCharacteristic?, characteristic: BluetoothGattCharacteristic?,
status: Int status: Int
) { ) {
if (gatt == null || characteristic == null) { checkNotNull(gatt)
throw IllegalStateException() checkNotNull(characteristic)
}
connection = gatt connection = gatt
gattListeners.values.map { it.onCharacteristicWrite(characteristic, status) } gattListeners.values.map { it.onCharacteristicWrite(characteristic, status) }
...@@ -158,9 +154,8 @@ object ConnectionService { ...@@ -158,9 +154,8 @@ object ConnectionService {
override fun onCharacteristicChanged(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?) { override fun onCharacteristicChanged(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?) {
connection = gatt connection = gatt
if (gatt == null || characteristic == null) { checkNotNull(gatt)
throw IllegalStateException() checkNotNull(characteristic)
}
gattListeners.values.map { it.onCharacteristicChanged(characteristic) } gattListeners.values.map { it.onCharacteristicChanged(characteristic) }
} }
......
...@@ -27,34 +27,34 @@ import android.view.LayoutInflater ...@@ -27,34 +27,34 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment 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.R
import de.ccc.events.badge.card10.common.ConnectionService import de.ccc.events.badge.card10.common.ConnectionService
import de.ccc.events.badge.card10.time.Card10Service
import kotlinx.android.synthetic.main.mood_fragment.* import kotlinx.android.synthetic.main.mood_fragment.*
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
class MoodFragment : Fragment() { class MoodFragment : Fragment() {
private var card10Service: Card10Service? = null private val card10Service = ConnectionService.card10Service
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
card10Service = ConnectionService.card10Service
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.mood_fragment, container, false) return inflater.inflate(R.layout.mood_fragment, container, false)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
mood_good.setOnClickListener{ mood_congress.setOnClickListener{
card10Service?.setRocketValue(ubyteArrayOf(0xffu, 0x00u, 0x00u).toByteArray()) card10Service?.setPersonalState(PersonalState.CHAOS)
}
mood_chaos.setOnClickListener{
card10Service?.setPersonalState(PersonalState.COMMUNICATION)
}
mood_congress.setOnClickListener{
card10Service?.setPersonalState(PersonalState.CAMP)
} }
mood_neutral.setOnClickListener{ no_contact.setOnClickListener{
card10Service?.setRocketValue(ubyteArrayOf(0x00u, 0xffu, 0x00u).toByteArray()) card10Service?.setPersonalState(PersonalState.NO_CONTACT)
} }
mood_bad.setOnClickListener{ no_contact.setOnClickListener{
card10Service?.setRocketValue(ubyteArrayOf(0x00u, 0x00u, 0xffu).toByteArray()) card10Service?.setPersonalState(PersonalState.NONE)
} }
} }
} }
...@@ -24,9 +24,7 @@ package de.ccc.events.badge.card10.time ...@@ -24,9 +24,7 @@ package de.ccc.events.badge.card10.time
import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattService import android.bluetooth.BluetoothGattService
import de.ccc.events.badge.card10.LEDS_ABOVE_CHARACTERISTIC_UUID import de.ccc.events.badge.card10.*
import de.ccc.events.badge.card10.ROCKETS_CHARACTERISTIC_UUID
import de.ccc.events.badge.card10.TIME_CHARACTERISTIC_UUID
import de.ccc.events.badge.card10.common.ConnectionService import de.ccc.events.badge.card10.common.ConnectionService
import java.nio.ByteBuffer import java.nio.ByteBuffer
...@@ -35,12 +33,16 @@ class Card10Service( ...@@ -35,12 +33,16 @@ class Card10Service(
) { ) {
private val timeCharacteristic = service.getCharacteristic(TIME_CHARACTERISTIC_UUID) private val timeCharacteristic = service.getCharacteristic(TIME_CHARACTERISTIC_UUID)
private val rocketsCharacteristic = service.getCharacteristic(ROCKETS_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 { init {
timeCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE timeCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
rocketsCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE rocketsCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
ledsAboveCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE ledsAboveCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
personalStateCharacteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
} }
fun setTime() { fun setTime() {
...@@ -59,4 +61,13 @@ class Card10Service( ...@@ -59,4 +61,13 @@ class Card10Service(
ledsAboveCharacteristic.value = value ledsAboveCharacteristic.value = value
ConnectionService.writeCharacteristic(ledsAboveCharacteristic) 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 @@ ...@@ -8,11 +8,15 @@
android:padding="16dp" android:padding="16dp"
> >
<TextView android:layout_width="wrap_content" <TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Mood"/> android:layout_height="wrap_content" android:text="@string/personal_state"/>
<Button android:id="@+id/mood_good" android:layout_width="wrap_content" android:layout_height="wrap_content" <Button android:id="@+id/mood_chaos" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Good"/> android:text="@string/chaos"/>
<Button android:id="@+id/mood_neutral" android:layout_width="wrap_content" android:layout_height="wrap_content" <Button android:id="@+id/mood_communication" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Neutral"/> android:text="@string/communication"/>
<Button android:id="@+id/mood_bad" android:layout_width="wrap_content" android:layout_height="wrap_content" <Button android:id="@+id/mood_congress" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Bad"/> 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> </LinearLayout>
...@@ -44,4 +44,10 @@ ...@@ -44,4 +44,10 @@
<string name="connection_error_generic">Connection error</string> <string name="connection_error_generic">Connection error</string>
<string name="connection_error_no_bonded_device">No bonded card10s available</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> </resources>
Supports Markdown
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