Error handling
This commit is contained in:
parent
8cda9e8c0f
commit
a34657dc1a
2
MobileApp/.idea/misc.xml
generated
2
MobileApp/.idea/misc.xml
generated
@ -25,7 +25,7 @@
|
|||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
@ -29,7 +29,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private ActivityMainBinding binding;
|
private ActivityMainBinding binding;
|
||||||
private ExtendedSocket socket;
|
private ExtendedSocket socket;
|
||||||
private DataTransferAsyncTask dataTransferAsyncTask;
|
private DataTransferAsyncTask dataTransferAsyncTask;
|
||||||
Boolean connected = false;
|
public Boolean connected = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -19,6 +19,7 @@ import androidx.lifecycle.ViewModelProvider;
|
|||||||
|
|
||||||
import com.example.lfrmobileapp.Communication;
|
import com.example.lfrmobileapp.Communication;
|
||||||
import com.example.lfrmobileapp.DataTransferAsyncTask;
|
import com.example.lfrmobileapp.DataTransferAsyncTask;
|
||||||
|
import com.example.lfrmobileapp.MainActivity;
|
||||||
import com.example.lfrmobileapp.R;
|
import com.example.lfrmobileapp.R;
|
||||||
import com.example.lfrmobileapp.databinding.FragmentAutomatikBinding;
|
import com.example.lfrmobileapp.databinding.FragmentAutomatikBinding;
|
||||||
|
|
||||||
@ -28,14 +29,21 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
import kotlin.collections.UArraySortingKt;
|
import kotlin.collections.UArraySortingKt;
|
||||||
|
|
||||||
|
// Autonomous Mode
|
||||||
public class DashboardFragment extends Fragment {
|
public class DashboardFragment extends Fragment {
|
||||||
Communication com = new Communication();
|
Communication com = new Communication();
|
||||||
private FragmentAutomatikBinding binding;
|
private FragmentAutomatikBinding binding;
|
||||||
|
|
||||||
|
MainActivity mainActivity;
|
||||||
|
|
||||||
//Keys for Shared Preferences
|
//Keys for Shared Preferences
|
||||||
String listKey = "listkey";
|
String listKey = "listkey";
|
||||||
|
|
||||||
DataTransferAsyncTask dataTransferAsyncTask;
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
mainActivity = (MainActivity) context;
|
||||||
|
}
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
@ -59,10 +67,12 @@ public class DashboardFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
if (mainActivity.connected){
|
||||||
if(isChecked){
|
if(isChecked){
|
||||||
dataTransferAsyncTask.writeTelegram(com.telegram(true, autoList));
|
mainActivity.sendTelegram(com.telegram(true, autoList));
|
||||||
}else{
|
}else{
|
||||||
dataTransferAsyncTask.writeTelegram(com.telegram(false, autoList));
|
mainActivity.sendTelegram(com.telegram(false, autoList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -149,7 +159,6 @@ public class DashboardFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
dataTransferAsyncTask.cancel(false);
|
|
||||||
binding = null;
|
binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -74,7 +75,12 @@ public class HomeFragment extends Fragment {
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
boolean send = false;
|
||||||
|
if (System.currentTimeMillis() - lastOnMoveCall > 250){
|
||||||
|
send = true;
|
||||||
|
lastOnMoveCall = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
if (send && mainActivity.connected) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
binding.rotateLeft.performClick();
|
binding.rotateLeft.performClick();
|
||||||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
||||||
@ -82,6 +88,7 @@ public class HomeFragment extends Fragment {
|
|||||||
} else {
|
} else {
|
||||||
mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, -1, 1}, 100));
|
mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, -1, 1}, 100));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -90,7 +97,12 @@ public class HomeFragment extends Fragment {
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
boolean send = false;
|
||||||
|
if (System.currentTimeMillis() - lastOnMoveCall > 250){
|
||||||
|
send = true;
|
||||||
|
lastOnMoveCall = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
if (send && mainActivity.connected){
|
||||||
if(event.getAction() == MotionEvent.ACTION_UP){
|
if(event.getAction() == MotionEvent.ACTION_UP){
|
||||||
binding.rotateRight.performClick();
|
binding.rotateRight.performClick();
|
||||||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
||||||
@ -98,6 +110,7 @@ public class HomeFragment extends Fragment {
|
|||||||
}else{
|
}else{
|
||||||
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100));
|
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -145,9 +158,10 @@ public class HomeFragment extends Fragment {
|
|||||||
joystick.setBackgroundResource(R.mipmap.blank);
|
joystick.setBackgroundResource(R.mipmap.blank);
|
||||||
telegram = com.telegram(new int[]{0, 0, 0, 0}, strength);
|
telegram = com.telegram(new int[]{0, 0, 0, 0}, strength);
|
||||||
}
|
}
|
||||||
if (send)
|
if (send && mainActivity.connected)
|
||||||
{
|
{
|
||||||
mainActivity.sendTelegram(telegram);
|
mainActivity.sendTelegram(telegram);
|
||||||
|
// Log.v("TAG", telegram + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -59,8 +59,8 @@ public class NotificationsFragment extends Fragment {
|
|||||||
String connectionFailed = "Verbindung fehlgeschlagen.";
|
String connectionFailed = "Verbindung fehlgeschlagen.";
|
||||||
String connectionSuccessful = "Verbindung erfolgreich.";
|
String connectionSuccessful = "Verbindung erfolgreich.";
|
||||||
|
|
||||||
String ipAddress = "192.168.0.1";
|
String ipAddress = "192.168.4.1";
|
||||||
int port = 8000;
|
int port = 8080;
|
||||||
|
|
||||||
int duration = Toast.LENGTH_LONG;
|
int duration = Toast.LENGTH_LONG;
|
||||||
DataTransferAsyncTask dataTransferAsyncTask;
|
DataTransferAsyncTask dataTransferAsyncTask;
|
||||||
@ -100,8 +100,12 @@ public class NotificationsFragment extends Fragment {
|
|||||||
final Button button = binding.connect;
|
final Button button = binding.connect;
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
try {
|
||||||
ipAddress = String.valueOf(binding.ipAdress.getText());
|
ipAddress = String.valueOf(binding.ipAdress.getText());
|
||||||
port = Integer.parseInt(String.valueOf(binding.port.getText()));
|
port = Integer.parseInt(String.valueOf(binding.port.getText()));
|
||||||
|
} catch (Exception e){
|
||||||
|
System.err.println("Parse Exception: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
connected = mainActivity.connectToWifi(ipAddress, port);
|
connected = mainActivity.connectToWifi(ipAddress, port);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user