1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-02-17 12:56:48 +01:00

Fossil HR: adjusted alarms to have title and message

This commit is contained in:
Daniel Dakhno 2020-04-25 01:57:02 +02:00
parent 4061e1c66c
commit 7cf4e64682
3 changed files with 48 additions and 20 deletions

View File

@ -440,7 +440,8 @@ public class FossilWatchAdapter extends WatchAdapter {
activeAlarms.add(new nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.alarm.Alarm(
(byte) alarm.getMinute(),
(byte) alarm.getHour(),
false
alarm.getTitle(),
alarm.getDescription()
));
continue;
}
@ -449,7 +450,9 @@ public class FossilWatchAdapter extends WatchAdapter {
activeAlarms.add(new nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.alarm.Alarm(
(byte) alarm.getMinute(),
(byte) alarm.getHour(),
(byte) repitition
(byte) repitition,
alarm.getTitle(),
alarm.getDescription()
));
}
queueWrite(new AlarmsSetRequest(activeAlarms.toArray(new nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.alarm.Alarm[0]), this){

View File

@ -29,24 +29,25 @@ public class Alarm {
private byte days = 0;
private byte minute, hour;
private boolean repeat;
private String title, message;
public Alarm(byte minute, byte hour){
public Alarm(byte minute, byte hour, String title, String message){
this.minute = minute;
this.hour = hour;
this.repeat = false;
this.title = title;
this.message = message;
}
public Alarm(byte minute, byte hour, boolean repeat){
this.minute = minute;
this.hour = hour;
this.repeat = repeat;
}
public Alarm(byte minute, byte hour, byte days){
public Alarm(byte minute, byte hour, byte days, String title, String message){
this.minute = minute;
this.hour = hour;
this.repeat = true;
this.days = days;
this.title = title;
this.message = message;
}
public void setDayEnabled(int day, boolean enabled){
@ -78,9 +79,25 @@ public class Alarm {
boolean repeat = (bytes[1] & 0x80) == 0x80;
if(repeat) {
return new Alarm(minutes, bytes[2], days);
return new Alarm(minutes, bytes[2], days, "some title", "i dunno this should't happen");
}
return new Alarm(minutes, bytes[2]);
return new Alarm(minutes, bytes[2], "some title", "i dunno this should't happen");
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@NonNull

View File

@ -52,20 +52,28 @@ public class AlarmsSetRequest extends FilePutRequest {
buffer = ByteBuffer.allocate(alarms.length * 3);
for (Alarm alarm : alarms) buffer.put(alarm.getData());
} else {
String label = "Brr Brr";
String message = "I am an alarm";
int sizeWhole = 17 * alarms.length;
for(Alarm alarm : alarms){
String label = alarm.getTitle();
label = label.substring(0, Math.min(label.length(), 15));
alarm.setTitle(label);
label = label.substring(0, Math.min(label.length(), 15));
message = message.substring(0, Math.min(message.length(), 50));
String message = alarm.getMessage();
message = message.substring(0, Math.min(message.length(), 50));
alarm.setMessage(message);
int SIZE_ALARM = 17 + label.length() + message.length();
int sizeAll = alarms.length * SIZE_ALARM;
buffer = ByteBuffer.allocate(sizeAll); // 4 for overall length
sizeWhole += label.length() + message.length();
}
buffer = ByteBuffer.allocate(sizeWhole); // 4 for overall length
buffer.order(ByteOrder.LITTLE_ENDIAN);
for (Alarm alarm : alarms) {
String label = alarm.getTitle();
String message = alarm.getMessage();
int alarmSize = 17 + label.length() + message.length();
buffer.put((byte) 0x00); // dunno why
buffer.putShort((short) (SIZE_ALARM - 3)); // alarm size, 0 above does not count
buffer.putShort((short) (alarmSize - 3)); // alarm size, 0 above and this does not count
buffer.put((byte) 0x00); // prolly entry id time data
buffer.putShort((short) 3); // prolly entry length
buffer.put(alarm.getData());