From f39dd6f61a05c1d0d69bd9eb81075271ec25ea4c Mon Sep 17 00:00:00 2001 From: Omer Schloss Date: Thu, 24 Jun 2021 10:15:35 +0300 Subject: [PATCH] update --- app/build.gradle | 3 +++ app/src/main/AndroidManifest.xml | 9 ++++----- .../flightgearcontrollerapp/model/FGModel.kt | 12 ++++++++++++ .../model/TelnetClient.kt | 16 ++++++++++++---- .../view_model/FGViewModel.kt | 8 +++++++- .../view_model/JoyStickVM.kt | 4 ---- .../flightgearcontrollerapp/views/JoyStick.kt | 16 ++++++++++++++++ .../views/JoyStickView.kt | 5 ----- .../views/MainActivity.kt | 4 +++- ...l => ic_baseline_airplane_mode_active_24.xml} | 0 app/src/main/res/layout/activity_main.xml | 10 ++-------- build.gradle | 4 ++++ 12 files changed, 63 insertions(+), 28 deletions(-) delete mode 100644 app/src/main/java/com/example/flightgearcontrollerapp/view_model/JoyStickVM.kt create mode 100644 app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStick.kt delete mode 100644 app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStickView.kt rename app/src/main/res/drawable/{ic_baseline_airplanemode_active_24.xml => ic_baseline_airplane_mode_active_24.xml} (100%) diff --git a/app/build.gradle b/app/build.gradle index 80c3074..836fe51 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,6 +42,9 @@ dependencies { implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 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.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 764c4f6..b68f0e7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,11 +9,10 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="false" - android:theme="@style/Theme.FlightGearControllerApp"> - - - + android:theme="@style/Theme.FlightGearControllerApp" > + diff --git a/app/src/main/java/com/example/flightgearcontrollerapp/model/FGModel.kt b/app/src/main/java/com/example/flightgearcontrollerapp/model/FGModel.kt index b9c5fed..5d1639a 100644 --- a/app/src/main/java/com/example/flightgearcontrollerapp/model/FGModel.kt +++ b/app/src/main/java/com/example/flightgearcontrollerapp/model/FGModel.kt @@ -50,6 +50,18 @@ class FGModel { } } + fun setAileron(fl: Float) { + if(isConnected) { + telnetClient.updateAileron(fl) + } + } + + fun setElevator(fl: Float) { + if(isConnected) { + telnetClient.updateElevator(fl) + } + } + } diff --git a/app/src/main/java/com/example/flightgearcontrollerapp/model/TelnetClient.kt b/app/src/main/java/com/example/flightgearcontrollerapp/model/TelnetClient.kt index d6ffea2..4342ac8 100644 --- a/app/src/main/java/com/example/flightgearcontrollerapp/model/TelnetClient.kt +++ b/app/src/main/java/com/example/flightgearcontrollerapp/model/TelnetClient.kt @@ -13,16 +13,15 @@ class TelnetClient{ private lateinit var executor: ExecutorService fun connect(ipAddress: String, portAddress: Int): Boolean { - return try { + try { client = Socket() client.connect(InetSocketAddress(ipAddress, portAddress),5000) output = PrintWriter(client.getOutputStream(), true) - executor = Executors.newSingleThreadExecutor(); - true + executor = Executors.newSingleThreadExecutor() + return true }catch (e: Exception){ e.printStackTrace() throw RuntimeException(e) - false } } @@ -41,4 +40,13 @@ class TelnetClient{ fun updateRudder(fl: Float) { 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() } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/example/flightgearcontrollerapp/view_model/FGViewModel.kt b/app/src/main/java/com/example/flightgearcontrollerapp/view_model/FGViewModel.kt index fb2e074..710b66a 100644 --- a/app/src/main/java/com/example/flightgearcontrollerapp/view_model/FGViewModel.kt +++ b/app/src/main/java/com/example/flightgearcontrollerapp/view_model/FGViewModel.kt @@ -2,7 +2,6 @@ package com.example.flightgearcontrollerapp.view_model import androidx.lifecycle.ViewModel import com.example.flightgearcontrollerapp.model.FGModel -import java.util.concurrent.ExecutorService class FGViewModel : ViewModel() { private val model = FGModel() @@ -25,4 +24,11 @@ class FGViewModel : ViewModel() { model.setRudder(fl) } + fun setAileron(fl: Float) { + model.setAileron(fl) + } + + fun setElevator(fl: Float) { + model.setElevator(fl) + } } diff --git a/app/src/main/java/com/example/flightgearcontrollerapp/view_model/JoyStickVM.kt b/app/src/main/java/com/example/flightgearcontrollerapp/view_model/JoyStickVM.kt deleted file mode 100644 index 97ab617..0000000 --- a/app/src/main/java/com/example/flightgearcontrollerapp/view_model/JoyStickVM.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.example.flightgearcontrollerapp.view_model - -class JoyStickVM { -} \ No newline at end of file diff --git a/app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStick.kt b/app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStick.kt new file mode 100644 index 0000000..240805a --- /dev/null +++ b/app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStick.kt @@ -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"); + } + }) + }*/ +} \ No newline at end of file diff --git a/app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStickView.kt b/app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStickView.kt deleted file mode 100644 index 445e939..0000000 --- a/app/src/main/java/com/example/flightgearcontrollerapp/views/JoyStickView.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.example.flightgearcontrollerapp.views - -class JoyStickView{ - -} diff --git a/app/src/main/java/com/example/flightgearcontrollerapp/views/MainActivity.kt b/app/src/main/java/com/example/flightgearcontrollerapp/views/MainActivity.kt index 361451b..40dc63b 100644 --- a/app/src/main/java/com/example/flightgearcontrollerapp/views/MainActivity.kt +++ b/app/src/main/java/com/example/flightgearcontrollerapp/views/MainActivity.kt @@ -13,6 +13,7 @@ import com.example.flightgearcontrollerapp.R import com.example.flightgearcontrollerapp.R.id.* import com.example.flightgearcontrollerapp.view_model.FGViewModel import com.google.android.material.slider.Slider +import com.jackandphantom.joystickview.JoyStickView class MainActivity : AppCompatActivity() { @@ -20,6 +21,7 @@ class MainActivity : AppCompatActivity() { private val vmConnection = FGViewModel() private lateinit var throttleSlider: Slider private lateinit var rudderSlider: Slider + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -49,7 +51,7 @@ class MainActivity : AppCompatActivity() { rudderSlider.addOnChangeListener { _, value, _ -> vmConnection.setRudder(value) } - + // var joyStick = JoyStick(findViewById(widget_joystick)) } diff --git a/app/src/main/res/drawable/ic_baseline_airplanemode_active_24.xml b/app/src/main/res/drawable/ic_baseline_airplane_mode_active_24.xml similarity index 100% rename from app/src/main/res/drawable/ic_baseline_airplanemode_active_24.xml rename to app/src/main/res/drawable/ic_baseline_airplane_mode_active_24.xml diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e2e41d0..9c8fd30 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,10 +8,7 @@ - - @@ -140,13 +137,10 @@ android:id="@+id/widget_joystick" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" - android:layout_marginEnd="0dp" - android:layout_marginBottom="0dp" app:innerCircleColor="#f6FFFFFF" - app:innerCircleImage="@drawable/ic_baseline_airplanemode_active_24" + app:innerCircleImage="@drawable/ic_baseline_airplane_mode_active_24" app:outerCircleBorderColor="#fff" app:outerCircleBorderWidth="5" app:outerCircleColor="@color/navy_blue_40" diff --git a/build.gradle b/build.gradle index 30ecab6..2f28d38 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,10 @@ buildscript { dependencies { classpath "com.android.tools.build:gradle:4.2.1" 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 // in the individual module build.gradle files }