Skip to content

Commit

Permalink
Release-v2.9.3 package
Browse files Browse the repository at this point in the history
  • Loading branch information
SaravanKumarMS committed Oct 14, 2024
1 parent 526e9b4 commit ac0f639
Show file tree
Hide file tree
Showing 13 changed files with 680 additions and 275 deletions.
3 changes: 3 additions & 0 deletions build/Si-Connect - v2_9_3.apk
Git LFS file not shown
3 changes: 0 additions & 3 deletions build/Si-Connect-v2_9_2.apk

This file was deleted.

6 changes: 3 additions & 3 deletions mobile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ android {
create("Si-Connect") {
dimension = versionDim
applicationId = "com.siliconlabs.bledemo"
versionCode = 54
versionName = "2.9.2"
versionCode = 55
versionName = "2.9.3"
}
}

Expand Down Expand Up @@ -167,5 +167,5 @@ dependencies {
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0")

implementation ("com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
package com.siliconlabs.bledemo.features.demo.devkitsensor917.activities

import android.annotation.SuppressLint
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.MenuItem
import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.siliconlabs.bledemo.R
import com.siliconlabs.bledemo.databinding.Activity917DevKitSensorLayoutBinding
import com.siliconlabs.bledemo.features.demo.devkitsensor917.APIInterface
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.ScanResponse
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.SensorsResponse
import com.siliconlabs.bledemo.features.demo.devkitsensor917.utils.DevKitSensorChecker
import com.siliconlabs.bledemo.features.demo.devkitsensor917.utils.DevKitSensorControl
import com.siliconlabs.bledemo.features.demo.matter_demo.utils.CustomProgressDialog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class DevKitSensor917Activity : AppCompatActivity() {

Expand All @@ -19,7 +35,9 @@ class DevKitSensor917Activity : AppCompatActivity() {
private val devKitSensorChecker = DevKitSensorChecker()
private val controls =
mutableMapOf<DevKitSensorChecker.DevkitSensor917BoardSensor, DevKitSensorControl>()

private lateinit var devkitSensorCntl: DevKitSensorControl
private lateinit var listener: ResponseListener
private var customProgressDialog: CustomProgressDialog? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -30,42 +48,86 @@ class DevKitSensor917Activity : AppCompatActivity() {
val actionBar = supportActionBar
actionBar!!.setHomeAsUpIndicator(R.drawable.matter_back)
actionBar.setDisplayHomeAsUpEnabled(true)
initGrid()
val ipAddress = intent.getStringExtra(IP_ADDRESS)
if (ipAddress != null) {
showProgressDialog(this.getString(R.string.dev_kit_progress_bar_message))
println("IP ADDRESS Imported: $ipAddress")
initGrid(ipAddress)
GlobalScope.launch {
doInSensorBackground(ipAddress)
}
}
}
//
// override fun onBackPressed() {
// if (getFragmentManager().getBackStackEntryCount() > 0)
// getFragmentManager().popBackStack();
// else
// super.onBackPressed();
// }


@SuppressLint("SetTextI18n")
private suspend fun doInSensorBackground(ipAddress: String) {
withContext(Dispatchers.IO) {
delay(3000L)
try {
val url = "http://$ipAddress"
val retro = Retrofit.Builder().baseUrl(url)
.addConverterFactory(GsonConverterFactory.create()).build()
val response = retro.create(APIInterface::class.java).getAllSensor()

println("Response: $response")
if (response.isSuccessful) {
val data = response.body()
println("data: $data")
withContext(Dispatchers.Main) {
if (data != null) {
listener.fetchData(data)
removeProgress()
}
}
} else {
removeProgress()
runOnUiThread {
Toast.makeText(
baseContext,
"API All Sensors Response failed",
Toast.LENGTH_SHORT
).show()
}

Timber.tag(TAG).e("API All Sensors Response failed:${response.message()}")
}
} catch (e: Exception) {
removeProgress()
Timber.tag(TAG).e("API All Sensors Exception occurred ${e.message}")
}
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
this.finish()
true
}

else -> super.onOptionsItemSelected(item)
}
}

private fun initGrid() {
private fun initGrid(ipAddress: String) {
binding.envGrid.apply {
devKitSensorChecker.devKitSensors.filter {
it.value == DevKitSensorChecker.DevkitSensorState.WORKING
}.forEach {
controls[it.key] = DevKitSensorControl(
devkitSensorCntl = DevKitSensorControl(
this.context,
getString(getTileDescription(it.key)),
ContextCompat.getDrawable(this.context, getTileIcon(it.key))
).also {

addView(it)
it.setListener(it.tag)
it.setListener(it.tag, ipAddress)


}
listener = devkitSensorCntl
controls[it.key] = devkitSensorCntl
}
}
}
Expand Down Expand Up @@ -99,6 +161,31 @@ class DevKitSensor917Activity : AppCompatActivity() {
}
}

private fun removeProgress() {
runOnUiThread {
if (customProgressDialog?.isShowing() == true) {
customProgressDialog?.dismiss()
}
}
}

private fun showProgressDialog(message: String) {
runOnUiThread {
customProgressDialog = CustomProgressDialog(this)
customProgressDialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
customProgressDialog!!.setMessage(message)
customProgressDialog!!.show()
}

}

interface ResponseListener {
fun fetchData(response: SensorsResponse?)
}

companion object {
const val IP_ADDRESS = "ip_address"
val TAG = ""
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.LEDStatusResp
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.MicrophoneResponse
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.ProvisionResponse
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.ScanResponse
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.SensorsResponse
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.StatusResponse
import com.siliconlabs.bledemo.features.demo.devkitsensor917.model.TempResponse
import retrofit2.Response
Expand Down Expand Up @@ -66,5 +67,7 @@ interface APIInterface {
@POST("/status_led")
fun setLEDStatusOff(@Body body: Map<String, String>): Call<LEDStatusResponse>

@GET("/all_sensors")
suspend fun getAllSensor():Response<SensorsResponse>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.siliconlabs.bledemo.features.demo.devkitsensor917.model

data class SensorsResponse(
val led: LEDResponse,
val light: AmbientLightResponse,
val temperature: TempResponse,
val accelerometer: AccelerometerGyroScopeResponse,
val gyroscope: AccelerometerGyroScopeResponse,
val humidity: HumidityResponse,
val microphone: MicrophoneResponse
)
Loading

0 comments on commit ac0f639

Please sign in to comment.