Ejemplo n.º 1
0
 // Begin BT communicaction thread
 private void beginCommunication(BluetoothSocket socket) {
   Log.i(TAG, "BonitorActivity - beginComunication()");
   // Begin Bluetooth Communication
   if (communicationThread != null) {
     communicationThread.cancel();
   }
   communicationThread = new CommunicationThread(socket);
   communicationThread.start();
 }
Ejemplo n.º 2
0
 public void run() {
   /** Start listening for socket connections */
   Socket socket = null;
   try {
     serverSocket = new ServerSocket(6000);
   } catch (IOException e) {
     e.printStackTrace();
   }
   try {
     socket = serverSocket.accept();
     CommunicationThread ct = new CommunicationThread(socket);
     clients.add(ct);
     ct.start();
     if (pause) {
       ct.pause();
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 // Back button pressed
 @Override
 public void onBackPressed() {
   Log.e(TAG, "BonitorActivity - onBackPressed()");
   if (connectionThread != null) {
     connectionThread.cancel();
   }
   if (communicationThread != null) {
     communicationThread.cancel();
   }
   if (fileWriter != null) {
     try {
       fileWriter.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   finish();
 }
Ejemplo n.º 4
0
 // onDestroy
 @Override
 protected void onDestroy() {
   Log.e(TAG, "BonitorActivity - onDestroy()");
   super.onDestroy();
   if (connectionThread != null) {
     connectionThread.cancel();
   }
   if (communicationThread != null) {
     communicationThread.cancel();
   }
   if (fileWriter != null) {
     try {
       fileWriter.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   finish();
 }
Ejemplo n.º 5
0
 // Click one button
 public void click(View v) {
   Log.i(TAG, "BonitorActivity - click()");
   switch (v.getId()) {
     case R.id.btnSend: // Send data
       if (communicationThread != null) {
         // To Arduino
         String msg = txt.getText().toString();
         Log.v(TAG, "SEND -> " + msg);
         communicationThread.write(msg);
         // To Monitor
         // String aux = msgTotal;
         // msgTotal = msg + '\n';
         printMonitor(msg + '\n');
         // msgTotal = aux;
       }
       txt.setText("");
       break;
     case R.id.btnFreeze: // Freeze monitor
       if (((ToggleButton) v).isChecked()) {
         Log.v(TAG, "FREEZE");
         freeze = true;
       } else {
         Log.v(TAG, "NOT FREEZE");
         freeze = false;
       }
       break;
     case R.id.btnTopDown: // TopDown
       if (((ToggleButton) v).isChecked()) {
         topDown = true;
       } else {
         topDown = false;
       }
     case R.id.btnClean: // Clean monitor
       Log.v(TAG, "CLEAN MONITOR");
       linearLayout.removeAllViews();
       count = 0;
       break;
   }
 }
Ejemplo n.º 6
0
 /** Disconnect from server */
 public void disconnectServer() {
   t.interrupt(); // Stopp communication thread
 }
Ejemplo n.º 7
0
 /**
  * Connect to server
  *
  * @param socket
  * @throws IOException - throws exception if we cant establish connection
  */
 public void createConnection(Socket socket) throws IOException {
   this.socket = socket;
   connector = new Connector(socket);
   t = new CommunicationThread(connector, gui);
   t.start();
 }
Ejemplo n.º 8
0
 public void unPause() {
   pause = false;
   for (CommunicationThread c : clients) {
     c.unpause();
   }
 }
Ejemplo n.º 9
0
 public void pause() {
   pause = true;
   for (CommunicationThread c : clients) {
     c.pause();
   }
 }