// 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(); }
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(); } }
// 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(); }
// 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(); }
// 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; } }
/** Disconnect from server */ public void disconnectServer() { t.interrupt(); // Stopp communication thread }
/** * 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(); }
public void unPause() { pause = false; for (CommunicationThread c : clients) { c.unpause(); } }
public void pause() { pause = true; for (CommunicationThread c : clients) { c.pause(); } }