Esempio n. 1
0
  public SlaveExercise() {
    super();
    final Handler mHandler =
        new Handler(Looper.getMainLooper()) {
          @Override
          public void handleMessage(Message msg) {
            if (msg.what == Constants.MESSAGE_SEND) {
              String message = (String) msg.obj;
              getMessage(message);
            }
            super.handleMessage(msg);
          }
        };

    CommunicationManager communicationManager = CommunicationManager.getInstance();

    BluetoothSocket socket = communicationManager.getSockets().get(0);
    CommunicationThread thread = new CommunicationThread(socket, mHandler);
    thread.start();
    communicationThread = thread;
  }
Esempio n. 2
0
 @Override
 public void setCharge(View v) {
   JSONObject message = new JSONObject();
   try {
     message.put(Constants.JSON_NAME, name);
     message.put(Constants.JSON_MESSAGE, "Charge value change");
     message.put(Constants.JSON_CHARGE_VALUE, charge);
     message.put(Constants.JSON_SPHERO_NUMBER, position);
   } catch (JSONException e) {
     Log.e(Constants.LOG_TAG, "Error writing JSON", e);
   }
   communicationThread.write(message.toString());
 }
Esempio n. 3
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   communicationThread.cancel();
 }