Skip to content
Snippets Groups Projects
Commit 49b79703 authored by boqiren's avatar boqiren
Browse files

add smartphone acceleration

parent e5c32ad3
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ buildscript { ...@@ -10,7 +10,7 @@ buildscript {
} }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
......
#Wed Nov 28 11:04:23 CET 2018 #Fri May 10 15:21:13 CEST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
...@@ -439,6 +439,7 @@ public class MainActivity extends AppCompatActivity implements ...@@ -439,6 +439,7 @@ public class MainActivity extends AppCompatActivity implements
final CheckBox sendUpdates = findViewById(R.id.checkBox_send_brightness); final CheckBox sendUpdates = findViewById(R.id.checkBox_send_brightness);
final CheckBox sendUpdatesRotation = findViewById(R.id.checkBox_send_rotation_ahrs); final CheckBox sendUpdatesRotation = findViewById(R.id.checkBox_send_rotation_ahrs);
final CheckBox sendUpdatesRotationQuat = findViewById(R.id.checkBox_send_rotation_quaternion); final CheckBox sendUpdatesRotationQuat = findViewById(R.id.checkBox_send_rotation_quaternion);
final CheckBox sendUpdatesAcceleration = findViewById(R.id.checkBox_send_acceleration);
final CheckBox sendUpdatesWearBrightness = findViewById(R.id.checkBox_send_wear_brightness); final CheckBox sendUpdatesWearBrightness = findViewById(R.id.checkBox_send_wear_brightness);
final CheckBox sendUpdatesWearAcc= findViewById(R.id.checkBox_send_wear_acceleration); final CheckBox sendUpdatesWearAcc= findViewById(R.id.checkBox_send_wear_acceleration);
...@@ -450,6 +451,7 @@ public class MainActivity extends AppCompatActivity implements ...@@ -450,6 +451,7 @@ public class MainActivity extends AppCompatActivity implements
sendMqttUpdates.put(phoneTopics.mqtt_topic_brightness, sendUpdates.isChecked()); sendMqttUpdates.put(phoneTopics.mqtt_topic_brightness, sendUpdates.isChecked());
sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation_ahrs, sendUpdatesRotation.isChecked()); sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation_ahrs, sendUpdatesRotation.isChecked());
sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked()); sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked());
sendMqttUpdates.put(phoneTopics.mqtt_topic_acceleration, sendUpdatesAcceleration.isChecked());
sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked()); sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked());
sendMqttUpdates.put(wearTopics.mqtt_topic_acceleration, sendUpdatesWearAcc.isChecked()); sendMqttUpdates.put(wearTopics.mqtt_topic_acceleration, sendUpdatesWearAcc.isChecked());
...@@ -471,6 +473,9 @@ public class MainActivity extends AppCompatActivity implements ...@@ -471,6 +473,9 @@ public class MainActivity extends AppCompatActivity implements
sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked()); sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked());
break; break;
//test wear //test wear
case R.id.checkBox_send_acceleration:
sendMqttUpdates.put(phoneTopics.mqtt_topic_acceleration, sendUpdatesAcceleration.isChecked());
break;
case R.id.checkBox_send_wear_brightness: case R.id.checkBox_send_wear_brightness:
sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked()); sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked());
break; break;
...@@ -495,6 +500,7 @@ public class MainActivity extends AppCompatActivity implements ...@@ -495,6 +500,7 @@ public class MainActivity extends AppCompatActivity implements
sendUpdates.setOnCheckedChangeListener(onCheckedChangeListener); sendUpdates.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesRotation.setOnCheckedChangeListener(onCheckedChangeListener); sendUpdatesRotation.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesRotationQuat.setOnCheckedChangeListener(onCheckedChangeListener); sendUpdatesRotationQuat.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesAcceleration.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesWearBrightness.setOnCheckedChangeListener(onCheckedChangeListener); sendUpdatesWearBrightness.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesWearAcc.setOnCheckedChangeListener(onCheckedChangeListener); sendUpdatesWearAcc.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesWearRotation.setOnCheckedChangeListener(onCheckedChangeListener); sendUpdatesWearRotation.setOnCheckedChangeListener(onCheckedChangeListener);
...@@ -687,6 +693,8 @@ public class MainActivity extends AppCompatActivity implements ...@@ -687,6 +693,8 @@ public class MainActivity extends AppCompatActivity implements
break; break;
case Sensor.TYPE_ACCELEROMETER: case Sensor.TYPE_ACCELEROMETER:
accelVectorValues = sensorEvent.values; accelVectorValues = sensorEvent.values;
textView = findViewById(R.id.value_own_acceleration);
textView.setText(Utils.formatArray3(accelVectorValues));
case Sensor.TYPE_GYROSCOPE: case Sensor.TYPE_GYROSCOPE:
gyroVectorValues = sensorEvent.values; gyroVectorValues = sensorEvent.values;
break; break;
...@@ -715,7 +723,6 @@ public class MainActivity extends AppCompatActivity implements ...@@ -715,7 +723,6 @@ public class MainActivity extends AppCompatActivity implements
mSensorManager.registerListener(this, gyroSensor, SensorManager.SENSOR_DELAY_UI); mSensorManager.registerListener(this, gyroSensor, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, magSensor, SensorManager.SENSOR_DELAY_UI); mSensorManager.registerListener(this, magSensor, SensorManager.SENSOR_DELAY_UI);
Wearable.getMessageClient(this).addListener(this); Wearable.getMessageClient(this).addListener(this);
} }
@Override @Override
...@@ -886,6 +893,17 @@ public class MainActivity extends AppCompatActivity implements ...@@ -886,6 +893,17 @@ public class MainActivity extends AppCompatActivity implements
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
} }
// Acceleration data
HashMap<String, Float> acceleration = new HashMap<>();
acceleration.put("x", accelVectorValues[0]);
acceleration.put("y", accelVectorValues[1]);
acceleration.put("z", accelVectorValues[2]);
try {
String s = mapper.writeValueAsString(acceleration);
sendUpdate(phoneTopics.mqtt_topic_acceleration, String.valueOf(acceleration));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
// AHRS data // AHRS data
filter.Update(gyroVectorValues[0], gyroVectorValues[1], gyroVectorValues[2], filter.Update(gyroVectorValues[0], gyroVectorValues[1], gyroVectorValues[2],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/text_rotation" android:text="@string/text_rotation"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" /> app:layout_constraintTop_toBottomOf="@+id/label_own_acceleration" />
<TextView <TextView
android:id="@+id/value_own_rotation" android:id="@+id/value_own_rotation"
...@@ -27,7 +27,25 @@ ...@@ -27,7 +27,25 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@android:string/unknownName" android:text="@android:string/unknownName"
app:layout_constraintStart_toEndOf="@+id/label_own_rotation" app:layout_constraintStart_toEndOf="@+id/label_own_rotation"
app:layout_constraintTop_toBottomOf="@+id/value_own_brightness" /> app:layout_constraintTop_toBottomOf="@+id/value_own_acceleration" />
<TextView
android:id="@+id/label_own_acceleration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Acceleration"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" />
<TextView
android:id="@+id/value_own_acceleration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="unknown"
app:layout_constraintLeft_toRightOf="@id/label_own_acceleration"
app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" />
<TextView <TextView
android:id="@+id/label_wear_name" android:id="@+id/label_wear_name"
...@@ -97,7 +115,7 @@ ...@@ -97,7 +115,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" /> app:layout_constraintTop_toBottomOf="@+id/label_own_rotation" />
<TextView <TextView
android:id="@+id/label_own_brightness" android:id="@+id/label_own_brightness"
......
...@@ -81,6 +81,14 @@ ...@@ -81,6 +81,14 @@
android:text="@string/send_updates_rotation_quaternion" android:text="@string/send_updates_rotation_quaternion"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_ahrs" /> app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_ahrs" />
<CheckBox
android:id="@+id/checkBox_send_acceleration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Send Updates Acceleration"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_quaternion" />
<CheckBox <CheckBox
android:id="@+id/checkBox_send_wear_brightness" android:id="@+id/checkBox_send_wear_brightness"
...@@ -89,7 +97,7 @@ ...@@ -89,7 +97,7 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="@string/send_updates_wear_brightness" android:text="@string/send_updates_wear_brightness"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_quaternion" /> app:layout_constraintTop_toBottomOf="@+id/checkBox_send_acceleration" />
<CheckBox <CheckBox
android:id="@+id/checkBox_send_wear_acceleration" android:id="@+id/checkBox_send_wear_acceleration"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment