androvac/app/src/main/java/eu/worn/apps/androvac/RoboVac11sRemote.java

91 lines
2.9 KiB
Java
Raw Normal View History

2019-02-17 09:52:17 +00:00
package eu.worn.apps.androvac;
2019-02-17 16:43:09 +00:00
import android.content.SharedPreferences;
2019-02-17 09:52:17 +00:00
import java.util.Calendar;
2019-02-17 14:04:34 +00:00
class RoboVac11sRemote {
2019-02-17 16:43:09 +00:00
private SharedPreferences preferences;
2019-02-17 14:04:34 +00:00
final IRModulation modulation = new EufyIRModulation();
2019-02-17 09:52:17 +00:00
2019-02-19 08:04:59 +00:00
private boolean scheduleEnabled;
private int scheduleHour;
private int scheduleMinute;
2019-02-17 09:52:17 +00:00
private byte[] buildMessage(byte command) {
byte msg[] = new byte[6];
Calendar now = Calendar.getInstance();
msg[0] = (byte) 0x68;
msg[1] = command;
msg[2] = (byte) now.get(Calendar.HOUR_OF_DAY);
msg[3] = (byte) now.get(Calendar.MINUTE);
2019-02-19 08:04:59 +00:00
msg[4] = (byte) (scheduleEnabled ? (scheduleHour * 4 + scheduleMinute / 15) : 0xff);
2019-02-17 09:52:17 +00:00
msg[5] = (byte) (msg[0] + msg[1] + msg[2] + msg[3] + msg[4]);
return msg;
}
2019-02-17 16:43:09 +00:00
RoboVac11sRemote(SharedPreferences pref) {
preferences = pref;
2019-02-19 08:04:59 +00:00
scheduleHour = preferences.getInt("scheduleHour", 0);
scheduleMinute = preferences.getInt("scheduleMinute", 0);
scheduleEnabled = preferences.getBoolean("scheduleEnabled", false);
2019-02-17 16:43:09 +00:00
}
private void storeSchedule() {
SharedPreferences.Editor editor = preferences.edit();
2019-02-19 08:04:59 +00:00
editor.putBoolean("scheduleEnabled", scheduleEnabled);
editor.putInt("scheduleHour", scheduleHour);
editor.putInt("scheduleMinute", scheduleMinute);
2019-02-17 16:43:09 +00:00
editor.commit();
}
2019-02-19 08:04:59 +00:00
public boolean isScheduleEnabled() {
return scheduleEnabled;
}
2019-02-17 16:43:09 +00:00
public int getScheduleHour() {
2019-02-19 08:04:59 +00:00
return scheduleHour;
2019-02-17 16:43:09 +00:00
}
public int getScheduleMinute() {
2019-02-19 08:04:59 +00:00
return scheduleMinute;
2019-02-17 09:52:17 +00:00
}
2019-02-17 16:43:09 +00:00
public byte[] setSchedule(int hour, int minute) {
2019-02-19 08:04:59 +00:00
scheduleHour = hour;
scheduleMinute = minute;
scheduleEnabled = true;
2019-02-17 16:43:09 +00:00
storeSchedule();
return buildMessage((byte) 0xcf);
2019-02-17 09:52:17 +00:00
}
2019-02-17 16:43:09 +00:00
public byte[] clearSchedule() {
2019-02-19 08:04:59 +00:00
scheduleEnabled = false;
2019-02-17 16:43:09 +00:00
storeSchedule();
return buildMessage((byte) 0xdf);
2019-02-17 09:52:17 +00:00
}
2019-02-17 16:43:09 +00:00
byte[] setTime() { return buildMessage((byte) 0xbf); }
2019-02-17 14:04:34 +00:00
byte[] cleanAuto() { return buildMessage((byte) 0x5d); }
byte[] cleanSpot() { return buildMessage((byte) 0x8c); }
byte[] cleanEdge() { return buildMessage((byte) 0x9c); }
byte[] cleanRoom() { return buildMessage((byte) 0xad); }
2019-02-17 09:52:17 +00:00
2019-02-17 14:04:34 +00:00
byte[] powerStandard() { return buildMessage((byte) 0x1e); }
byte[] powerMax() { return buildMessage((byte) 0x1c); }
byte[] powerBoostIQ() { return buildMessage((byte) 0x1d); }
2019-02-17 09:52:17 +00:00
2019-02-17 14:04:34 +00:00
byte[] moveForward() { return buildMessage((byte) 0x2f); }
byte[] moveBackward() { return buildMessage((byte) 0x7f); }
byte[] moveCCW() { return buildMessage((byte) 0x3f); }
byte[] moveCW() { return buildMessage((byte) 0x6f); }
byte[] returnBase() { return buildMessage((byte) 0xef); }
2019-02-17 09:52:17 +00:00
2019-02-17 14:04:34 +00:00
byte[] stop() { return buildMessage((byte) 0x4f); }
2019-02-17 09:52:17 +00:00
}