Skip to content

Commit

Permalink
Fix issues with controller timing out when it shouldn't
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyeOfBreeze committed Mar 5, 2021
1 parent 6b24789 commit e269523
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
applicationId "org.btelman.controller.rvr"
minSdkVersion 18
targetSdkVersion 29
versionCode 8
versionName "1.3.2"
versionCode 9
versionName "1.3.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class MainActivity : AppCompatActivity() {
viewModelRVR?.let { viewModel->
if(viewModel.connected.value == true){
val lastInputCommand = System.currentTimeMillis() - inputHandler.lastUpdated
if(lastInputCommand > prefsManager.timeoutMs){
if(!inputHandler.isInputGamepad && lastInputCommand > prefsManager.timeoutMs){
if(timedOut && lastInputCommand > prefsManager.timeoutMs + 1000) return //allow it to send the stop command for a second
timedOut = true
left = 0f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class InputHandler(
) : RemoReceiver.RemoListener, JoystickSurfaceView.JoystickUpdateListener,
GamepadHandler.GamepadListener {
private var lastGamepadId: Int? = null
val isInputGamepad : Boolean
get() {
return lastGamepadId != null
}
var right = 0.0f
var left = 0.0f
var lastUpdated = System.currentTimeMillis()
Expand Down Expand Up @@ -71,7 +75,7 @@ class InputHandler(
historyPos: Int
) {

val mInputDevice = event.device
val mInputDevice = event.device ?: return

// Calculate the vertical distance to move by
// using the input value from one of these physical controls:
Expand All @@ -93,6 +97,7 @@ class InputHandler(
}

override fun onCommand(command: String) {
lastGamepadId = null
Log.d("InputHandler",command)
val linearSpeed : Float
val rotateSpeed : Float
Expand Down Expand Up @@ -126,6 +131,7 @@ class InputHandler(
}

override fun OnJoystickUpdate(id: Int, joystickAxes: FloatArray?) {
lastGamepadId = null
if(joystickAxes == null) return
val y = joystickAxes[0]
val x = joystickAxes[1]
Expand All @@ -147,6 +153,8 @@ class InputHandler(
Toast.makeText(context, "Lost connection to gamepad", Toast.LENGTH_SHORT).show()
left = 0f
right = 0f
lastGamepadId = null
lastUpdated = System.currentTimeMillis()
sendInputUpdatedEvent()
}
}
Expand Down

0 comments on commit e269523

Please sign in to comment.