forked from openintents/sensorsimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SensorSimulator: gyroscope sensor (only in server) + "howToAddASensor…
….txt" git-svn-id: https://openintents.googlecode.com/svn/trunk@3472 72b678ce-9140-0410-bee8-679b907dd61a
- Loading branch information
Showing
10 changed files
with
569 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...imulatorOO/src/org/openintents/tools/simulator/controller/sensor/GyroscopeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.