Skip to content

Commit

Permalink
Reset McuSettings on PowerOff
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaggly committed Oct 11, 2021
1 parent 16b2995 commit 2e5aca3
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "0.8S"
versionName "0.8.1S"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlin.math.roundToInt
object McuLogic {
//Lib
var mcuCommunicator : McuCommunicator? = null
var realSysMode : Int = 1
val mcuStat = McuStatus()

//Intern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.snaggly.ksw_toolkit.core.service.mcu.action.EventAction
import com.snaggly.ksw_toolkit.core.service.mcu.action.EventActionLogger
import com.snaggly.ksw_toolkit.core.service.mcu.parser.*
import com.snaggly.ksw_toolkit.core.service.sys_observers.BrightnessObserver
import com.snaggly.ksw_toolkit.util.list.eventtype.EventManagerTypes
import com.wits.pms.statuscontrol.PowerManagerApp
import projekt.auto.mcu.ksw.serial.reader.LogcatReader
import projekt.auto.mcu.ksw.serial.McuCommunicator
Expand Down Expand Up @@ -124,6 +125,48 @@ class McuReaderHandler(private val context: Context) {

//Get current CarData
McuLogic.mcuCommunicator!!.sendCommand(104, byteArrayOf(5, 0), false)

//Reset Data on PowerOff/PowerOn
parseMcuEvent.powerEvent = object : IPowerEvent {
override fun getPowerEvent(data: ByteArray): EventManagerTypes {
if (data.size <= 1)
return EventManagerTypes.Dummy

//PowerOff
if (data[0].toInt() == 5) {
//Restore NightBrightness
if (config.systemOptions.nightBrightness!!
&& PowerManagerApp.getSettingsInt("Backlight_auto_set") != 0) {
McuLogic.mcuCommunicator?.sendCommand(McuCommands.Set_Backlight_Control_Off)
}

//Restore MediaButton
if (config.systemOptions.extraMediaButtonHandle!!
&& PowerManagerApp.getSettingsInt("CarDisplay") != 0) {
val dataBytes = byteArrayOf(0x0e, 0x01)
McuLogic.mcuCommunicator?.sendCommand(0x70, dataBytes, false)
if (McuLogic.realSysMode == 1)
McuLogic.mcuCommunicator?.sendCommand(McuCommands.SWITCH_TO_ANDROID)
}
}
//PowerOn
else if (data[0].toInt() == 4) {
//Reset NightBrightness
if (config.systemOptions.nightBrightness!!
&& PowerManagerApp.getSettingsInt("Backlight_auto_set") != 0) {
McuLogic.mcuCommunicator?.sendCommand(McuCommands.Set_Backlight_Control_On)
}

//Reset MediaButton
if (config.systemOptions.extraMediaButtonHandle!!
&& PowerManagerApp.getSettingsInt("CarDisplay") != 0) {
val dataBytes = byteArrayOf(0x0e, 0x00)
McuLogic.mcuCommunicator?.sendCommand(0x70, dataBytes, false)
}
}
return EventManagerTypes.Dummy
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ abstract class IMcuEvent(context: Context) {
var benzDataEvent: IBenzDataEvent = BenzDataEventLogger
var carDataEvent: ICarDataEvent = CarDataEventLogger
var screenSwitchEvent: IScreenSwitchEvent = ScreenSwitchEvent
var powerEvent: IPowerEvent = PowerEvent
val buttonClickEvent = ButtonClickEvent
val idleEvent = IdleEvent(context)
abstract fun getMcuEvent(cmdType: Int, data: ByteArray): EventManagerTypes?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.snaggly.ksw_toolkit.core.service.mcu.parser

import com.snaggly.ksw_toolkit.util.list.eventtype.EventManagerTypes

interface IPowerEvent {
fun getPowerEvent(data: ByteArray) : EventManagerTypes
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IdleEvent(val context: Context) {
}

fun getIdleEvent(data: ByteArray) : EventManagerTypes {
McuLogic.realSysMode = data[0].toInt()
if (data[0] == 0x1.toByte()) {
backTapper?.removeBackWindow()
if (wasInSys2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class McuEvent(context: Context) : IMcuEvent(context) {
}
0x1D -> return benzDataEvent.getBenzDataEvent(data)
0x1C -> return idleEvent.getIdleEvent(data)
0x11 -> return powerEvent.getPowerEvent(data)
else -> return null
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.snaggly.ksw_toolkit.core.service.mcu.parser

import com.snaggly.ksw_toolkit.util.list.eventtype.EventManagerTypes

object PowerEvent : IPowerEvent {
override fun getPowerEvent(data: ByteArray): EventManagerTypes {
return EventManagerTypes.Dummy
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ object ScreenSwitchMediaHack : IScreenSwitchEvent {
if (data[1] == 0x1.toByte()) {
switchLock = false
McuLogic.mcuCommunicator!!.sendCommand(0x70, disableOEM, false)
McuLogic.mcuCommunicator!!.sendCommand(McuCommands.SetMusicSource(SOUND_SRC_TYPE.SRC_ATSL_AIRCONSOLE))
if (thisHasSoundRestorer)
McuLogic.mcuCommunicator!!.sendCommand(McuCommands.SetMusicSource(SOUND_SRC_TYPE.SRC_ATSL_AIRCONSOLE))
} else if (data[1] == 0x2.toByte() && !switchLock) {
switchLock = true
McuLogic.mcuCommunicator!!.sendCommand(0x70, enableOEM, false)
Expand Down

0 comments on commit 2e5aca3

Please sign in to comment.