/**
  * delete event を送る.
  *
  * @param profile profile.
  * @param attribute attribute.
  * @param mgr PebbleManager
  */
 private void sendDeleteEvent(final int profile, final int attribute, final PebbleManager mgr) {
   PebbleDictionary dic = new PebbleDictionary();
   dic.addInt8(PebbleManager.KEY_PROFILE, (byte) profile);
   dic.addInt8(PebbleManager.KEY_ATTRIBUTE, (byte) attribute);
   dic.addInt8(PebbleManager.KEY_ACTION, (byte) PebbleManager.ACTION_DELETE);
   mgr.sendCommandToPebble(dic, null);
 }
  @SmallTest
  public void testReceiveDataWithPLAY_PRESSStartsLocationServices() {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addUint32(Constants.CMD_BUTTON_PRESS, Constants.PLAY_PRESS);

    _pebbleDataReceiver.receiveData(_mockContext, 12345, dic);

    verify(_mockServiceStarter, times(1)).startLocationServices();
  }
  @SmallTest
  public void testReceiveDataWithORUXMAPS_NEW_WAYPOINT_PRESSAddsNewWaypoint() {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addUint32(Constants.CMD_BUTTON_PRESS, Constants.ORUXMAPS_NEW_WAYPOINT_PRESS);

    _pebbleDataReceiver.receiveData(_mockContext, 12345, dic);

    verify(_mockOruxMaps, times(1)).newWaypoint();
  }
  @SmallTest
  public void testReceiveDataWithORUXMAPS_STOP_RECORD_PRESSStartsRecord() {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addUint32(Constants.CMD_BUTTON_PRESS, Constants.ORUXMAPS_STOP_RECORD_PRESS);

    _pebbleDataReceiver.receiveData(_mockContext, 12345, dic);

    verify(_mockOruxMaps, times(1)).stopRecord();
  }
Ejemplo n.º 5
0
  public void sendDataToWatch() {
    // Build up a Pebble dictionary
    PebbleDictionary data = new PebbleDictionary();

    data.addUint8(0, (byte) tresholdLevel);

    // Send the assembled dictionary to the weather watch-app;
    PebbleKit.sendDataToPebble(
        getApplicationContext(), UUID.fromString("5ed10362-a625-41e6-b35c-e6b10feb71e6"), data);
  }
  @SmallTest
  public void
      testReceiveDataWithMSG_VERSION_PEBBLEAndVersionGreaterOrEqualThanCurrentDoesNotSendMessage()
          throws InterruptedException {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addInt32(Constants.MSG_VERSION_PEBBLE, Constants.LAST_VERSION_PEBBLE);

    _pebbleDataReceiver.receiveData(_mockContext, 12345, dic);

    verify(_mockMessageManager, timeout(1000).times(0)).sendMessageToPebble(any(String.class));
  }
  @SmallTest
  public void testReceiveDataWithREFRESH_PRESSResetsSavedData() throws InterruptedException {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addUint32(Constants.CMD_BUTTON_PRESS, Constants.REFRESH_PRESS);

    _pebbleDataReceiver.receiveData(_mockContext, 12345, dic);

    _stateLatch.await(1000, TimeUnit.MILLISECONDS);
    verify(_mockDataStore, times(1)).resetAllValues();
    verify(_mockDataStore, times(1)).commit();
  }
  @SmallTest
  public void testReceiveDataWithREFRESH_PRESSRefreshLocationServices()
      throws InterruptedException {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addUint32(Constants.CMD_BUTTON_PRESS, Constants.REFRESH_PRESS);

    _pebbleDataReceiver.receiveData(_mockContext, 12345, dic);

    _stateLatch.await(1000, TimeUnit.MILLISECONDS);
    assertNotNull(_refreshEvent);
  }
