update
This commit is contained in:
parent
927b11e2bf
commit
d75a8bb2b2
@ -14,7 +14,7 @@
|
|||||||
android:name=".ControlActivity"
|
android:name=".ControlActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:theme="@style/Theme.HexapodFullScreen"
|
android:theme="@style/Theme.HexapodFullScreen"
|
||||||
android:screenOrientation="landscape"
|
android:screenOrientation="sensorLandscape"
|
||||||
android:configChanges="orientation|keyboardHidden"/>
|
android:configChanges="orientation|keyboardHidden"/>
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
package com.rookiedev.hexapod
|
package com.rookiedev.hexapod
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.res.Resources
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.TypedValue
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.rookiedev.hexapod.network.TCPClient
|
import com.rookiedev.hexapod.network.TCPClient
|
||||||
import com.rookiedev.hexapod.network.TCPClient.OnConnectEstablished
|
import com.rookiedev.hexapod.network.TCPClient.OnConnectEstablished
|
||||||
import com.rookiedev.hexapod.network.TCPClient.OnMessageReceived
|
import com.rookiedev.hexapod.network.TCPClient.OnMessageReceived
|
||||||
|
import kotlinx.coroutines.*
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
import kotlin.math.atan2
|
import kotlin.math.atan2
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
import kotlinx.coroutines.*
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,32 +69,28 @@ class ControlActivity : AppCompatActivity() {
|
|||||||
private var radius = 0f
|
private var radius = 0f
|
||||||
|
|
||||||
private var tcpClient: TCPClient? = null
|
private var tcpClient: TCPClient? = null
|
||||||
|
private var ip:String = ""
|
||||||
|
private var port = 0
|
||||||
|
|
||||||
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||||
|
|
||||||
private var currentState: String = "standby"
|
private var currentState: String = "standby"
|
||||||
|
|
||||||
// private val lock = ReentrantLock()
|
|
||||||
// private val waitLock = lock.newCondition()
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_control)
|
setContentView(R.layout.activity_control)
|
||||||
|
|
||||||
|
val myIntent = intent // gets the previously created intent
|
||||||
|
|
||||||
|
ip = myIntent.getStringExtra("ip").toString()
|
||||||
|
port = myIntent.getStringExtra("port").toString().toInt()
|
||||||
|
|
||||||
controlWindowInsets(true)
|
controlWindowInsets(true)
|
||||||
|
|
||||||
val controlCircle = findViewById<ImageView>(R.id.control_image)
|
val controlCircle = findViewById<ImageView>(R.id.control_image)
|
||||||
|
|
||||||
val dip = 32f
|
|
||||||
val r: Resources = resources
|
|
||||||
this.pxMargin = TypedValue.applyDimension(
|
|
||||||
TypedValue.COMPLEX_UNIT_DIP,
|
|
||||||
dip,
|
|
||||||
r.displayMetrics
|
|
||||||
)
|
|
||||||
|
|
||||||
val vto: ViewTreeObserver = controlCircle.viewTreeObserver
|
val vto: ViewTreeObserver = controlCircle.viewTreeObserver
|
||||||
vto.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
|
vto.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
|
||||||
override fun onPreDraw(): Boolean {
|
override fun onPreDraw(): Boolean {
|
||||||
@ -132,7 +126,7 @@ class ControlActivity : AppCompatActivity() {
|
|||||||
currentState = "standby"
|
currentState = "standby"
|
||||||
}
|
}
|
||||||
} else if (length >= radius / 3 && length < 2 * radius / 3) {
|
} else if (length >= radius / 3 && length < 2 * radius / 3) {
|
||||||
var angle = atan2(coorY, coorX)
|
val angle = atan2(coorY, coorX)
|
||||||
if (angle > -PI / 4 && angle <= PI / 4) {
|
if (angle > -PI / 4 && angle <= PI / 4) {
|
||||||
if (currentState != "shiftright") {
|
if (currentState != "shiftright") {
|
||||||
println("Move right")
|
println("Move right")
|
||||||
@ -159,7 +153,7 @@ class ControlActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (length >= 2 * radius / 3 && length < radius) {
|
} else if (length >= 2 * radius / 3 && length < radius) {
|
||||||
var angle = atan2(coorY, coorX)
|
val angle = atan2(coorY, coorX)
|
||||||
if (angle > -PI / 4 && angle <= PI / 4) {
|
if (angle > -PI / 4 && angle <= PI / 4) {
|
||||||
if (currentState != "rightturn") {
|
if (currentState != "rightturn") {
|
||||||
println("Turn right")
|
println("Turn right")
|
||||||
@ -190,7 +184,7 @@ class ControlActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
this.tcpClient = TCPClient(this, "192.168.1.202", 1234, object : OnMessageReceived {
|
this.tcpClient = TCPClient(this, ip, port, object : OnMessageReceived {
|
||||||
override fun messageReceived(message: String?) {
|
override fun messageReceived(message: String?) {
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
// alertDialog(DISCONNECTED)
|
// alertDialog(DISCONNECTED)
|
||||||
|
@ -24,8 +24,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
buttonConnect.setOnClickListener {
|
buttonConnect.setOnClickListener {
|
||||||
// your code to perform when the user clicks on the button
|
// your code to perform when the user clicks on the button
|
||||||
|
|
||||||
Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()
|
// Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()
|
||||||
val intent = Intent(this, ControlActivity::class.java).apply {
|
val intent = Intent(this, ControlActivity::class.java).apply {
|
||||||
|
putExtra("ip", ipInput.text.toString())
|
||||||
|
putExtra("port", portInput.text.toString())
|
||||||
}
|
}
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:digits="0123456789."
|
android:digits="0123456789."
|
||||||
android:hint="IP"
|
android:hint="IP"
|
||||||
android:inputType="number|numberDecimal" />
|
android:inputType="number|numberDecimal"
|
||||||
|
android:text="192.168.1.202" />
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
@ -58,7 +59,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Port"
|
android:hint="Port"
|
||||||
android:inputType="number" />
|
android:inputType="number"
|
||||||
|
android:text="1234" />
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user