Skip to content

Commit

Permalink
SensorSimulator: gyroscope sensor (only in server) + "howToAddASensor…
Browse files Browse the repository at this point in the history
….txt"

git-svn-id: https://openintents.googlecode.com/svn/trunk@3472 72b678ce-9140-0410-bee8-679b907dd61a
  • Loading branch information
ilarele committed Jul 8, 2011
1 parent 334d09f commit 0d83e62
Show file tree
Hide file tree
Showing 10 changed files with 569 additions and 9 deletions.
24 changes: 24 additions & 0 deletions ilarele_gsoc/HowToAddASensor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
In Java Application (server)
0. in SensorModel class, add constants for the new server: POZ_X, TYPE_X, X
1. describe sensor:
add classes:
XModel
XView
XController
2. add sensor in the code:
in SensorSimulatorModel add sensors.add(new XModel())
in SensorSimulatorView add sensors.add(new XView(xmodel))
in SensorSimulatorController add sensors.add(new XController(xmodel, xview))
3. add sensor in communication:
add (in model.sensor.SensorServerThread class) code in the method getSensorModelFromName, getSensorCtrlFromName


in SettingsActivity
1. in Sensor class, add TYPE_X
2. in SensorNames class:
add TYPE_X
add code for the new sensor in getSensorName, getSensorInteger, getNumSensorValues

3. if it is a new sensor in android api:
increment SensorNames.SENSOR_MAX_BIT
increment SensorSimulatorClient.MAX_SENSOR
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openintents.tools.simulator.controller.sensor.AccelerometerController;
import org.openintents.tools.simulator.controller.sensor.BarcodeReaderController;
import org.openintents.tools.simulator.controller.sensor.GravityController;
import org.openintents.tools.simulator.controller.sensor.GyroscopeController;
import org.openintents.tools.simulator.controller.sensor.LightController;
import org.openintents.tools.simulator.controller.sensor.LinearAccelerationController;
import org.openintents.tools.simulator.controller.sensor.MagneticFieldController;
Expand Down Expand Up @@ -112,9 +113,12 @@ public SensorSimulatorController(final SensorSimulatorModel model,
.getPressure()));
mSensors.add(new LinearAccelerationController(model
.getLinearAcceleration(), view.getLinearAceleration()));
mSensors.add(new GravityController(model.getGravity(), view.getGravity()));
mSensors.add(new GravityController(model.getGravity(), view
.getGravity()));
mSensors.add(new RotationVectorController(model.getRotationVector(),
view.getRotationVector()));
mSensors.add(new GyroscopeController(model.getGyroscope(), view
.getGyroscope()));

