|
|
|
|
|
|
|
|
MainActivity mainActivity; |
|
|
MainActivity mainActivity; |
|
|
|
|
|
|
|
|
Communication com = new Communication(); |
|
|
Communication com = new Communication(); |
|
|
|
|
|
long lastOnMoveCall = System.currentTimeMillis(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private FragmentManuellBinding binding; |
|
|
private FragmentManuellBinding binding; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
joystick.setOnMoveListener(new JoystickView.OnMoveListener() { |
|
|
joystick.setOnMoveListener(new JoystickView.OnMoveListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void onMove(int angle, int strength) { |
|
|
public void onMove(int angle, int strength) { |
|
|
|
|
|
boolean send = false; |
|
|
|
|
|
if (System.currentTimeMillis() - lastOnMoveCall > 250){ |
|
|
|
|
|
send = true; |
|
|
|
|
|
lastOnMoveCall = System.currentTimeMillis(); |
|
|
|
|
|
} |
|
|
|
|
|
String telegram = ""; |
|
|
|
|
|
|
|
|
homeViewModel.setText(Integer.toString(angle), Integer.toString(strength)); |
|
|
homeViewModel.setText(Integer.toString(angle), Integer.toString(strength)); |
|
|
//8 segments of the joystick |
|
|
//8 segments of the joystick |
|
|
if((angle >= 338 || angle < 22) && strength != 0){ |
|
|
if((angle >= 338 || angle < 22) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.right); |
|
|
joystick.setBackgroundResource(R.mipmap.right); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, -1, 1}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{1, -1, -1, 1}, strength); |
|
|
}else if((angle >= 22 && angle < 67) && strength != 0){ |
|
|
}else if((angle >= 22 && angle < 67) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.right_forward); |
|
|
joystick.setBackgroundResource(R.mipmap.right_forward); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{1, 0, 0, 1}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{1, 0, 0, 1}, strength); |
|
|
}else if((angle >=67 && angle < 112) && strength != 0){ |
|
|
}else if((angle >=67 && angle < 112) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.forward); |
|
|
joystick.setBackgroundResource(R.mipmap.forward); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{1, 1, 1, 1}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{1, 1, 1, 1}, strength); |
|
|
}else if((angle >=112 && angle < 157) && strength != 0){ |
|
|
}else if((angle >=112 && angle < 157) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.left_forward); |
|
|
joystick.setBackgroundResource(R.mipmap.left_forward); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{0, 1, 1, 0}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{0, 1, 1, 0}, strength); |
|
|
}else if((angle >=157 && angle < 202) && strength != 0){ |
|
|
}else if((angle >=157 && angle < 202) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.left); |
|
|
joystick.setBackgroundResource(R.mipmap.left); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, 1, -1}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{-1, 1, 1, -1}, strength); |
|
|
}else if((angle >=202 && angle < 247) && strength != 0){ |
|
|
}else if((angle >=202 && angle < 247) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.left_back); |
|
|
joystick.setBackgroundResource(R.mipmap.left_back); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{-1, 0, 0, -1}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{-1, 0, 0, -1}, strength); |
|
|
}else if((angle >=247 && angle < 292) && strength != 0){ |
|
|
}else if((angle >=247 && angle < 292) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.back); |
|
|
joystick.setBackgroundResource(R.mipmap.back); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{-1, -1, -1, -1}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{-1, -1, -1, -1}, strength); |
|
|
}else if((angle >=292 && angle < 337) && strength != 0){ |
|
|
}else if((angle >=292 && angle < 337) && strength != 0){ |
|
|
joystick.setBackgroundResource(R.mipmap.right_back); |
|
|
joystick.setBackgroundResource(R.mipmap.right_back); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{0, -1, -1, 0}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{0, -1, -1, 0}, strength); |
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
|
joystick.setBackgroundResource(R.mipmap.blank); |
|
|
joystick.setBackgroundResource(R.mipmap.blank); |
|
|
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, strength)); |
|
|
|
|
|
|
|
|
telegram = com.telegram(new int[]{0, 0, 0, 0}, strength); |
|
|
|
|
|
} |
|
|
|
|
|
if (send) |
|
|
|
|
|
{ |
|
|
|
|
|
mainActivity.sendTelegram(telegram); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |