Skip to content

Commit

Permalink
Merge pull request #111 from sky-map-team/reverseaxisoption
Browse files Browse the repository at this point in the history
Add an option to reverse the magnetic z direction
  • Loading branch information
jaydeetay committed May 21, 2016
2 parents 3337a32 + 43d5e4e commit c660732
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.google.android.stardroid"
minSdkVersion 15
targetSdkVersion 23
versionCode 1427
versionName "1.8.4.1"
versionCode 1428
versionName "1.8.5 - alpha1"
buildConfigField 'String', 'GOOGLE_ANALYTICS_CODE', '""'
}
signingConfigs {
Expand Down
Binary file modified app/src/main/assets/constellations.binary
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.android.stardroid.util.smoothers.PlainSmootherModelAdaptor;

import javax.inject.Inject;
import javax.inject.Provider;

/**
* Sets the direction of view from the orientation sensors.
Expand Down Expand Up @@ -81,22 +82,24 @@ public SensorDampingSettings(float damping, int exponent) {
private SensorManager manager;
private SensorListener accelerometerSmoother;
private SensorListener compassSmoother;
private PlainSmootherModelAdaptor modelAdaptor;
private Provider<PlainSmootherModelAdaptor> modelAdaptorProvider;
private SensorAccuracyReporter accuracyReporter;

private SharedPreferences sharedPreferences;

@Inject
SensorOrientationController(Context context, SensorAccuracyReporter accuracyReporter) {
SensorOrientationController(Context context, SensorAccuracyReporter accuracyReporter,
Provider<PlainSmootherModelAdaptor> modelAdaptorProvider) {
manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
this.accuracyReporter = accuracyReporter;
this.modelAdaptorProvider = modelAdaptorProvider;
}

@Override
public void start() {
modelAdaptor = new PlainSmootherModelAdaptor(model);
PlainSmootherModelAdaptor modelAdaptor = modelAdaptorProvider.get();

Log.d(TAG, "Exponentially weighted smoothers used");
String dampingPreference = sharedPreferences.getString(SENSOR_DAMPING_PREF_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@

package com.google.android.stardroid.util.smoothers;

import android.content.SharedPreferences;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.util.Log;

import com.google.android.stardroid.ApplicationConstants;
import com.google.android.stardroid.control.AstronomerModel;
import com.google.android.stardroid.units.Vector3;
import com.google.android.stardroid.util.MiscUtil;

import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.util.Log;
import javax.inject.Inject;

/**
* Adapts sensor output for use with the astronomer model.
Expand All @@ -30,12 +33,16 @@
*/
public class PlainSmootherModelAdaptor implements SensorListener {
private static final String TAG = MiscUtil.getTag(PlainSmootherModelAdaptor.class);
private static final String REVERSE_MAGNETIC_Z_PREFKEY = "reverse_magnetic_z";
private Vector3 magneticValues = ApplicationConstants.INITIAL_SOUTH.copy();
private Vector3 acceleration = ApplicationConstants.INITIAL_DOWN.copy();
private AstronomerModel model;
private boolean reverseMagneticZaxis;

public PlainSmootherModelAdaptor(AstronomerModel model) {
@Inject
PlainSmootherModelAdaptor(AstronomerModel model, SharedPreferences sharedPreferences) {
this.model = model;
reverseMagneticZaxis = sharedPreferences.getBoolean(REVERSE_MAGNETIC_Z_PREFKEY, false);
}

@Override
Expand All @@ -48,9 +55,11 @@ public void onSensorChanged(int sensor, float[] values) {
magneticValues.x = values[0];
magneticValues.y = values[1];
// The z direction for the mag magneticField sensor is in the opposite
// direction to that for accelerometer.
// TODO(johntaylor): this might not be the best place to reverse this.
magneticValues.z = -values[2];
// direction to that for accelerometer, except on some phones that are doing it wrong.
// Yes that's right, the right thing to do is to invert it. So if we reverse that,
// we don't invert it. Got it?
// TODO(johntaylor): this might not be the best place to do this.
magneticValues.z = reverseMagneticZaxis ? values[2] : -values[2];
} else {
Log.e(TAG, "Pump is receiving values that aren't accel or magnetic");
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,6 @@
<string name="compass_calibration_activity_heading_compass">Compass -</string>
<string name="compass_calibration_activity_do_not_show_this_again">Do not show this again</string>
<string name="compass_calibration_activity_warning">Your compass needs to be calibrated</string>
<string name="sensor_reverse_preference_title">Reverse Magnetic Z</string>
<string name="sensor_reverse_preference_summary">Fix for phones with incorrectly implemented sensors - requires restart</string>
</resources>
7 changes: 1 addition & 6 deletions app/src/main/res/values/whatsnew.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
<string name="whats_new_text" translation_description="Description of new features in this version in html">
<![CDATA[
<h1>New in version %s</h1>
\t • The Mercury transit and two new solar eclipses in time travel mode <br/>
\t • Made the planet motion in time travel smoother <br/>
\t • Two new images in the gallery <br/>
\t • Compass calibration assistance <br/>
\t • Internal efficiency improvements to search (credit: tricao) <br/>
\t • A new basic diagnostics page for debugging.
\t • Added option to reverse the magnetic sensor for the small number of phones (e.g. some OnePlusOnes) that have incorrectly implemented the sensor API <br/>
]]>
</string>
</resources>
9 changes: 5 additions & 4 deletions app/src/main/res/xml/preference_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="stardroid.preferences">
<PreferenceCategory android:title="@string/provider_prefs">
<!-- TODO(johntaylor): restore this once it's toggling properly CheckBoxPreference
android:key="show_sky_gradient"
android:defaultValue="true"
android:title="@string/show_sky_gradient" /-->
<CheckBoxPreference
android:key="source_provider.0"
android:defaultValue="true"
Expand Down Expand Up @@ -96,6 +92,11 @@
android:entryValues="@array/sensor_damping_values"
android:entries="@array/sensor_damping"
android:defaultValue="EXTRA HIGH" />
<CheckBoxPreference
android:defaultValue="false"
android:title="@string/sensor_reverse_preference_title"
android:summary="@string/sensor_reverse_preference_summary"
android:key="reverse_magnetic_z"/>
</PreferenceCategory>
</PreferenceScreen>
<CheckBoxPreference
Expand Down
32 changes: 16 additions & 16 deletions tools/data/constellations.ascii
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ source {
declination: -1.87
}
color: 2160688306
string_index: 2131165705
string_index: 2131165707
}
line {
color: 2160688306
Expand All @@ -647,7 +647,7 @@ source {
declination: -0.37
}
}
name_ids: 2131165705
name_ids: 2131165707
}
source {
search_location {
Expand Down Expand Up @@ -690,7 +690,7 @@ source {
declination: 32.34
}
color: 2160688306
string_index: 2131165708
string_index: 2131165710
}
line {
color: 2160688306
Expand All @@ -711,7 +711,7 @@ source {
declination: 29.5833
}
}
name_ids: 2131165708
name_ids: 2131165710
}
source {
search_location {
Expand Down Expand Up @@ -3986,7 +3986,7 @@ source {
declination: 25.03
}
color: 2160688306
string_index: 2131165711
string_index: 2131165713
}
line {
color: 2160688306
Expand Down Expand Up @@ -4038,7 +4038,7 @@ source {
declination: 37.75
}
}
name_ids: 2131165711
name_ids: 2131165713
}
source {
search_location {
Expand Down Expand Up @@ -4288,7 +4288,7 @@ source {
declination: -65.9
}
color: 2160688306
string_index: 2131165709
string_index: 2131165711
}
line {
color: 2160688306
Expand Down Expand Up @@ -4321,7 +4321,7 @@ source {
declination: -69.1333
}
}
name_ids: 2131165709
name_ids: 2131165711
}
source {
search_location {
Expand Down Expand Up @@ -4615,7 +4615,7 @@ source {
declination: -51.54
}
color: 2160688306
string_index: 2131165706
string_index: 2131165708
}
line {
color: 2160688306
Expand Down Expand Up @@ -4701,7 +4701,7 @@ source {
declination: -64.7333
}
}
name_ids: 2131165706
name_ids: 2131165708
}
source {
search_location {
Expand Down Expand Up @@ -4777,7 +4777,7 @@ source {
declination: -69.39
}
color: 2160688306
string_index: 2131165710
string_index: 2131165712
}
line {
color: 2160688306
Expand All @@ -4802,7 +4802,7 @@ source {
declination: -62.4667
}
}
name_ids: 2131165710
name_ids: 2131165712
}
source {
search_location {
Expand Down Expand Up @@ -5164,7 +5164,7 @@ source {
declination: -13.52
}
color: 2160688306
string_index: 2131165704
string_index: 2131165706
}
line {
color: 2160688306
Expand Down Expand Up @@ -5274,7 +5274,7 @@ source {
declination: -23.75
}
}
name_ids: 2131165704
name_ids: 2131165706
}
source {
search_location {
Expand Down Expand Up @@ -5381,7 +5381,7 @@ source {
declination: 10.85
}
color: 2160688306
string_index: 2131165703
string_index: 2131165705
}
line {
color: 2160688306
Expand Down Expand Up @@ -5429,7 +5429,7 @@ source {
declination: -70.3833
}
}
name_ids: 2131165703
name_ids: 2131165705
}
source {
search_location {
Expand Down

0 comments on commit c660732

Please sign in to comment.