DeviceView deviceView = ((OrientationView) ((OrientationController) mSensors
.get(SensorModel.POZ_ORIENTATION)).getView()).getDeviceView();
Expand Down Expand Up @@ -194,7 +198,8 @@ private void doTimer() {
// From time to time we get the user settings:
if (currentTime >= mSensorSimulatorModel.getNextUpdate()) {
// Do update
mSensorSimulatorModel.addNextUpdate(mSensorSimulatorModel.getDuration());
mSensorSimulatorModel.addNextUpdate(mSensorSimulatorModel
.getDuration());
if (mSensorSimulatorModel.getNextUpdate() < currentTime) {
// Skip time if we are already behind:
mSensorSimulatorModel.setNextUpdate(System.currentTimeMillis());
Expand Down Expand Up @@ -248,8 +253,8 @@ public void updateSensorRefresh() {
long maxcount = mSensorSimulatorView.getRefreshCount();
if (maxcount >= 0 && updateSensorCount >= maxcount) {
long newtime = System.currentTimeMillis();
double ms = (double) (newtime - mSensorSimulatorModel.getUpdateSensorTime())
/ ((double) maxcount);
double ms = (double) (newtime - mSensorSimulatorModel
.getUpdateSensorTime()) / ((double) maxcount);
mSensorSimulatorModel.setRefreshSensors(ms);
mSensorSimulatorView.setRefreshSensorsLabel(ms);

Expand Down Expand Up @@ -297,7 +302,8 @@ public MagneticFieldController getMagneticField() {
}

public TemperatureController getTemperature() {
return (TemperatureController) mSensors.get(SensorModel.POZ_TEMPERATURE);
return (TemperatureController) mSensors
.get(SensorModel.POZ_TEMPERATURE);
}

public BarcodeReaderController getBarcodeReader() {
Expand All @@ -319,7 +325,8 @@ public AccelerometerController getAccelerometer() {
}

public OrientationController getOrientation() {
return (OrientationController) mSensors.get(SensorModel.POZ_ORIENTATION);
return (OrientationController) mSensors
.get(SensorModel.POZ_ORIENTATION);
}

public void setFix(boolean value) {
Expand All @@ -342,6 +349,7 @@ public LinearAccelerationController getLinearAcceleration() {
}

public RotationVectorController getRotationVector() {
return (RotationVectorController) mSensors.get(SensorModel.POZ_ROTATION);
return (RotationVectorController) mSensors
.get(SensorModel.POZ_ROTATION);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2008 - 2011 OpenIntents.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openintents.tools.simulator.controller.sensor;

import org.openintents.tools.simulator.Global;
import org.openintents.tools.simulator.model.sensor.sensors.OrientationModel;
import org.openintents.tools.simulator.model.sensor.sensors.GyroscopeModel;
import org.openintents.tools.simulator.model.sensor.sensors.SensorModel;
import org.openintents.tools.simulator.model.sensor.sensors.WiiAccelerometerModel;
import org.openintents.tools.simulator.view.sensor.sensors.GyroscopeView;

/**
* GyroscopeController keeps the behaviour of the Gyroscope sensor (listeners,
* etc.)
*
*
* @author ilarele
*
*/
public class GyroscopeController extends SensorController {

public GyroscopeController(GyroscopeModel model, GyroscopeView view) {
super(model, view);
}

@Override
public void updateSensorPhysics(OrientationModel orientation,
WiiAccelerometerModel realDeviceBridgeAddon, int delay) {
GyroscopeModel gyroscopeModel = (GyroscopeModel) mSensorModel;
GyroscopeView gyroscopeView = (GyroscopeView) mSensorView;
// Gyroscope
if (gyroscopeModel.isEnabled()) {
gyroscopeModel.refreshAngularSpeed(delay, orientation.getReadPitch(), orientation.getReadYaw(), orientation.getReadRoll());
// Add random component:
double random = gyroscopeView.getRandom();
if (random > 0) {
gyroscopeModel.addRandom(SensorModel.getRandom(random));
}
} else {
gyroscopeModel.setGyroscope(0, 0, 0);
}
}

@Override
public String getString() {
GyroscopeModel gyroscopeModel = (GyroscopeModel) mSensorModel;
return Global.TWO_DECIMAL_FORMAT.format(gyroscopeModel
.getReadGyroscopePitch())
+ ", "
+ Global.TWO_DECIMAL_FORMAT.format(gyroscopeModel
.getReadGyroscopeYaw())
+ ", "
+ Global.TWO_DECIMAL_FORMAT.format(gyroscopeModel
.getReadGyroscopeRoll());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openintents.tools.simulator.model.sensor.sensors.AccelerometerModel;
import org.openintents.tools.simulator.model.sensor.sensors.BarcodeReaderModel;
import org.openintents.tools.simulator.model.sensor.sensors.GravityModel;
import org.openintents.tools.simulator.model.sensor.sensors.GyroscopeModel;
import org.openintents.tools.simulator.model.sensor.sensors.LightModel;
import org.openintents.tools.simulator.model.sensor.sensors.LinearAccelerationModel;
import org.openintents.tools.simulator.model.sensor.sensors.MagneticFieldModel;
Expand Down Expand Up @@ -110,6 +111,7 @@ public SensorSimulatorModel(SensorSimulator sensorSimulator) {
mSensors.add(new LinearAccelerationModel());
mSensors.add(new GravityModel());
mSensors.add(new RotationVectorModel());
mSensors.add(new GyroscopeModel());

mSensorServer = new SensorServer(sensorSimulator);

Expand Down Expand Up @@ -243,4 +245,8 @@ public GravityModel getGravity() {
public RotationVectorModel getRotationVector() {
return (RotationVectorModel) mSensors.get(SensorModel.POZ_ROTATION);
}

public GyroscopeModel getGyroscope() {
return (GyroscopeModel) mSensors.get(SensorModel.POZ_GYROSCOPE);
}
}
Loading

0 comments on commit 0d83e62

Please sign in to comment.