diff --git a/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java b/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java index 7cb74e1746bcf05cb91bae069cc7b9e4bf15e122..6e032612790cef484eb38445a1d1d30b59327136 100644 --- a/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java +++ b/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java @@ -226,9 +226,11 @@ public class MainActivity extends AppCompatActivity implements private void setupSendUpdatesCheckbox() { final CheckBox sendUpdates = findViewById(R.id.checkBox_send_brightness); final CheckBox sendUpdatesRotation = findViewById(R.id.checkBox_send_rotation_ahrs); + final CheckBox sendUpdatesRotationQuat = findViewById(R.id.checkBox_send_rotation_quaternion); sendMqttUpdates.put(phoneTopics.mqtt_topic_brightness, sendUpdates.isChecked()); sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation_ahrs, sendUpdatesRotation.isChecked()); + sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked()); CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override @@ -240,11 +242,15 @@ public class MainActivity extends AppCompatActivity implements case R.id.checkBox_send_rotation_ahrs: sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation_ahrs, sendUpdatesRotation.isChecked()); break; + case R.id.checkBox_send_rotation_quaternion: + sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked()); + break; } } }; sendUpdates.setOnCheckedChangeListener(onCheckedChangeListener); sendUpdatesRotation.setOnCheckedChangeListener(onCheckedChangeListener); + sendUpdatesRotationQuat.setOnCheckedChangeListener(onCheckedChangeListener); } private void setName() { @@ -485,8 +491,10 @@ public class MainActivity extends AppCompatActivity implements * Whether the data is really published depends on the checkboxes. */ private void sendUpdateOfSmartphone() { + ObjectMapper mapper = new ObjectMapper(); + // Brightness data HashMap<String, Float> dataLight = new HashMap<>(); dataLight.put("brightness", mLightValue); try { @@ -496,6 +504,7 @@ public class MainActivity extends AppCompatActivity implements e.printStackTrace(); } + // AHRS data filter.Update(gyroVectorValues[0], gyroVectorValues[1], gyroVectorValues[2], accelVectorValues[0], accelVectorValues[1], accelVectorValues[2], magVectorValues[0], magVectorValues[1], magVectorValues[2]); @@ -514,6 +523,19 @@ public class MainActivity extends AppCompatActivity implements } catch (JsonProcessingException e) { e.printStackTrace(); } + + // Quaternion data + HashMap<String, Float> dataQuat = new HashMap<>(); + dataQuat.put("x", mRotationVectorValues[0]); + dataQuat.put("y", mRotationVectorValues[1]); + dataQuat.put("z", mRotationVectorValues[2]); + //dataQuat.put("w", mRotationVectorValues[3]); + try { + String s = mapper.writeValueAsString(dataQuat); + sendUpdate(phoneTopics.mqtt_topic_rotation, s); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } private void sendUpdate(String topic, String newValue) { diff --git a/mobile/src/main/res/layout/activity_main.xml b/mobile/src/main/res/layout/activity_main.xml index c1bdc74d34d6d30df123dafec1e639ea7d7a4950..e68e0a09b339c881bdc70aa2d7230c69712c8ce0 100644 --- a/mobile/src/main/res/layout/activity_main.xml +++ b/mobile/src/main/res/layout/activity_main.xml @@ -257,6 +257,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/checkBox_send_brightness" /> + <CheckBox + android:id="@+id/checkBox_send_rotation_quaternion" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:text="@string/send_updates_rotation_quaternion" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_ahrs" /> + <TextView android:id="@+id/label_wear_status" android:layout_width="wrap_content" @@ -277,7 +287,7 @@ android:textOff="@string/switch_light_on" android:textOn="@string/switch_light_off" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_ahrs" /> + app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_quaternion" /> </android.support.constraint.ConstraintLayout> </ScrollView> diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index c7474e2dcb535196ad8ea9a18571066fbd523013..14a7d53eb04539a2b6b72f52df34a2a0a2b31319 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -16,4 +16,5 @@ <string name="switch_on">Switch On</string> <string name="switch_light_on">Switch Light ON</string> <string name="switch_light_off">Switch Light OFF</string> + <string name="send_updates_rotation_quaternion">Send Updates Rotation (Quaternion)</string> </resources>