Skip to content

Commit 53e9303

Browse files
committed
Merge branch 'release/v1.0'
2 parents e8912ac + 7130962 commit 53e9303

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+990
-148
lines changed

app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId "com.fewlaps.flone"
1010
minSdkVersion 15
1111
targetSdkVersion 23
12-
versionCode 6
13-
versionName "0.5 beta"
12+
versionCode 7
13+
versionName "1.0"
1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1515
}
1616
lintOptions {
@@ -42,6 +42,7 @@ dependencies {
4242
testCompile "org.mockito:mockito-core:1.9.5"
4343
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
4444
testCompile "org.robolectric:robolectric:3.0-rc3"
45+
testCompile 'org.assertj:assertj-core:1.7.0'
4546

4647
// @see https://google.github.io/android-testing-support-library/docs/espresso
4748
// @see https://google.github.io/android-testing-support-library/downloads

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
android:screenOrientation="portrait" />
2929
<activity
3030
android:name=".view.activity.FlyActivity"
31-
android:launchMode="singleInstance"
3231
android:screenOrientation="portrait" />
3332
<activity
3433
android:name=".view.activity.CalibrationActivity"
3534
android:screenOrientation="portrait"
3635
android:theme="@style/AppTheme.NoActionBar" />
36+
<activity
37+
android:name=".view.activity.PreferenceActivity"
38+
android:screenOrientation="portrait"
39+
android:theme="@style/AppTheme.NoActionBar" />
3740

3841
<service android:name=".service.DroneService" />
3942
</application>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.fewlaps.flone;
2+
3+
/**
4+
* A tool to get the pitch and yaw the user wants to send to the drone.
5+
* <p/>
6+
* Usually, users won't want to send a 2000 or a 1000, because it's a too high value. So,
7+
* we'll have to map the input of the user to the bounds he previously set.
8+
* <p/>
9+
* A limit of 100 makes the min to be 1100 and the max to be 1900.
10+
*/
11+
public class DesiredPitchRollCalculator {
12+
13+
public static final int MID = 1500;
14+
15+
public static final int MIN_LIMIT = 0;
16+
public static final int MAX_LIMIT = 500;
17+
18+
private int limit = 0;
19+
20+
public DesiredPitchRollCalculator(int limit) {
21+
this.limit = limit;
22+
}
23+
24+
public void setLimit(int limit) {
25+
this.limit = limit;
26+
}
27+
28+
public int getValue(int value) {
29+
int absolute = getAbsolute(value);
30+
31+
int calculatedValue = map(absolute, MIN_LIMIT, MAX_LIMIT, MIN_LIMIT, MAX_LIMIT - limit);
32+
33+
if (value > MID) {
34+
return MID + calculatedValue;
35+
} else {
36+
return MID - calculatedValue;
37+
}
38+
}
39+
40+
public int getAbsolute(int value) {
41+
if (value > MID) {
42+
return value - MID;
43+
} else {
44+
int absolute = value - MID;
45+
return absolute * -1;
46+
}
47+
}
48+
49+
/**
50+
* This is the common Arduino map() function, expressed in Java
51+
* http://stackoverflow.com/questions/7505991/arduino-map-equivalent-function-in-java
52+
*/
53+
private int map(int x, int inMin, int inMax, int outMin, int outMax) {
54+
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
55+
}
56+
}

app/src/main/java/com/fewlaps/flone/DesiredYawCalculator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
/**
44
* A tool to get the yaw the user wants to send to the drone. The idea is that
55
* droneHeading and desiresHeading are values from -180 to 180.
6-
*
7-
* @author Roc Boronat (roc@fewlaps.com)
8-
* @date 05/07/2015
96
*/
107
public class DesiredYawCalculator {
118
public double getYaw(double droneHeading, double phoneHeading) {

app/src/main/java/com/fewlaps/flone/data/CalibrationDatabase.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,55 @@
44
import android.content.SharedPreferences;
55
import android.preference.PreferenceManager;
66

7+
import com.fewlaps.flone.data.bean.DroneCalibrationData;
78
import com.fewlaps.flone.data.bean.PhoneCalibrationData;
89
import com.google.gson.Gson;
910

10-
/**
11-
* @author Roc Boronat (roc@fewlaps.com)
12-
* @date 19/02/2015
13-
*/
1411
public class CalibrationDatabase {
1512

1613
private static final Gson GSON = new Gson();
1714

1815
private static final String PREF_PHONE_CALIBRATION = "prefPhoneCalibration";
16+
private static final String PREF_DRONE_CALIBRATION = "prefDroneCalibration";
1917

20-
private static PhoneCalibrationData cachedData = null;
18+
private static PhoneCalibrationData phoneCacheData = null;
19+
private static DroneCalibrationData droneCacheData = null;
2120

2221
public static PhoneCalibrationData getPhoneCalibrationData(Context context) {
23-
if (cachedData == null) {
22+
if (phoneCacheData == null) {
2423
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
2524
String value = preferences.getString(PREF_PHONE_CALIBRATION, null);
2625
if (value != null) {
27-
cachedData = GSON.fromJson(value, PhoneCalibrationData.class);
26+
phoneCacheData = GSON.fromJson(value, PhoneCalibrationData.class);
2827
} else {
29-
cachedData = new PhoneCalibrationData();
28+
phoneCacheData = new PhoneCalibrationData();
3029
}
3130
}
32-
return cachedData;
31+
return phoneCacheData;
3332
}
3433

3534
public static void setPhoneCalibrationData(Context context, PhoneCalibrationData data) {
3635
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
3736
preferences.edit().putString(PREF_PHONE_CALIBRATION, GSON.toJson(data)).commit();
38-
cachedData = data;
37+
phoneCacheData = data;
38+
}
39+
40+
public static DroneCalibrationData getDroneCalibrationData(Context context, String droneNickName) {
41+
if (droneCacheData == null) {
42+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
43+
String value = preferences.getString(PREF_DRONE_CALIBRATION + droneNickName, null);
44+
if (value != null) {
45+
droneCacheData = GSON.fromJson(value, DroneCalibrationData.class);
46+
} else {
47+
droneCacheData = new DroneCalibrationData();
48+
}
49+
}
50+
return droneCacheData;
51+
}
52+
53+
public static void setDroneCalibrationData(Context context, String droneNickName, DroneCalibrationData data) {
54+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
55+
preferences.edit().putString(PREF_DRONE_CALIBRATION + droneNickName, GSON.toJson(data)).commit();
56+
droneCacheData = data;
3957
}
4058
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.fewlaps.flone.data;
2+
3+
public class DefaultValues {
4+
5+
public static final double DEFAULT_PHONE_PITCH_ROLL = 100;
6+
7+
public static final int DEFAULT_PITCH_ROLL_LIMIT = 300; //low = expert, high = beginner, min = 0, max = 500
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.fewlaps.flone.data.bean;
2+
3+
public class DroneCalibrationData {
4+
5+
private double headingDifference = 0;
6+
7+
public double getHeadingDifference() {
8+
return headingDifference;
9+
}
10+
11+
public void setHeadingDifference(double headingDifference) {
12+
this.headingDifference = headingDifference;
13+
}
14+
}
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package com.fewlaps.flone.data.bean;
22

3-
/**
4-
* @author Roc Boronat (roc@fewlaps.com)
5-
* @date 26/05/2015
6-
*/
3+
import com.fewlaps.flone.data.DefaultValues;
4+
75
public class PhoneCalibrationData {
8-
public Double minPitch;
9-
public Double maxPitch;
10-
public Double minRoll;
11-
public Double maxRoll;
6+
7+
private Double minPitch = DefaultValues.DEFAULT_PHONE_PITCH_ROLL * -1;
8+
private Double maxPitch = DefaultValues.DEFAULT_PHONE_PITCH_ROLL;
9+
private Double minRoll = DefaultValues.DEFAULT_PHONE_PITCH_ROLL * -1;
10+
private Double maxRoll = DefaultValues.DEFAULT_PHONE_PITCH_ROLL;
11+
12+
private int limit = DefaultValues.DEFAULT_PITCH_ROLL_LIMIT;
1213

1314
public PhoneCalibrationData() {
14-
minPitch = -50d;
15-
maxPitch = 50d;
16-
minRoll = -50d;
17-
maxRoll = 50d;
15+
1816
}
1917

2018
public double getAverageMaxPitch() {
@@ -24,4 +22,12 @@ public double getAverageMaxPitch() {
2422
public double getAverageMaxRoll() {
2523
return ((minRoll * -1) + maxRoll) / 2;
2624
}
25+
26+
public int getLimit() {
27+
return limit;
28+
}
29+
30+
public void setLimit(int limit) {
31+
this.limit = limit;
32+
}
2733
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.fewlaps.flone.io.bean;
2+
3+
public class CalibrateDroneAccelerometerRequest {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.fewlaps.flone.io.bean;
2+
3+
public class CalibrateDroneMagnetometerRequest {
4+
5+
}

0 commit comments

Comments
 (0)