Skip to content

Commit

Permalink
Release-v2.7.2 package
Browse files Browse the repository at this point in the history
  • Loading branch information
SaravanKumarMS committed Oct 13, 2023
1 parent 501d1a7 commit fdd06af
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 63 deletions.
Binary file added build/EFRConnect - v2.7.2.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions mobile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ android {
create("blueGecko") {
dimension = versionDim
applicationId = "com.siliconlabs.bledemo"
versionCode = 43
versionName = "2.7.1"
versionCode = 44
versionName = "2.7.2"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<Bit index="4" size="1" name="RR-Interval bit">
<Enumerations>
<Enumeration key="0" value="RR-Interval values are not present." />
<Enumeration key="1" value="One or more RR-Interval values are present." requires="C4"/>
<Enumeration key="1" value="One or more RR-Interval values are present. Units: 1/1024 seconds" requires="C4"/>
</Enumerations>
</Bit>
<ReservedForFutureUse index="5" size="3"></ReservedForFutureUse>
Expand Down Expand Up @@ -68,29 +68,27 @@
</Field>
<Field name="RR-Interval">
<InformativeText>
<!-- The presence of the RR-Interval field is dependent upon bit 4 of the Flags field.
<p>The RR-Interval value represents the time between two R-Wave detections.</p>
The presence of the RR-Interval field is dependent upon bit 4 of the Flags field.
The RR-Interval value represents the time between two R-Wave detections.

<p>Because several RR-Intervals may be measured between transmissions of the HEART RATE MEASUREMENT characteristic,
Because several RR-Intervals may be measured between transmissions of the HEART RATE MEASUREMENT characteristic,
multiple RR-Interval sub-fields may be present in the characteristic. The number of RR-Interval sub-fields present
is determined by a combination of the overall length of the characteristic and whether or not the characteristic contains
the Energy Expended field.</p>
the Energy Expended field.

<p>Where there are multiple RR-Interval values transmitted in the HEART RATE MEASUREMENT characteristic, the field uses the following format:</p>
<p>RR-Interval Value 0 (LSO...MSO), RR-Interval Value 1 (LSO...MSO), RR-Interval Value 2 (LSO...MSO), RR-Interval Value n (LSO...MSO).</p>
<p>Where the RR-Interval Value 0 is older than the RR-Interval Value 1.</p>
<p>RR-Interval Value 0 is transmitted first followed by the newer measurements.</p>-->
Where there are multiple RR-Interval values transmitted in the HEART RATE MEASUREMENT characteristic, the field uses the following format:
RR-Interval Value 0 (LSO...MSO), RR-Interval Value 1 (LSO...MSO), RR-Interval Value 2 (LSO...MSO), RR-Interval Value n (LSO...MSO).
Where the RR-Interval Value 0 is older than the RR-Interval Value 1.
RR-Interval Value 0 is transmitted first followed by the newer measurements.

</InformativeText>
<Requirement>C4</Requirement>
<Format>uint16</Format>
<Unit>org.bluetooth.unit.time.second</Unit>
<Description>Resolution of 1/1024 second</Description>



</Field>
</Value>
<Note> <p>The fields in the above table are in the order of LSO to MSO. Where LSO = Least Significant Octet and MSO = Most Significant Octet.</p>
<Note>
The fields in the above table are in the order of LSO to MSO. Where LSO = Least Significant Octet and MSO = Most Significant Octet.
</Note>
</Characteristic>
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,115 @@ import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import com.siliconlabs.bledemo.bluetooth.data_types.Field
import com.siliconlabs.bledemo.R
import com.siliconlabs.bledemo.bluetooth.data_types.Field
import com.siliconlabs.bledemo.databinding.CharacteristicFieldBitfieldWriteModeBinding
import com.siliconlabs.bledemo.databinding.CharacteristicFieldReadModeBinding

class BitFieldView(context: Context?,
field: Field,
fieldValue: ByteArray
class BitFieldView(
context: Context?,
field: Field,
fieldValue: ByteArray
) : FieldView(context, field, fieldValue) {
private val BUTTON_0 = 1
private val BUTTON_1 = 2
private val BUTTON_1_PRESSED = 2
private val BUTTON_2_PRESSED = 4
private val BUTTON_0_AND_1_PRESSED = 6
private val FIELDLENG = 4

private val STATUS_ON = "ON"
private val STATUS_OFF = "OFF"
private val FLAGS = "Flags - "

private val bitfieldBuilder = fillStringBuilderWithZeros(field.getSizeInBytes() * 8)
private var inputInfo: Int = 0

override fun createViewForRead(isParsedSuccessfully: Boolean, viewHandler: ViewHandler) {
val fieldBits = getFieldValueAsLsoMsoBitsString()
inputInfo = getFirst4BitsAsInt(fieldBits)

for (bit in field.bitfield?.bits!!) {
val enumerations = ArrayList<String>()
for (enumeration in bit.enumerations!!) {
enumerations.add(enumeration.value!!)
val bitInfo = field.bitfield?.bits!!

if (inputInfo == BUTTON_1_PRESSED || inputInfo == BUTTON_0_AND_1_PRESSED) {

if (fieldBits.length >= FIELDLENG) {

var nibble = toggleFirstFourBits(fieldBits).toString()

nibble = getReverseBit(nibble)

val enumerations = ArrayList<String>()
val bits = field.bitfield?.bits!!
for (bit in bitInfo.indices) {
var data: String = ""
if (nibble[bit] == '0') {
data =
bitInfo[bit]?.enumerations!![nibble[bit].digitToInt()].value.toString()
} else if (nibble[bit] == '1') {
data =
bitInfo[bit]?.enumerations!![nibble[bit].digitToInt()].value.toString()
}
enumerations.add(data)

CharacteristicFieldReadModeBinding.inflate(LayoutInflater.from(context))
.apply {
characteristicFieldName.text = FLAGS + bits[bit].name
if (isParsedSuccessfully) {
characteristicFieldValue.text = enumerations[bit]
if (bit == 1) {
characteristicFieldStatus.text = STATUS_ON
} else {
characteristicFieldStatus.text = STATUS_OFF
}
}

characteristicFieldStatus.visibility = View.VISIBLE
viewHandler.handleFieldView(root, characteristicFieldValue)
}
}
}

val chosenOption = getValueInStringBitsRange(
} else {

for (bit in field.bitfield?.bits!!) {
val enumerations = ArrayList<String>()
for (enumeration in bit.enumerations!!) {
enumerations.add(enumeration.value!!)
}

val chosenOption = getValueInStringBitsRange(
bit.index,
bit.index + bit.size,
fieldBits
)
)
val inputInfo = getFirst4BitsAsInt(fieldBits)
CharacteristicFieldReadModeBinding.inflate(LayoutInflater.from(context)).apply {
characteristicFieldName.text = FLAGS + bit.name
if (isParsedSuccessfully) {
when (chosenOption) {
BUTTON_0 -> {
characteristicFieldValue.text = enumerations[inputInfo]
characteristicFieldStatus.text = STATUS_OFF
characteristicFieldStatus.visibility = View.VISIBLE
}

CharacteristicFieldReadModeBinding.inflate(LayoutInflater.from(context)).apply {
characteristicFieldName.text = bit.name
if (isParsedSuccessfully) {
characteristicFieldValue.text = enumerations[chosenOption]
}
else -> {
characteristicFieldValue.text = enumerations[chosenOption]
characteristicFieldStatus.text = STATUS_OFF
characteristicFieldStatus.visibility = View.VISIBLE
}
}

}

viewHandler.handleFieldView(root, characteristicFieldValue)
viewHandler.handleFieldView(root, characteristicFieldValue)
}
}
}
}


override fun createViewForWrite(fieldOffset: Int, valueListener: ValueListener) {
val fieldValueInBits = getFieldValueAsLsoMsoBitsString()

Expand All @@ -52,50 +123,54 @@ class BitFieldView(context: Context?,
enumerations.add(enumeration.value!!)
}

CharacteristicFieldBitfieldWriteModeBinding.inflate(LayoutInflater.from(context)).apply {
val currentOption = getValueInStringBitsRange(
CharacteristicFieldBitfieldWriteModeBinding.inflate(LayoutInflater.from(context))
.apply {
val currentOption = getValueInStringBitsRange(
bit.index,
bit.index + bit.size,
fieldValueInBits
)
)

characteristicFieldName.text = bit.name
characteristicFieldValueSpinner.apply {
adapter = ArrayAdapter(
characteristicFieldName.text = bit.name
characteristicFieldValueSpinner.apply {
adapter = ArrayAdapter(
context,
R.layout.enumeration_spinner_dropdown_item,
enumerations
)
setSelection(currentOption)
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
)
setSelection(currentOption)
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
position: Int,
id: Long
) {
// After each spinner selection bits are prepared for characteristic write - value array is updated with selected value
setStringBuilderBitsInRange(
) {
// After each spinner selection bits are prepared for characteristic write - value array is updated with selected value
setStringBuilderBitsInRange(
bitfieldBuilder,
bit.index,
bit.index + bit.size,
position
)
val newValue = bitsStringToByteArray(bitfieldBuilder.toString(),
field.getSizeInBytes())
valueListener.onValueChanged(field, newValue, fieldOffset)

if (bit.enumerations!![currentOption].requires !=
bit.enumerations!![position].requires) {
valueListener.onFieldsChanged()
)
val newValue = bitsStringToByteArray(
bitfieldBuilder.toString(),
field.getSizeInBytes()
)
valueListener.onValueChanged(field, newValue, fieldOffset)

if (bit.enumerations!![currentOption].requires !=
bit.enumerations!![position].requires
) {
valueListener.onFieldsChanged()
}
}
}

override fun onNothingSelected(parent: AdapterView<*>?) {}
override fun onNothingSelected(parent: AdapterView<*>?) {}
}
}
valueListener.handleFieldView(root)
}
valueListener.handleFieldView(root)
}
}
}

Expand Down Expand Up @@ -142,7 +217,12 @@ class BitFieldView(context: Context?,
}
}

private fun setStringBuilderBitsInRange(builder: StringBuilder, startBit: Int, endBit: Int, value: Int) {
private fun setStringBuilderBitsInRange(
builder: StringBuilder,
startBit: Int,
endBit: Int,
value: Int
) {
var tmpEndBit = endBit
var tmpValue = value
while (startBit < tmpEndBit) {
Expand Down Expand Up @@ -174,6 +254,36 @@ class BitFieldView(context: Context?,
return arr
}

fun Int.toBinary(len: Int): String {
return String.format("%" + len + "s", this.toString(2)).replace(" ".toRegex(), "0")
}

private fun getReverseBit(x: String): String {
return x.reversed()
}

private fun getFirst4BitsAsInt(binaryString: String): Int {
val trimmedBinaryString = binaryString.trim()
val substring = trimmedBinaryString.take(4)
return Integer.parseInt(substring, 2)
}

private fun toggleFirstFourBits(bitInput: String): String {
var res: String = ""
val toggledBits = StringBuilder(bitInput)
for (i in 0 until 4) {
if (bitInput[i] == '0') {
toggledBits.setCharAt(i, '1')
} else {
toggledBits.setCharAt(i, '0')
}
}
if (inputInfo == 6) {
toggledBits.setCharAt(1,'1')
}
if (toggledBits.length >= FIELDLENG) {
res = toggledBits.substring(0, FIELDLENG)
}
return res
}
}
38 changes: 32 additions & 6 deletions mobile/src/main/res/layout/characteristic_field_read_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,35 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_XS">

<TextView
android:id="@+id/characteristic_field_value"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/characteristic_list_item_value_text_size"
android:background="@color/silabs_white"
android:textColor="@color/silabs_primary_text"
tools:text="Field value and its unit" />
android:orientation="horizontal"
android:layout_marginBottom="5dp"
android:weightSum="4">

<TextView
android:id="@+id/characteristic_field_value"
android:layout_width="0dp"
android:layout_weight="3.5"
android:layout_height="wrap_content"
android:textSize="@dimen/characteristic_list_item_value_text_size"
android:background="@color/silabs_white"
android:textColor="@color/silabs_primary_text"
tools:text="Field value and its unit" />

<TextView
android:id="@+id/characteristic_field_status"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:visibility="gone"
android:layout_gravity="end"
android:gravity="end"
android:background="@color/silabs_white"
android:textColor="@color/silabs_subtle_text"
tools:text="OFF" />
</LinearLayout>

<TextView
android:id="@id/characteristic_field_name"
Expand All @@ -25,4 +46,9 @@
android:textColor="@color/silabs_subtle_text"
tools:text="Field name" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />

</LinearLayout>

0 comments on commit fdd06af

Please sign in to comment.