Skip to content

Commit

Permalink
Find headset automatically
Browse files Browse the repository at this point in the history
Find headset algorithmically instead of using hardcoded value
Print more details in main activity
  • Loading branch information
rustammendel committed Aug 20, 2024
1 parent ea5fe34 commit e4a60ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/rlabs/dakc/DakcTileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ class DakcTileService : TileService() {
// Called when the user taps on your tile in an active or inactive state.
override fun onClick() {
super.onClick()
Log.d("QS", "Tile tapped")
runAsRoot(arrayOf("tinymix -D 2 3 120"))
Log.d("Dakc", "Tile tapped")
var n = 0
var mixerName = ""
while (!mixerName.contains("USB-C to 3.5mm") && n < 10) {
mixerName = runAsRoot(arrayOf("tinymix -D $n | head")).first.toString().split("\n")[0]
n++
}
runAsRoot(arrayOf("tinymix -D ${n - 1} 3 120"))
}

}
Expand Down
36 changes: 19 additions & 17 deletions app/src/main/java/com/rlabs/dakc/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,45 @@ class MainActivity : ComponentActivity() {
lateinit var dev1: TextView
lateinit var dev2: TextView
lateinit var dev3: TextView
lateinit var button1: Button
lateinit var refreshButton: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
dev1 = findViewById(R.id.dev1)
dev1.text = TinymixOut(device = "1")

dev1 = findViewById(R.id.dev1)
dev2 = findViewById(R.id.dev2)
dev2.text = TinymixOut(device = "2")

dev3 = findViewById(R.id.dev3)
dev3.text = TinymixOut(device = "2", 7)


button1 = findViewById(R.id.button1)
button1.setOnClickListener {
dev1.text = TinymixOut(device = "1")
dev2.text = TinymixOut(device = "2")
dev3.text = TinymixOut(device = "2", 7)
fun readFields() {
dev1.text = tinymixOut(device = "0")
dev2.text = tinymixOut(device = "1")
dev3.text = tinymixOut(device = "2")
}
readFields()

}
refreshButton = findViewById(R.id.button1)
refreshButton.setOnClickListener { readFields() }

}

}

fun TinymixOut(device: String, lineNum: Int = 0): String {
val outPair = runAsRoot(arrayOf("tinymix -D $device"))
fun tinymixOut(device: String, lineNum: Int = 0): String {
val outPair = runAsRoot(arrayOf("tinymix -D $device | head -20"))

val out = outPair.first.toString()
val errout = outPair.second.toString()

val firstLine = if (errout.isNotEmpty()) errout.split("\n")[0] else out.split("\n")[lineNum]
val outArr = out.split("\n")

val firstLine = if (errout.isNotEmpty()) errout.split("\n")[0] else outArr[lineNum]
val iVolLine = outArr.indexOfFirst { s -> s.contains("Headset Playback Volume") }

val volInfo = if (errout.isEmpty() && iVolLine != -1) outArr[iVolLine] else ""

Log.d("tinymix", out)

return "tinymix -D $device out: \n$firstLine"
return "tinymix -D $device out: \n$firstLine \n$volInfo"

}

0 comments on commit e4a60ac

Please sign in to comment.