suyu/src/android/app/src/main/java/org/suyu/suyu_emu/features/input/SuyuInputDevice.kt

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.2 KiB
Kotlin
Raw Normal View History

// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
2024-03-12 03:30:43 +01:00
// SPDX-FileCopyrightText: 2024 suyu Emulator Project
2024-03-05 09:42:40 +01:00
// SPDX-License-Identifier: GPL-2.0-or-later
2024-03-12 03:30:43 +01:00
package org.suyu.suyu_emu.features.input
2024-03-05 09:42:40 +01:00
import android.view.InputDevice
import androidx.annotation.Keep
2024-03-12 03:30:43 +01:00
import org.suyu.suyu_emu.SuyuApplication
import org.suyu.suyu_emu.R
import org.suyu.suyu_emu.utils.InputHandler.getGUID
2024-03-05 09:42:40 +01:00
@Keep
2024-03-12 03:30:43 +01:00
interface SuyuInputDevice {
2024-03-05 09:42:40 +01:00
fun getName(): String
fun getGUID(): String
fun getPort(): Int
fun getSupportsVibration(): Boolean
fun vibrate(intensity: Float)
fun getAxes(): Array<Int> = arrayOf()
fun hasKeys(keys: IntArray): BooleanArray = BooleanArray(0)
}
2024-03-12 03:30:43 +01:00
class SuyuPhysicalDevice(
2024-03-05 09:42:40 +01:00
private val device: InputDevice,
private val port: Int,
useSystemVibrator: Boolean
2024-03-12 03:30:43 +01:00
) : SuyuInputDevice {
2024-03-05 09:42:40 +01:00
private val vibrator = if (useSystemVibrator) {
2024-03-12 03:30:43 +01:00
SuyuVibrator.getSystemVibrator()
2024-03-05 09:42:40 +01:00
} else {
2024-03-12 03:30:43 +01:00
SuyuVibrator.getControllerVibrator(device)
2024-03-05 09:42:40 +01:00
}
override fun getName(): String {
return device.name
}
override fun getGUID(): String {
return device.getGUID()
}
override fun getPort(): Int {
return port
}
override fun getSupportsVibration(): Boolean {
return vibrator.supportsVibration()
}
override fun vibrate(intensity: Float) {
vibrator.vibrate(intensity)
}
override fun getAxes(): Array<Int> = device.motionRanges.map { it.axis }.toTypedArray()
override fun hasKeys(keys: IntArray): BooleanArray = device.hasKeys(*keys)
}
2024-03-12 03:30:43 +01:00
class SuyuInputOverlayDevice(
2024-03-05 09:42:40 +01:00
private val vibration: Boolean,
private val port: Int
2024-03-12 03:30:43 +01:00
) : SuyuInputDevice {
private val vibrator = SuyuVibrator.getSystemVibrator()
2024-03-05 09:42:40 +01:00
override fun getName(): String {
2024-03-12 03:30:43 +01:00
return SuyuApplication.appContext.getString(R.string.input_overlay)
2024-03-05 09:42:40 +01:00
}
override fun getGUID(): String {
return "00000000000000000000000000000000"
}
override fun getPort(): Int {
return port
}
override fun getSupportsVibration(): Boolean {
if (vibration) {
return vibrator.supportsVibration()
}
return false
}
override fun vibrate(intensity: Float) {
if (vibration) {
vibrator.vibrate(intensity)
}
}
}