Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch barometer #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.android.tools.build:gradle:4.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
Expand All @@ -19,13 +19,14 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
google()
maven { url "https://jitpack.io" }
}
project.ext {
myApplicationID="com.pulce.wristglider"
myVersionCode=26
myVersionNumber="0.4.7"
myVersionCode=29
myVersionNumber="0.4.8"
myMinSdkVersion=21
myWearMinSdkVersion=23
myTargetSdkVersion=28
Expand Down
20 changes: 18 additions & 2 deletions commonclasses/src/main/java/com/pulce/commonclasses/Statics.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ public class Statics {

public static final int MY_NULL_VALUE = -999999;

public static final float MY_LPF_ALPHA = 0.25f;

public static final double KF_PRESSURE_VAR_ACCEL = 0.0075; // Variance of pressure acceleration noise input.
public static final double KF_PRESSURE_VAR_MEASUREMENT = 0.05; // Variance of pressure measurement noise.
public static final double KF_ALT_VAR_ACCEL = 0.01; // Variance of altitude acceleration noise input.
public static final double KF_ALT_VAR_MEASUREMENT = 0.005; // Variance of altitude measurement noise.

public static final int MY_BEEP_DURATION = 200;
public static final int MY_BEEP_DURATION_COEF = 70;
public static final int MY_UP_MAX_VARIO_THRESHOLD = 10;
public static final int MY_INITIAL_FREQ_UP = 1200;
public static final int MY_FREQ_COEF = 100;
public static final int MY_FREQ_DOWN = 800;

private static final DecimalFormat latForm = new DecimalFormat("0000000");
private static final DecimalFormat lonForm = new DecimalFormat("00000000");

Expand All @@ -43,10 +57,12 @@ public class Statics {
public static final String PREFSCREENON = "/com/pulce/wristglider/prefscreenon";
public static final String PREFHEIGTHUNIT = "/com/pulce/wristglider/prefheightunit";
public static final String PREFSPEEDUNIT = "/com/pulce/wristglider/prefspeedunit";
public static final String PREFVARIOUNIT = "/com/pulce/wristglider/prefvariounit";
public static final String PREFUSEBTVARIO = "/com/pulce/wristglider/prefusebtvario";
public static final String PREFBTVARIOUNIT = "/com/pulce/wristglider/prefbtvariounit";
public static final String PREFBTVARIODEVICE = "/com/pulce/wristglider/prefbtvariodevice";

public static final String PREFVARIOBEEPER = "/com/pulce/wristglider/prefvariobeeper";
public static final String PREFVARIOBEEPERDOWN = "/com/pulce/wristglider/prefvariobeeperdown";
public static final String PREFVARIOBEEPERUP = "/com/pulce/wristglider/prefvariobeeperup";

public static String getUTCdateReverse() {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
48 changes: 43 additions & 5 deletions mobile/src/main/java/com/pulce/wristglider/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.support.v4.content.ContextCompat;
import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
Expand All @@ -25,6 +26,7 @@
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
Expand Down Expand Up @@ -101,7 +103,10 @@ protected void onCreate(Bundle savedInstanceState) {
addTableRow(getString(R.string.height_unit), Statics.PREFHEIGTHUNIT);
addTableRow(getString(R.string.speed_unit), Statics.PREFSPEEDUNIT);
addTableRow(getString(R.string.use_bt_vario), Statics.PREFUSEBTVARIO);
addTableRow(getString(R.string.vario_unit), Statics.PREFBTVARIOUNIT);
addTableRow(getString(R.string.vario_unit), Statics.PREFVARIOUNIT);
addTableRow(getString(R.string.vario_beeper), Statics.PREFVARIOBEEPER);
addTableRow(getString(R.string.vario_beeper_up), Statics.PREFVARIOBEEPERUP);
addTableRow(getString(R.string.vario_beeper_down), Statics.PREFVARIOBEEPERDOWN);

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
Expand Down Expand Up @@ -316,7 +321,10 @@ private void updatePreferences() {
dataMap.getDataMap().putString(Statics.PREFHEIGTHUNIT, prefs.getString(Statics.PREFHEIGTHUNIT, "m"));
dataMap.getDataMap().putString(Statics.PREFROTATEDEGREES, prefs.getString(Statics.PREFROTATEDEGREES, "0"));
dataMap.getDataMap().putBoolean(Statics.PREFUSEBTVARIO, prefs.getBoolean(Statics.PREFUSEBTVARIO, false));
dataMap.getDataMap().putString(Statics.PREFBTVARIOUNIT, prefs.getString(Statics.PREFBTVARIOUNIT, "m/s"));
dataMap.getDataMap().putString(Statics.PREFVARIOUNIT, prefs.getString(Statics.PREFVARIOUNIT, "m/s"));
dataMap.getDataMap().putBoolean(Statics.PREFVARIOBEEPER, prefs.getBoolean(Statics.PREFVARIOBEEPER, false));
dataMap.getDataMap().putFloat(Statics.PREFVARIOBEEPERUP, prefs.getFloat(Statics.PREFVARIOBEEPERUP, 0));
dataMap.getDataMap().putFloat(Statics.PREFVARIOBEEPERDOWN, prefs.getFloat(Statics.PREFVARIOBEEPERDOWN, -2));
PutDataRequest request = dataMap.asPutDataRequest();
request.setUrgent();
Wearable.DataApi.putDataItem(mGoogleApiClient, request);
Expand Down Expand Up @@ -486,6 +494,7 @@ public void onNothingSelected(AdapterView<?> parent) {
case Statics.PREFLOGGERAUTO:
case Statics.PREFSCREENON:
case Statics.PREFUSEBTVARIO:
case Statics.PREFVARIOBEEPER:
final CheckBox cp2 = new CheckBox(this);
cp2.setChecked(prefs.getBoolean(preferencekey, false));
cp2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
Expand All @@ -500,7 +509,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
break;
case Statics.PREFHEIGTHUNIT:
case Statics.PREFSPEEDUNIT:
case Statics.PREFBTVARIOUNIT:
case Statics.PREFVARIOUNIT:
case Statics.PREFLOGGERSECONDS:
case Statics.PREFROTATEDEGREES:
final Spinner spinner2 = new Spinner(this);
Expand All @@ -521,7 +530,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
spinner2Array.add("mph");
spinner2Array.add("kn");
break;
case Statics.PREFBTVARIOUNIT:
case Statics.PREFVARIOUNIT:
spinner2Array.add("m/s");
spinner2Array.add("kn");
break;
Expand Down Expand Up @@ -563,6 +572,34 @@ public void onNothingSelected(AdapterView<?> parent) {
});
tr.addView(spinner2);
break;
case Statics.PREFVARIOBEEPERUP:
case Statics.PREFVARIOBEEPERDOWN:
final LinearLayout sbl = new LinearLayout(this);
final TextView tv = new TextView(this);
final SeekBar sb = new SeekBar(this);
sb.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
sb.setMax(100); // -50 to 50
sb.setProgress((int) (50 + prefs.getFloat(preferencekey, 0) * 10)); // float to int with shift (ex. 1,5 as 65) )
tv.setText(String.format("%.1f", (sb.getProgress() - 50) / 10.f)); // int to float with shift (ex. 65 as 1,5)
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int pval = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
pval = progress;
tv.setText(String.format("%.1f", (progress - 50) / 10.f)); // int to float with shift (ex. 65 as 1,5)
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
prefs.edit().putFloat(preferencekey, (pval - 50) / 10.f).apply(); // int to float with shift (ex. 65 as 1,5)
updatePreferences();
}
});
sbl.addView(tv);
sbl.addView(sb);
tr.addView(sbl);
break;
default:
tr.setClickable(true);
final TextView tv2 = (TextView) getLayoutInflater().inflate(R.layout.standard_textview, tr, false);
Expand Down Expand Up @@ -617,7 +654,8 @@ public void onClick(DialogInterface dialog, int which) {
});
break;
}
tablelayout.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
tr.setGravity(Gravity.CENTER_VERTICAL);
tablelayout.addView(tr);
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions mobile/src/main/res/layout/spinner_item_two_boxes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_twoline_text_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="20px"
android:paddingBottom="20px"
android:paddingStart="15px"
android:paddingEnd="15px"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:maxLines="2"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
/>
Expand Down
8 changes: 4 additions & 4 deletions mobile/src/main/res/layout/standard_textview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
android:id="@+id/standard_text_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="20px"
android:paddingBottom="20px"
android:paddingStart="15px"
android:paddingEnd="15px"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
/>
3 changes: 3 additions & 0 deletions mobile/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
<string name="bt_failed_user">Bluetooth Verbindung von Benutzer getrennt</string>
<string name="vario_unit">Einheit Vario</string>
<string name="new_glider_fail_no_type">Fluggerät Typ muss angegeben werden</string>
<string name="vario_beeper">Vario piepser</string>
<string name="vario_beeper_down">Senkenschwelle</string>
<string name="vario_beeper_up">Hubschwelle</string>
</resources>
3 changes: 3 additions & 0 deletions mobile/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
<string name="bt_failed_user">Połączenie Bluetooth anulowane przez użytkownika</string>
<string name="vario_unit">Wariometr</string>
<string name="new_glider_fail_no_type">Typ paralotni nie może być pusty.</string>
<string name="vario_beeper">Dźwięk vario</string>
<string name="vario_beeper_up">Wznoszenie od</string>
<string name="vario_beeper_down">Opadanie od</string>
</resources>
3 changes: 3 additions & 0 deletions mobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
<string name="bt_failed_no_device">Bluetooth Vario device not found</string>
<string name="bt_failed_user">Bluetooth connection canceled by the user</string>
<string name="vario_unit">Vario unit</string>
<string name="vario_beeper">Vario beeper</string>
<string name="vario_beeper_up">Lift threshold</string>
<string name="vario_beeper_down">Sink threshold</string>
<string name="new_glider_fail_no_type">Glider type cannot be empty.</string>
</resources>
2 changes: 1 addition & 1 deletion wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion project.myCompileSdkVersion.toInteger()
publishNonDefault true

defaultConfig {
applicationId project.ext.myApplicationID
Expand Down Expand Up @@ -48,5 +47,6 @@ dependencies {
compileOnly 'com.google.android.wearable:wearable:2.4.0'
implementation 'com.google.firebase:firebase-appindexing:11.6.2'
implementation 'com.google.android.gms:play-services-location:11.6.2'
implementation 'com.github.karlotoy:perfectTune:1.0.2'
implementation project(':commonclasses')
}
59 changes: 59 additions & 0 deletions wear/src/main/java/com/pulce/wristglider/Beeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.pulce.wristglider;

import com.karlotoy.perfectune.instance.PerfectTune;
import com.pulce.commonclasses.Statics;

public class Beeper {

private PerfectTune tone;
private long lastTime;
private static int BeepDuration = Statics.MY_BEEP_DURATION;
private static int BeepDurationCoef = Statics.MY_BEEP_DURATION_COEF;
private static int UpMaxVarioThreshold = Statics.MY_UP_MAX_VARIO_THRESHOLD;
private static int InitialFreqUp = Statics.MY_INITIAL_FREQ_UP;
private static int FreqCoef = Statics.MY_FREQ_COEF;
private static int FreqDown = Statics.MY_FREQ_DOWN;
private boolean playFlag = true;

private float upVarioThreshold = 0;
private float downVarioThreshold = -2;

Beeper(float varioThresholdUp, float varioThresholdDown) {
tone = new PerfectTune();
lastTime = System.currentTimeMillis();
setThresholds(varioThresholdUp, varioThresholdDown);
}

public void setThresholds(float varioThresholdUp, float varioThresholdDown) {
upVarioThreshold = varioThresholdUp;
downVarioThreshold = varioThresholdDown;
}

public void beep(float vario) {
float duration = (BeepDuration - vario * BeepDurationCoef >= 25) ? BeepDuration - vario * BeepDurationCoef : 25;
if (System.currentTimeMillis() - lastTime > duration && !playFlag) {
playFlag = !playFlag;
tone.stopTune();
}
if (vario > UpMaxVarioThreshold) vario = UpMaxVarioThreshold; // cut-off to max UpMaxVarioThreshold (default 10m/s)

if (vario > upVarioThreshold) {
duration = duration * 3;
if (playFlag && ((System.currentTimeMillis() - lastTime) > duration)) {
lastTime = System.currentTimeMillis();
tone.setTuneFreq(InitialFreqUp + vario * FreqCoef);
tone.playTune();
playFlag = !playFlag;
}
} else if (vario < downVarioThreshold) {
tone.setTuneFreq(FreqDown);
tone.playTune();
} else {
tone.stopTune();
}
}

public void stop() {
tone.stopTune();
}
}
Loading