2014-03-31 11:06:40 -04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package ve.ucv.ciens.ccg.nxtarbot;
|
|
|
|
|
|
2014-03-31 11:47:46 -04:30
|
|
|
import java.io.DataInputStream;
|
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
import lejos.nxt.comm.Bluetooth;
|
|
|
|
|
import lejos.nxt.comm.NXTConnection;
|
|
|
|
|
import ve.ucv.ciens.ccg.nxtarbot.threads.CommRecv;
|
|
|
|
|
import ve.ucv.ciens.ccg.nxtarbot.threads.CommSend;
|
2014-03-31 11:06:40 -04:30
|
|
|
|
|
|
|
|
public class NxtAR_bot{
|
2014-03-31 11:47:46 -04:30
|
|
|
private static DataOutputStream dataOutputStream;
|
|
|
|
|
private static DataInputStream dataInputStream;
|
|
|
|
|
private static NXTConnection bluetoothConnection;
|
|
|
|
|
private static CommRecv recv;
|
|
|
|
|
private static CommSend send;
|
|
|
|
|
|
2014-03-31 11:06:40 -04:30
|
|
|
public static void main(String[] args){
|
2014-03-31 11:47:46 -04:30
|
|
|
bluetoothConnection = Bluetooth.waitForConnection();
|
|
|
|
|
bluetoothConnection.setIOMode(NXTConnection.RAW);
|
|
|
|
|
dataOutputStream = bluetoothConnection.openDataOutputStream();
|
|
|
|
|
dataInputStream = bluetoothConnection.openDataInputStream();
|
|
|
|
|
|
|
|
|
|
System.out.println("Connected");
|
|
|
|
|
|
|
|
|
|
send = new CommSend(dataOutputStream);
|
|
|
|
|
recv = new CommRecv(dataInputStream);
|
|
|
|
|
|
|
|
|
|
recv.start();
|
|
|
|
|
send.start();
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
recv.join();
|
|
|
|
|
send.join();
|
|
|
|
|
}catch(InterruptedException i){ }
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
dataOutputStream.close();
|
|
|
|
|
dataInputStream.close();
|
|
|
|
|
}catch(IOException io){
|
|
|
|
|
System.out.println(io.getMessage());
|
|
|
|
|
}
|
|
|
|
|
bluetoothConnection.close();
|
2014-03-31 11:06:40 -04:30
|
|
|
}
|
|
|
|
|
}
|