Skip to content

Commit

Permalink
Update sample.
Browse files Browse the repository at this point in the history
- Keyboard Joystick
- Get wakeup word.
  • Loading branch information
zjn0505 committed Dec 14, 2023
1 parent 006dfb9 commit 6a4d03a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
59 changes: 59 additions & 0 deletions sample/src/main/java/com/robotemi/sdk/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.speech.tts.UtteranceProgressListener
import android.text.method.ScrollingMovementMethod
import android.util.Log
import android.view.Gravity
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
Expand Down Expand Up @@ -325,6 +326,60 @@ class MainActivity : AppCompatActivity(), NlpListener, OnRobotReadyListener,
btnStopMovement.setOnClickListener { stopMovement() }
btnFollow.setOnClickListener { followMe() }
btnskidJoy.setOnClickListener { skidJoy() }
btnskidJoyDialog.setOnClickListener {
val alert = AlertDialog.Builder(it.context)
.setTitle("Skid Joy control by WSAD")
.setMessage("Control temi with keyboard WSAD, hold ctrl to move non-smartly, Z, X, C to break")
.setPositiveButton("OK", null)
.show()
alert.setOnKeyListener { _, keyCode, event ->
var x = 0f
var y = 0f

if (listOf(
KeyEvent.KEYCODE_S,
KeyEvent.KEYCODE_W,
KeyEvent.KEYCODE_A,
KeyEvent.KEYCODE_D,
KeyEvent.KEYCODE_X,
KeyEvent.KEYCODE_Z,
KeyEvent.KEYCODE_C,
).contains(keyCode)
) {
// Use W, A, S, D to move the robot smartly
// If Ctrl is hold, then do non smart move.
if (listOf(
KeyEvent.KEYCODE_X,
KeyEvent.KEYCODE_Z,
KeyEvent.KEYCODE_C
).contains(keyCode)
) {
x = 0f
y = 0f
robot.stopMovement()
return@setOnKeyListener false
}
if (event.action == KeyEvent.ACTION_DOWN) {
when (keyCode) {
KeyEvent.KEYCODE_S -> x = if (y != 0f) -0.4f else -0.6f
KeyEvent.KEYCODE_W -> x = if (y != 0f) 0.5f else 0.6f
KeyEvent.KEYCODE_A -> y = if (x < 0) -1f else 1f
KeyEvent.KEYCODE_D -> y = if (x < 0) 1f else -1f
}
robot.skidJoy(x, y, !event.isCtrlPressed)
} else if (event.action == KeyEvent.ACTION_UP) {
when (keyCode) {
KeyEvent.KEYCODE_S -> x = 0f
KeyEvent.KEYCODE_W -> x = 0f
KeyEvent.KEYCODE_A -> y = 0f
KeyEvent.KEYCODE_D -> y = 0f
}
}
}
false

}
}
btnTiltAngle.setOnClickListener { tiltAngle() }
btnTiltBy.setOnClickListener { tiltBy() }
btnTurnBy.setOnClickListener { turnBy() }
Expand All @@ -340,6 +395,10 @@ class MainActivity : AppCompatActivity(), NlpListener, OnRobotReadyListener,
btnHideTopBar.setOnClickListener { hideTopBar() }
btnShowTopBar.setOnClickListener { showTopBar() }
btnWakeup.setOnClickListener { wakeup() }
btnWakeup.setOnLongClickListener {
Toast.makeText(this@MainActivity, robot.wakeupWord, Toast.LENGTH_SHORT).show()
true
}
btnWakeupCustomLanguages.setOnClickListener { wakeupCustomLanguages() }
btnSetAsrLanguages.setOnClickListener { setAsrLanguages() }
btnDisableWakeup.setOnClickListener { disableWakeup() }
Expand Down
5 changes: 5 additions & 0 deletions sample/src/main/res/layout/group_map_and_movement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
style="@style/ButtonCommon"
android:text="@string/skidjoy" />

<Button
android:id="@+id/btnskidJoyDialog"
style="@style/ButtonCommon"
android:text="skidjoy key" />

<Button
android:id="@+id/btnTiltAngle"
style="@style/ButtonCommon"
Expand Down

0 comments on commit 6a4d03a

Please sign in to comment.