Skip to content
Snippets Groups Projects
Commit a080d831 authored by Dominik Grzelak's avatar Dominik Grzelak
Browse files

orientation with quaternions can now be transmitted too

parent a4edfa11
Branches
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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>
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment