Wait for 250ms before sending again
This commit is contained in:
parent
a8e8ccbbe1
commit
e9114fdfe5
@ -38,6 +38,8 @@ public class HomeFragment extends Fragment {
|
||||
MainActivity mainActivity;
|
||||
|
||||
Communication com = new Communication();
|
||||
long lastOnMoveCall = System.currentTimeMillis();
|
||||
|
||||
|
||||
private FragmentManuellBinding binding;
|
||||
|
||||
@ -105,36 +107,47 @@ public class HomeFragment extends Fragment {
|
||||
joystick.setOnMoveListener(new JoystickView.OnMoveListener() {
|
||||
@Override
|
||||
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));
|
||||
//8 segments of the joystick
|
||||
if((angle >= 338 || angle < 22) && strength != 0){
|
||||
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){
|
||||
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){
|
||||
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){
|
||||
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){
|
||||
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){
|
||||
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){
|
||||
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){
|
||||
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{
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user