- /* Private methods */
- private void tellMain(CMD.Response cmd, Object value)
- {
- try {
- android.os.Message msg = android.os.Message.obtain();
- msg.what = cmd.ordinal();
- msg.obj = value;
- this.messenger.send(msg);
- } catch (Exception e) {
- Util.debug("Sensors: error sending message", e);
- }
- }
-
- private void notify(String text, int icon)
- {
- // Notify Main
- this.tellMain(CMD.Response.NOTIFY, text);
-
- // Notification bar
- //Notification note = new Notification(icon, null, 0);
- //Intent intent = new Intent(this, Main.class);
- //PendingIntent pend = PendingIntent.getActivity(this, 0, intent, 0);
- //note.setLatestEventInfo(this, "iBeaconNav!", text, pend);
- //PendingIntent pend = PendingIntent.getActivity(this, 0, intent, 0);
-
- Notification note = new Notification.Builder(this)
- .setContentTitle("iBeaconNav!")
- .setContentText("iBeaconNav!")
- .setSmallIcon(icon)
- .build();
-
- this.startForeground(1, note);
- }
-
- private void handle(CMD.Command cmd, Messenger mgr)
- {
- // Validate messenger
- if (cmd != CMD.Command.REGISTER && mgr != null && mgr != this.messenger)
- Util.debug("Sensors: handle - invalid messenger");
-
- // Handle the command
- switch (cmd) {
- // Setup communication with Main
- case REGISTER:
- Util.debug("Sensors: handle - register");
- this.messenger = mgr;
- break;
-
- // Create client thread
- case CONNECT:
- Util.debug("Sensors: handle - connect");
- sensorManager.registerListener(this, accSensor, SensorManager.SENSOR_DELAY_FASTEST);
- sensorManager.registerListener(this, grvSensor, SensorManager.SENSOR_DELAY_FASTEST);
- sensorManager.registerListener(this, magSensor, SensorManager.SENSOR_DELAY_FASTEST);
- sensorManager.registerListener(this, gyrSensor, SensorManager.SENSOR_DELAY_FASTEST);
- break;
-
- // Stop client thread
- case DISCONNECT:
- Util.debug("Sensors: handle - register");
- // TODO
- break;
-
- // Reset heading
- case RSTHEAD:
- Util.debug("Sensors: handle - reset heading");
- this.rotation = new Quat();
- currentHeading = 0;
- displayData(CMD.Data.HEADING);
- break;
-
- // Reset distance
- case RSTDST:
- Util.debug("Sensors: handle - reset distance");
- currentPosX = 0;
- currentPosY = 0;
- displayData(CMD.Data.POSITION);
- break;
- }
- }
-