boolean result = false;
try {
String str = "sensor\n\n\n\n";
+ if(output != null)
+ output.flush();
+ else
+ return false;
+
output.write(str.getBytes(), 0, str.length());
output.flush();
Button checkboxAccelerometer;
Button checkboxGyro;
Button checkboxGeoMagnetic;
+ Button checkboxOrientation;
private Text dataText;
Timer dataOutputTimer;
static String magneticData;
static String gyroData;
+ static boolean orientation_active = true;
static boolean button_click = false;
public Accelerometer(AbstractInjectorItem item, String name) {
dataOutputTimer.stop();
else if( checkboxGeoMagnetic.getSelection()) {
magneticData = "magnetic filed : " + mf.format(magnetic.getReadCompassX()) +
- ", " + mf.format(magnetic.getReadCompassY()) + ", " + mf.format(magnetic.getReadCompassZ());
+ ", " + mf.format(magnetic.getReadCompassY()) + ", " + mf.format(magnetic.getReadCompassZ()) + "\n" + "orientation : " + mf.format(magnetic.getAzimuth()) +
+ ", " + mf.format(magnetic.getPitch()) + ", " + mf.format(magnetic.getRoll());
}
else {
magneticData = "magnetic : Disable";
formUtil.createLabel(sliderComposite, "Pitch");
pitchSlider = formUtil.createSlider(sliderComposite);
setDefaultSlider(pitchSlider);
+ pitchValue = (int) panel.pitchDegree;
pitchSlider.setSelection((int) panel.pitchDegree + 180);
pitchSlider.addSelectionListener(new SelectionAdapter() {
@Override
formUtil.createLabel(sliderComposite, "Roll");
rollSlider = formUtil.createSlider(sliderComposite);
setDefaultSlider(rollSlider);
+ rollValue = (int) panel.rollDegree;
rollSlider.setSelection((int) panel.rollDegree + 180);
rollSlider.addSelectionListener(new SelectionAdapter() {
@Override
formUtil.createLabel(sliderComposite, "Yaw");
yawSlider = formUtil.createSlider(sliderComposite);
setDefaultSlider(yawSlider);
+ yawValue = (int) panel.yawDegree;
yawSlider.setSelection((int) panel.yawDegree + 180);
yawSlider.addSelectionListener(new SelectionAdapter() {
@Override
checkboxAccelerometer = formUtil.createButton(checkboxComposite, "Accelerometer sensor", SWT.CHECK);
checkboxGeoMagnetic = formUtil.createButton(checkboxComposite, "Geomagnetic sensor", SWT.CHECK);
checkboxGyro = formUtil.createButton(checkboxComposite, "Gyroscope sensor", SWT.CHECK);
+ checkboxOrientation = formUtil.createButton(checkboxComposite, "Orientation sensor", SWT.CHECK);
checkboxAccelerometer.setSelection(true);
checkboxGeoMagnetic.setSelection(true);
checkboxGyro.setSelection(true);
+ checkboxOrientation.setSelection(true);
checkboxAccelerometer.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
panel.accelerometerTimer(checkboxAccelerometer.getSelection());
+ if(!checkboxAccelerometer.getSelection())
+ {
+ checkboxOrientation.setSelection(false);
+ orientation_active = false;
+ }
super.widgetSelected(e);
}
checkboxGeoMagnetic.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
panel.geomagneticTimer(checkboxGeoMagnetic.getSelection());
+ if(!checkboxGeoMagnetic.getSelection())
+ {
+ checkboxOrientation.setSelection(false);
+ orientation_active = false;
+ }
super.widgetSelected(e);
}
});
super.widgetSelected(e);
}
});
+ checkboxOrientation.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if(checkboxOrientation.getSelection())
+ {
+ checkboxAccelerometer.setSelection(true);
+ panel.accelerometerTimer(checkboxAccelerometer.getSelection());
+ checkboxGeoMagnetic.setSelection(true);
+ panel.geomagneticTimer(checkboxGeoMagnetic.getSelection());
+ orientation_active = true;
+ }
+ else
+ orientation_active = false;
+ super.widgetSelected(e);
+ }
+ });
//panel.ConnectionChanged();
boolean connected = checkDeviceConnectedAlready();
private Timer timer;
private Timer geomagneticTimer;
private Timer gyroTimer;
+ private Timer orientationTimer;
private boolean connected = false;
public MobilePanel(Accelerometer page) {
magnetic.updateSensorPhysics(rollDegree, pitchDegree, yawDegree);
magnetic.updateSensorReadoutValues();
magnetic.updateUserSettings();
- //magnetic.setAzimuth();
+ if(Accelerometer.orientation_active)
+ magnetic.setOrient(read_accelx, read_accely, read_accelz);
- /* orientation logic via accelerometer value */
- int orient_yaw, orient_pitch, orient_roll;
- orient_yaw = (int)(Math.round(Math.atan2(-read_accelx, -read_accely) * (180.0/3.14) + 360) % 360);
- orient_pitch = (int)(Math.atan2(-read_accely, -read_accelz) * (180.0/3.14)) % 180;
- orient_roll = (int)(Math.atan2(read_accelx, read_accelz) * (180.0/3.14)) % 180;
-
- if(orient_roll > 90)
- orient_roll = 180 - orient_roll;
- else if(orient_roll < -90)
- orient_roll = -180 - orient_roll;
-
- mPage.sendMessage(Magnetic.sensorNumber, orient_yaw, -orient_pitch, orient_roll , 4, magnetic.getReadCompassX(), magnetic.getReadCompassY(), magnetic.getReadCompassZ());
- //mPage.sendMessage(Magnetic.sensorNumber, magnetic.getAzimuth(), 0, 0 , 4, magnetic.getReadCompassX(), magnetic.getReadCompassY(), magnetic.getReadCompassZ());
- //System.out.println("geomagnetic : X " + magnetic.getReadCompassX() + " Y : " + magnetic.getReadCompassY() + " Z : " + magnetic.getReadCompassZ());
+ mPage.sendMessage(Magnetic.sensorNumber, magnetic.getAzimuth(), magnetic.getPitch(), magnetic.getRoll() , 4, magnetic.getReadCompassX(), magnetic.getReadCompassY(), magnetic.getReadCompassZ());
}
});
gyroTimer = new Timer(delay, new ActionListener(){
}
}
}
+ public void orientationTimer(boolean checked){
+ if( orientationTimer != null){
+ if( checked == true && connected == true){
+ orientationTimer.start();
+ }
+ if( checked == false){
+ orientationTimer.stop();
+ }
+ }
+ }
public void setGyroAxisX(double[] axis) {
gyro_axisX = axis.clone();
}
private double compassx;
private double compassy;
private double compassz;
- private double azimuth;
+ private int azimuth = 0;
+ private int pitch = -90;
+ private int roll = 0;
// private double magneticnorth = 22874.1;
// private double magneticeast = 5939.5;
// private double magneticvertical = 43180.5;
compassx = vec.x;
compassy = vec.y;
compassz = vec.z;
-
}
- public void setAzimuth(){
- if( read_compassx == 0 && read_compassy < 0){
- azimuth = 90;
- }
- else if( read_compassx == 0 && read_compassy > 0){
- azimuth = 270;
- }
- else if( read_compassx < 0) {
- azimuth = 180 - (Math.atan(read_compassy/read_compassx)) * 180/Math.PI;
- }
- else if( read_compassx > 0 && read_compassy < 0 ) {
- azimuth = -(Math.atan(read_compassy/read_compassx))*180/Math.PI;
- }
- else if( read_compassx > 0 && read_compassy >=0 ){
- azimuth = 360 - Math.atan(read_compassy/read_compassx) * 180/Math.PI;
- }
+
+ public void setOrient(double x, double y, double z){
+ /* orientation logic via accelerometer value */
+ int orient_yaw, orient_pitch, orient_roll;
+ orient_yaw = (int)(Math.round(Math.atan2(-x, -y) * (180.0/3.14) + 360) % 360);
+ orient_pitch = (int)(Math.atan2(-y, -z) * (180.0/3.14)) % 180;
+ orient_roll = (int)(Math.atan2(x, z) * (180.0/3.14)) % 180;
+
+ if(orient_roll > 90)
+ orient_roll = 180 - orient_roll;
+ else if(orient_roll < -90)
+ orient_roll = -180 - orient_roll;
+
+ azimuth = orient_yaw;
+ pitch = -orient_pitch;
+ roll = orient_roll;
}
- public double getAzimuth(){
+ public int getAzimuth(){
return azimuth;
}
-
+ public int getPitch(){
+ return pitch;
+ }
+ public int getRoll(){
+ return roll;
+ }
public void updateSensorReadoutValues() {
long currentTime = System.currentTimeMillis();
if (average_compass) {