This commit is contained in:
Omer Schloss 2021-06-24 10:15:35 +03:00
parent 428016ce8c
commit f39dd6f61a
12 changed files with 63 additions and 28 deletions

View File

@ -42,6 +42,9 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.jackandphantom.android:joystickview:1.0.2' implementation 'com.jackandphantom.android:joystickview:1.0.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
//testImplementation 'junit:junit:4.+' //testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

View File

@ -9,11 +9,10 @@
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false" android:supportsRtl="false"
android:theme="@style/Theme.FlightGearControllerApp"> android:theme="@style/Theme.FlightGearControllerApp" >
<activity
<activity android:name=".views.MainActivity" android:name=".views.MainActivity"
android:theme="@style/Theme.FlightGearControllerApp.NoActionBar"> android:theme="@style/Theme.FlightGearControllerApp.NoActionBar" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -50,6 +50,18 @@ class FGModel {
} }
} }
fun setAileron(fl: Float) {
if(isConnected) {
telnetClient.updateAileron(fl)
}
}
fun setElevator(fl: Float) {
if(isConnected) {
telnetClient.updateElevator(fl)
}
}
} }

View File

@ -13,16 +13,15 @@ class TelnetClient{
private lateinit var executor: ExecutorService private lateinit var executor: ExecutorService
fun connect(ipAddress: String, portAddress: Int): Boolean { fun connect(ipAddress: String, portAddress: Int): Boolean {
return try { try {
client = Socket() client = Socket()
client.connect(InetSocketAddress(ipAddress, portAddress),5000) client.connect(InetSocketAddress(ipAddress, portAddress),5000)
output = PrintWriter(client.getOutputStream(), true) output = PrintWriter(client.getOutputStream(), true)
executor = Executors.newSingleThreadExecutor(); executor = Executors.newSingleThreadExecutor()
true return true
}catch (e: Exception){ }catch (e: Exception){
e.printStackTrace() e.printStackTrace()
throw RuntimeException(e) throw RuntimeException(e)
false
} }
} }
@ -41,4 +40,13 @@ class TelnetClient{
fun updateRudder(fl: Float) { fun updateRudder(fl: Float) {
executor.execute { output.print("set /controls/flight/rudder $fl\r\n");output.flush() } executor.execute { output.print("set /controls/flight/rudder $fl\r\n");output.flush() }
} }
fun updateAileron(fl: Float) {
executor.execute { output.print("set /controls/flight/aileron $fl\r\n");output.flush() }
}
fun updateElevator(fl: Float) {
executor.execute { output.print("set /controls/flight/elevator $fl\r\n");output.flush() }
}
} }

View File

@ -2,7 +2,6 @@ package com.example.flightgearcontrollerapp.view_model
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.example.flightgearcontrollerapp.model.FGModel import com.example.flightgearcontrollerapp.model.FGModel
import java.util.concurrent.ExecutorService
class FGViewModel : ViewModel() { class FGViewModel : ViewModel() {
private val model = FGModel() private val model = FGModel()
@ -25,4 +24,11 @@ class FGViewModel : ViewModel() {
model.setRudder(fl) model.setRudder(fl)
} }
fun setAileron(fl: Float) {
model.setAileron(fl)
}
fun setElevator(fl: Float) {
model.setElevator(fl)
}
} }

View File

@ -1,4 +0,0 @@
package com.example.flightgearcontrollerapp.view_model
class JoyStickVM {
}

View File

@ -0,0 +1,16 @@
package com.example.flightgearcontrollerapp.views
import android.util.Log
import com.jackandphantom.joystickview.JoyStickView
class JoyStick(jsv: JoyStickView) {
/* private var joyStickView = jsv
init {
joyStickView.setOnMoveListener(object : JoyStickView.OnMov0eListener( run {
fun onMove(angle: Int, strength: Int) {
Log.i("TAG", "angle: $angle strength: $strength");
}
})
}*/
}

View File

@ -1,5 +0,0 @@
package com.example.flightgearcontrollerapp.views
class JoyStickView{
}

View File

@ -13,6 +13,7 @@ import com.example.flightgearcontrollerapp.R
import com.example.flightgearcontrollerapp.R.id.* import com.example.flightgearcontrollerapp.R.id.*
import com.example.flightgearcontrollerapp.view_model.FGViewModel import com.example.flightgearcontrollerapp.view_model.FGViewModel
import com.google.android.material.slider.Slider import com.google.android.material.slider.Slider
import com.jackandphantom.joystickview.JoyStickView
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@ -20,6 +21,7 @@ class MainActivity : AppCompatActivity() {
private val vmConnection = FGViewModel() private val vmConnection = FGViewModel()
private lateinit var throttleSlider: Slider private lateinit var throttleSlider: Slider
private lateinit var rudderSlider: Slider private lateinit var rudderSlider: Slider
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
@ -49,7 +51,7 @@ class MainActivity : AppCompatActivity() {
rudderSlider.addOnChangeListener { _, value, _ -> rudderSlider.addOnChangeListener { _, value, _ ->
vmConnection.setRudder(value) vmConnection.setRudder(value)
} }
// var joyStick = JoyStick(findViewById(widget_joystick))
} }

View File

@ -8,10 +8,7 @@
<variable <variable
name="viewModel" name="viewModel"
type="com.example.flightgearcontrollerapp.view_model.FGViewModel" /> type="com.example.flightgearcontrollerapp.view_model.FGViewModel" />
<variable <variable
name="joystickVM"
type="com.example.flightgearcontrollerapp.view_model.JoyStickVM"/>
<variable
name="model" name="model"
type="com.example.flightgearcontrollerapp.model.FGModel"/> type="com.example.flightgearcontrollerapp.model.FGModel"/>
</data> </data>
@ -140,13 +137,10 @@
android:id="@+id/widget_joystick" android:id="@+id/widget_joystick"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginBottom="0dp"
app:innerCircleColor="#f6FFFFFF" app:innerCircleColor="#f6FFFFFF"
app:innerCircleImage="@drawable/ic_baseline_airplanemode_active_24" app:innerCircleImage="@drawable/ic_baseline_airplane_mode_active_24"
app:outerCircleBorderColor="#fff" app:outerCircleBorderColor="#fff"
app:outerCircleBorderWidth="5" app:outerCircleBorderWidth="5"
app:outerCircleColor="@color/navy_blue_40" app:outerCircleColor="@color/navy_blue_40"

View File

@ -7,6 +7,10 @@ buildscript {
dependencies { dependencies {
classpath "com.android.tools.build:gradle:4.2.1" classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.5.10"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }