0061834ce4b000171eb4aea94a5e3c6b 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import java.io.DataOutputStream;
  2. import java.io.IOException;
  3. public class SendThread extends Thread{
  4. public static final byte FORWARD = 0;
  5. public static final byte STOP = 1;
  6. public static final byte EXIT = 2;
  7. public static final byte LEFT = 3;
  8. public static final byte RIGHT = 4;
  9. public static final byte BACKWARD = 5;
  10. private int command;
  11. private int before;
  12. private boolean run;
  13. private DataOutputStream output;
  14. public SendThread(DataOutputStream out) {
  15. super();
  16. command = -1;
  17. before = command;
  18. run = true;
  19. output = out;
  20. }
  21. @Override
  22. public void run() {
  23. while (run) {
  24. if (before != command) {
  25. // try {
  26. // output.write(command);
  27. // output.flush();
  28. // System.out.println("Send cmd");
  29. // } catch (IOException e) {
  30. // System.out.println("Erro send cmd");
  31. // }
  32. System.out.println("Send cmd");
  33. before = command;
  34. }
  35. try {
  36. Thread.sleep(200);
  37. } catch (InterruptedException e) {
  38. // TODO Auto-generated catch block
  39. e.printStackTrace();
  40. }
  41. }
  42. }
  43. public void send (int c) {
  44. command = c;
  45. }
  46. }