connection to FlightGear and design

This commit is contained in:
Omer Schloss
2021-06-20 21:15:51 +03:00
parent d8a1345a4d
commit f2ff9354d3
15 changed files with 354 additions and 173 deletions

View File

@@ -0,0 +1,50 @@
package com.example.flightgearcontrollerapp.model
class FGModel {
private val telnetClient = TelnetClient()
private var isExceptionOccurred = false
//private val joystickView = JoystickView()
private var isTouchingJoystick = false
/*
private val jsCenterX = 0
private val jsCenterY = 0
private val jsOuterRadius = 0
private val jsInnerRadius = 0
*/
fun connect(ipAddress: String, portAddress: String): Boolean {
var res = false
val t = Thread {
try {
res = telnetClient.connect(ipAddress, portAddress.toInt())
} catch (e: Exception) {
e.printStackTrace()
throw RuntimeException(e)
}
}
val h = Thread.UncaughtExceptionHandler { _, _ -> isExceptionOccurred = true;res= false }
t.uncaughtExceptionHandler = h
t.start()
try {
t.join()
if (!isExceptionOccurred) {
this.isTouchingJoystick = false
}
} catch (e: Exception) {
e.printStackTrace()
return false
}
return res
}
fun disconnect() {
telnetClient.disconnect()
}
}