12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import java.io.DataOutputStream;
- import java.io.IOException;
- public class SendThread extends Thread{
-
- public static final byte FORWARD = 0;
- public static final byte STOP = 1;
- public static final byte EXIT = 2;
- public static final byte LEFT = 3;
- public static final byte RIGHT = 4;
- public static final byte BACKWARD = 5;
-
- private int command;
- private int before;
- private boolean run;
- private DataOutputStream output;
-
- public SendThread(DataOutputStream out) {
- super();
- command = -1;
- before = command;
- run = true;
- output = out;
- }
-
- @Override
- public void run() {
- while (run) {
- if (before != command) {
- try {
- // output.write(command);
- // output.flush();
- System.out.println("Send cmd");
- } catch (IOException e) {
- System.out.println("Erro send cmd");
- }
- before = command;
- }
-
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- public void send (int c) {
- command = c;
- }
- }
|