/** * 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); }
@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; } }