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

light state (on/off) can now be controlled

parent 033fc5fb
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -98,6 +99,7 @@ public class MainActivity extends AppCompatActivity implements
private String clientId;
private AppSettings settings;
MadgwickAHRS filter;
ToggleButton switchLight;
private EditText valueServerURI;
......@@ -176,9 +178,34 @@ public class MainActivity extends AppCompatActivity implements
String mqttServer = settings.get(SETTINGS_MQTT_SERVER, getResources().getString(R.string.default_mqtt_server_uri));
valueServerURI.setText(mqttServer);
switchLight = findViewById(R.id.toggleButton_lightonoff);
switchLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch (buttonView.getId()) {
case R.id.toggleButton_lightonoff:
sendMqttUpdates.put(phoneTopics.mqtt_topic_onoff, true); // is always true
sendLightOnOffUpdateOfSmartphone(isChecked);
break;
}
}
});
setupSendUpdatesCheckbox();
}
private void sendLightOnOffUpdateOfSmartphone(boolean state) {
ObjectMapper mapper = new ObjectMapper();
HashMap<String, Boolean> dataLight = new HashMap<>();
dataLight.put("on", state);
try {
String s = mapper.writeValueAsString(dataLight);
sendUpdate(phoneTopics.mqtt_topic_onoff, s);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
private void updateMqttTopics(String wearableName) {
// moto: "Moto 360"
// polar: ??
......
......@@ -6,11 +6,13 @@ public class MqttTopics {
public final String mqtt_topic_acceleration;
public final String mqtt_topic_rotation;
public final String mqtt_topic_rotation_ahrs;
public final String mqtt_topic_onoff;
public MqttTopics(String subTopic) {
mqtt_topic_brightness = MQTT_TOPIC_BASE + subTopic + "/brightness";
mqtt_topic_acceleration = MQTT_TOPIC_BASE + subTopic + "/acceleration";
mqtt_topic_rotation = MQTT_TOPIC_BASE + subTopic + "/rotation";
mqtt_topic_rotation_ahrs = MQTT_TOPIC_BASE + subTopic + "/rotationahrs";
mqtt_topic_onoff = MQTT_TOPIC_BASE + subTopic + "/onoff";
}
}
......@@ -263,4 +263,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/separator_wear" />
<ToggleButton
android:id="@+id/toggleButton-lightonoff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Switch On"
android:textOn="Switch Light OFF"
android:textOff="Switch Light ON"
app:layout_constraintEnd_toEndOf="@+id/checkBox_send_rotation_ahrs"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_ahrs" />
</android.support.constraint.ConstraintLayout>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment