make strobo and SOS toggling more reliable

This commit is contained in:
tibbi 2022-07-14 14:06:49 +02:00
parent 704fa5221d
commit 98f9931cff

View File

@ -25,6 +25,8 @@ class MyCameraImpl(val context: Context) {
private var params: Camera.Parameters? = null private var params: Camera.Parameters? = null
private var isMarshmallow = false private var isMarshmallow = false
private var shouldEnableFlashlight = false private var shouldEnableFlashlight = false
private var shouldEnableStroboscope = false
private var shouldEnableSOS = false
private var isStroboSOS = false // are we sending SOS, or casual stroboscope? private var isStroboSOS = false // are we sending SOS, or casual stroboscope?
private var marshmallowCamera: MarshmallowCamera? = null private var marshmallowCamera: MarshmallowCamera? = null
@ -55,7 +57,7 @@ class MyCameraImpl(val context: Context) {
fun toggleStroboscope(): Boolean { fun toggleStroboscope(): Boolean {
if (isSOSRunning) { if (isSOSRunning) {
stopSOS() stopSOS()
toggleStroboscope() shouldEnableStroboscope = true
return true return true
} }
@ -85,7 +87,7 @@ class MyCameraImpl(val context: Context) {
fun toggleSOS(): Boolean { fun toggleSOS(): Boolean {
if (isStroboscopeRunning) { if (isStroboscopeRunning) {
stopStroboscope() stopStroboscope()
toggleSOS() shouldEnableSOS = true
return true return true
} }
@ -324,9 +326,19 @@ class MyCameraImpl(val context: Context) {
isStroboscopeRunning = false isStroboscopeRunning = false
} }
if (shouldEnableFlashlight) { when {
enableFlashlight() shouldEnableFlashlight -> {
shouldEnableFlashlight = false enableFlashlight()
shouldEnableFlashlight = false
}
shouldEnableSOS -> {
toggleSOS()
shouldEnableSOS = false
}
shouldEnableStroboscope -> {
toggleStroboscope()
shouldEnableStroboscope = false
}
} }
} }
} }