e02acfa4e1b000171eb4aea94a5e3c6b 929 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. } catch (IOException e) { }
  28. before = command;
  29. }
  30. try {
  31. Thread.sleep(200);
  32. } catch (InterruptedException e) {
  33. // TODO Auto-generated catch block
  34. e.printStackTrace();
  35. }
  36. }
  37. }
  38. public void send (int c) {
  39. command = c;
  40. }
  41. }