GlyphAdapter: sending data to ParanoidGlyph thirdparty service

Now we can control glyph leds from other applications using Glyph SDK. Tested on glyphify and glyph composer

Change-Id: I1b4a5d28b524eb24abda02696b77253707f9edd5
This commit is contained in:
BrainKub
2025-02-24 03:00:13 +03:00
committed by Brain Kub
parent c59c1d5a2c
commit c8c7b1cdb3
2 changed files with 38 additions and 2 deletions

View File

@@ -9,6 +9,6 @@ import android.app.Service
import android.content.Intent
public class GlyphService : Service() {
private val binder = IGlyphServiceImpl()
private val binder by lazy { IGlyphServiceImpl(this) }
override fun onBind(intent: Intent?) = binder
}

View File

@@ -5,20 +5,56 @@
package com.nothing.thirdparty
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import android.util.Log
class IGlyphServiceImpl : IGlyphService.Stub() {
class IGlyphServiceImpl(private val context: Context) : IGlyphService.Stub() {
private var glyphService: IGlyphService? = null
private val connection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
glyphService = IGlyphService.Stub.asInterface(service)
}
override fun onServiceDisconnected(name: ComponentName?) {
glyphService = null
}
}
init {
bindglyphService()
}
private fun bindglyphService() {
if (context != null) {
val intent = Intent("com.nothing.thirdparty.IGlyphService").apply {
component = ComponentName("co.aospa.glyph", "co.aospa.glyph.Services.ThirdPartyService")
}
context.bindService(intent, connection, Context.BIND_AUTO_CREATE)
} else {
Log.e("IGlyphServiceImpl", "Context is null, cannot bind service")
}
}
override fun setFrameColors(iArray: IntArray?) {
Log.i("IGlyphServiceImpl", "updateLedFrame - ${iArray.contentToString()}")
if (iArray != null) {
glyphService?.setFrameColors(iArray)
}
}
override fun openSession() {
Log.i("IGlyphServiceImpl", "openSession")
glyphService?.setFrameColors(intArrayOf(0, 0, 0, 0, 0))
}
override fun closeSession() {
Log.i("IGlyphServiceImpl", "closeSession")
glyphService?.setFrameColors(intArrayOf(0, 0, 0, 0, 0))
}