Ejemplo n.º 9
0
  public void sendWeatherDataToWatch(int weatherIconId, String temp) {
    // Build up a Pebble dictionary containing the weather icon and the current temperature in
    // degrees fahrenheit
    PebbleDictionary data = new PebbleDictionary();
    data.addUint8(ICON_KEY, (byte) weatherIconId);
    data.addString(TEMP_KEY, temp);

    // Send the assembled dictionary to the weather watch-app; this is a no-op if the app isn't
    // running or is not
    // installed
    PebbleKit.sendDataToPebble(caller.getApplicationContext(), WEATHER_UUID, data);
  }
 @Override
 public void receiveData(Context context, int transactionId, PebbleDictionary data) {
   Follow followMe = ((DroidPlannerApp) applicationContext).followMe;
   PebbleKit.sendAckToPebble(applicationContext, transactionId);
   int request = (data.getInteger(KEY_PEBBLE_REQUEST).intValue());
   switch (request) {
     case KEY_REQUEST_MODE_FOLLOW:
       followMe.toggleFollowMeState();
       break;
     case KEY_REQUEST_CYCLE_FOLLOW_TYPE:
       followMe.cycleType();
       break;
     case KEY_REQUEST_MODE_LOITER:
       ((DroidPlannerApp) applicationContext)
           .getDrone()
           .state
           .changeFlightMode(ApmModes.ROTOR_LOITER);
       break;
     case KEY_REQUEST_MODE_RTL:
       ((DroidPlannerApp) applicationContext)
           .getDrone()
           .state
           .changeFlightMode(ApmModes.ROTOR_RTL);
       break;
   }
 }
 @Override
 protected boolean onPutOnDeviceOrientation(
     final Intent request, final Intent response, final String deviceId, final String sessionKey) {
   if (deviceId == null) {
     MessageUtils.setEmptyDeviceIdError(response);
     return true;
   } else if (!PebbleUtil.checkDeviceId(deviceId)) {
     MessageUtils.setNotFoundDeviceError(response);
     return true;
   } else if (sessionKey == null) {
     MessageUtils.setInvalidRequestParameterError(response, ERROR_MESSAGE);
     return true;
   } else {
     PebbleManager mgr = ((PebbleDeviceService) getContext()).getPebbleManager();
     // Pebbleで加速度センサーの登録依頼を送る
     PebbleDictionary dic = new PebbleDictionary();
     dic.addInt8(PebbleManager.KEY_PROFILE, (byte) PebbleManager.PROFILE_DEVICE_ORIENTATION);
     dic.addInt8(
         PebbleManager.KEY_ATTRIBUTE,
         (byte) PebbleManager.DEVICE_ORIENTATION_ATTRIBUTE_ON_DEVICE_ORIENTATION);
     dic.addInt8(PebbleManager.KEY_ACTION, (byte) PebbleManager.ACTION_PUT);
     mgr.sendCommandToPebble(
         dic,
         new OnSendCommandListener() {
           @Override
           public void onReceivedData(final PebbleDictionary dic) {
             if (dic == null) {
               MessageUtils.setUnknownError(response);
             } else {
               // イベントリスナーを登録
               EventError error = EventManager.INSTANCE.addEvent(request);
               if (error == EventError.NONE) {
                 setResult(response, DConnectMessage.RESULT_OK);
               } else if (error == EventError.INVALID_PARAMETER) {
                 MessageUtils.setInvalidRequestParameterError(response);
               } else {
                 MessageUtils.setUnknownError(response);
               }
             }
             getContext().sendBroadcast(response);
           }
         });
     // レスポンスを非同期で返却するので、falseを返す
     return false;
   }
 }
  /**
   * Sends a full dictionary with updated information when called. If no pebble is present, the
   * watchapp isn't installed, or the watchapp isn't running, nothing will happen.
   *
   * @param drone
   */
  public void sendDataToWatchNow(Drone drone) {
    Follow followMe = ((DroidPlannerApp) applicationContext).followMe;
    PebbleDictionary data = new PebbleDictionary();

    String mode = drone.state.getMode().getName();
    if (!drone.state.isArmed()) mode = "Disarmd";
    else if (((DroidPlannerApp) applicationContext).followMe.isEnabled() && mode == "Guided")
      mode = "Follow";
    data.addString(KEY_MODE, mode);

    FollowModes type = followMe.getType();
    if (type != null) {
      data.addString(KEY_FOLLOW_TYPE, type.toString());
    } else data.addString(KEY_FOLLOW_TYPE, "none");

    String bat = "Bat:" + Double.toString(roundToOneDecimal(drone.battery.getBattVolt())) + "V";
    String speed = "Speed: " + Double.toString(roundToOneDecimal(drone.speed.getAirSpeed()));
    String altitude = "Alt: " + Double.toString(roundToOneDecimal(drone.altitude.getAltitude()));
    String telem = bat + "\n" + altitude + "\n" + speed;
    data.addString(KEY_TELEM, telem);

    data.addString(KEY_APP_VERSION, EXPECTED_APP_VERSION);

    PebbleKit.sendDataToPebble(applicationContext, DP_UUID, data);
  }
Ejemplo n.º 13
0
  /**
   * Sends an event to the app, and tells whether it's been added or removed
   *
   * @param e
   * @param added
   */
  public void sendEvent(Event e, boolean added) {
    byte b_false = 0;
    byte b_true = 1;
    PebbleDictionary data = new PebbleDictionary();
    //		data.addInt32(0,e.hashCode); //The batch number of this transaction
    data.addInt8(1, added ? b_true : b_false); // I have no idea what I'm doing
    data.addInt32(2, e.startDay);
    data.addInt32(3, e.endDay);
    data.addInt32(4, e.startTime);
    data.addInt32(5, e.endTime);
    data.addString(6, e.title);
    pending_events.put(COUNTER, data);
    Log.i(MainActivity.TAG, "start time:" + e.startTime);
    Log.i(MainActivity.TAG, "start day:" + e.startDay);

    pending_events.put(COUNTER, data);
    PebbleKit.sendDataToPebbleWithTransactionId(
        ctx, PEBBLE_APP_UUID, data, COUNTER); // counter is also transaction ID
    COUNTER++;
  }