feat: home
This commit is contained in:
@@ -67,6 +67,19 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
|
||||
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 音量
|
||||
*/
|
||||
private val _volume: MutableStateFlow<Int> = MutableStateFlow(0)
|
||||
val volume = _volume.asStateFlow()
|
||||
|
||||
|
||||
/**
|
||||
* 亮度
|
||||
*/
|
||||
private val _brightness: MutableStateFlow<Int> = MutableStateFlow(0)
|
||||
val brightness = _brightness.asStateFlow()
|
||||
|
||||
lateinit var sn: String
|
||||
private set
|
||||
|
||||
@@ -124,27 +137,19 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
|
||||
}
|
||||
|
||||
IInstructService.INSTRUCT_VOLUME_UP -> {
|
||||
systemFuncServiceTodo { service ->
|
||||
setVolumeSpecified(service.volumeSpecified + 1)
|
||||
}
|
||||
volumeAdd()
|
||||
}
|
||||
|
||||
IInstructService.INSTRUCT_VOLUME_DOWN -> {
|
||||
systemFuncServiceTodo { service ->
|
||||
setVolumeSpecified(service.volumeSpecified - 1)
|
||||
}
|
||||
volumeSubtract()
|
||||
}
|
||||
|
||||
IInstructService.INSTRUCT_LIGHT_UP -> {
|
||||
systemFuncServiceTodo { service ->
|
||||
setBrightnessSpecified(service.brightnessSpecified + 1)
|
||||
}
|
||||
brightnessAdd()
|
||||
}
|
||||
|
||||
IInstructService.INSTRUCT_LIGHT_DOWN -> {
|
||||
systemFuncServiceTodo { service ->
|
||||
setBrightnessSpecified(service.brightnessSpecified - 1)
|
||||
}
|
||||
brightnessSubtract()
|
||||
}
|
||||
|
||||
IInstructService.INSTRUCT_TAKE_PHOTO -> {
|
||||
@@ -185,12 +190,48 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
|
||||
}
|
||||
}
|
||||
|
||||
fun quitInstructReceived() {
|
||||
_instructState.update { InstructState.None }
|
||||
}
|
||||
|
||||
fun playTTS(msg: String) {
|
||||
ttsServiceTodo {
|
||||
ttsService?.playTtsMsg(msg)
|
||||
}
|
||||
}
|
||||
|
||||
fun volumeAdd() {
|
||||
systemFuncServiceTodo { service ->
|
||||
val volume = (service.volumeSpecified + 1).coerceIn(0, 15)
|
||||
service.volumeSpecified = volume
|
||||
_volume.update { volume }
|
||||
}
|
||||
}
|
||||
|
||||
fun volumeSubtract() {
|
||||
systemFuncServiceTodo { service ->
|
||||
val volume = (service.volumeSpecified - 1).coerceIn(0, 15)
|
||||
service.volumeSpecified = volume
|
||||
_volume.update { volume }
|
||||
}
|
||||
}
|
||||
|
||||
fun brightnessAdd() {
|
||||
systemFuncServiceTodo { service ->
|
||||
val brightness = (service.brightnessSpecified + 1).coerceIn(0, 15)
|
||||
service.brightnessSpecified = brightness
|
||||
_brightness.update { brightness }
|
||||
}
|
||||
}
|
||||
|
||||
fun brightnessSubtract() {
|
||||
systemFuncServiceTodo { service ->
|
||||
val brightness = (service.brightnessSpecified - 1).coerceIn(0, 15)
|
||||
service.brightnessSpecified = brightness
|
||||
_brightness.update { brightness }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getSn() = suspendCancellableCoroutine { continuation ->
|
||||
ServiceManager.getSystemFuncService(context) { service ->
|
||||
if (service == null) {
|
||||
@@ -199,6 +240,8 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
|
||||
}
|
||||
systemFuncService = service
|
||||
sn = service.sn
|
||||
_volume.update { service.volumeSpecified }
|
||||
_brightness.update { service.brightnessSpecified }
|
||||
continuation.resume(sn)
|
||||
}
|
||||
}
|
||||
@@ -248,14 +291,6 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
|
||||
}
|
||||
}
|
||||
|
||||
private fun setVolumeSpecified(volume: Int) {
|
||||
systemFuncService?.volumeSpecified = volume.coerceIn(0, 15)
|
||||
}
|
||||
|
||||
private fun setBrightnessSpecified(brightness: Int) {
|
||||
systemFuncService?.brightnessSpecified = brightness.coerceIn(0, 15)
|
||||
}
|
||||
|
||||
inner class SysKeyReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
val action = intent?.action ?: return
|
||||
|
||||
Reference in New Issue
Block a user