mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-31 21:15:50 +01:00
added some fun and useless requests
This commit is contained in:
parent
2bba2c449f
commit
e6ac9d91a5
@ -0,0 +1,160 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.microapp;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public interface MicroAppCommand {
|
||||
byte[] getData();
|
||||
}
|
||||
|
||||
class StartCriticalCommand implements MicroAppCommand{
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return new byte[]{(byte) 0x03, (byte) 0x00};
|
||||
}
|
||||
}
|
||||
|
||||
class CloseCommand implements MicroAppCommand{
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return new byte[]{(byte) 0x01, (byte) 0x00};
|
||||
}
|
||||
}
|
||||
|
||||
class DelayCommand implements MicroAppCommand{
|
||||
private double delayInSeconds;
|
||||
|
||||
public DelayCommand(double delayInSeconds) {
|
||||
this.delayInSeconds = delayInSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return ByteBuffer.wrap(new byte[]{0x08, 0x01, 0x00, 0x00})
|
||||
.order(ByteOrder.LITTLE_ENDIAN)
|
||||
.putShort(2, (short)(delayInSeconds * 10f))
|
||||
.array();
|
||||
}
|
||||
}
|
||||
|
||||
enum VibrationType{
|
||||
NORMAL((byte) 0x04);
|
||||
|
||||
private byte value;
|
||||
|
||||
VibrationType(byte value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public byte getValue(){ return this.value; }
|
||||
}
|
||||
|
||||
class VibrateCommand implements MicroAppCommand{
|
||||
private VibrationType vibrationType;
|
||||
|
||||
public VibrateCommand(VibrationType vibrationType) {
|
||||
this.vibrationType = vibrationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return ByteBuffer.wrap(new byte[]{(byte) 0x93, 0x00, 0x00})
|
||||
.put(2, vibrationType.getValue())
|
||||
.array();
|
||||
}
|
||||
}
|
||||
|
||||
enum MovingDirection{
|
||||
CLOCKWISE((byte) 0x00),
|
||||
COUNTER_CLOCKWISE((byte) 0x01),
|
||||
SHORTEST((byte) 0x02),
|
||||
;
|
||||
private byte value;
|
||||
|
||||
MovingDirection(byte value){ this.value = value; }
|
||||
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
enum MovingSpeed{
|
||||
MAX((byte) 0x00),
|
||||
HALF((byte) 0x01),
|
||||
QUARTER((byte) 0x02),
|
||||
EIGHTH((byte) 0x03),
|
||||
SIXTEENTH((byte) 0x04),
|
||||
;
|
||||
private byte value;
|
||||
|
||||
MovingSpeed(byte value){ this.value = value; }
|
||||
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
class StreamCommand implements MicroAppCommand{
|
||||
private byte type;
|
||||
|
||||
public StreamCommand(byte type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return new byte[]{(byte) 0x8B, (byte) 0x00, this.type};
|
||||
}
|
||||
}
|
||||
|
||||
class RepeatStartCommand implements MicroAppCommand{
|
||||
private byte count;
|
||||
|
||||
public RepeatStartCommand(byte count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return new byte[]{(byte) 0x86, (byte) 0x00, this.count};
|
||||
}
|
||||
}
|
||||
|
||||
class RepeatStopCommand implements MicroAppCommand{
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return new byte[]{(byte) 0x07, (byte) 0x00};
|
||||
}
|
||||
}
|
||||
|
||||
class AnimationCommand implements MicroAppCommand{
|
||||
private short hour, minute;
|
||||
private MovingDirection direction;
|
||||
private MovingSpeed speed;
|
||||
private byte absoluteMovementFlag;
|
||||
|
||||
public AnimationCommand(short hour, short minute) {
|
||||
this.hour = hour;
|
||||
this.minute = minute;
|
||||
this.speed = MovingSpeed.MAX;
|
||||
this.direction = MovingDirection.SHORTEST;
|
||||
this.absoluteMovementFlag = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
return ByteBuffer.allocate(10)
|
||||
.order(ByteOrder.LITTLE_ENDIAN)
|
||||
.put((byte) 0x09)
|
||||
.put((byte) 0x04)
|
||||
.put((byte) 0x01)
|
||||
.put((byte) 0x03)
|
||||
.put((byte) ((direction.getValue() << 6) | (byte)(absoluteMovementFlag << 5) | this.speed.getValue()))
|
||||
.putShort(this.hour)
|
||||
.put((byte) ((direction.getValue() << 6) | (byte)(absoluteMovementFlag << 5) | this.speed.getValue()))
|
||||
.putShort(this.minute)
|
||||
.array();
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.microapp;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
||||
|
||||
public class PlayCrazyShitRequest extends FilePutRequest {
|
||||
public PlayCrazyShitRequest(byte[] appData, FossilWatchAdapter adapter) {
|
||||
super((short) 0x0600, createPayload(appData), adapter);
|
||||
}
|
||||
|
||||
private static byte[] createPayload(byte[] appData) {
|
||||
List<MicroAppCommand> commands = new ArrayList<>();
|
||||
|
||||
commands.add(new StartCriticalCommand());
|
||||
// commands.add(new RepeatStartCommand((byte) 10));
|
||||
commands.add(new VibrateCommand(VibrationType.NORMAL));
|
||||
commands.add(new DelayCommand(1));
|
||||
// commands.add(new RepeatStopCommand());
|
||||
// commands.add(new StreamCommand((byte) 0b11111111));
|
||||
// commands.add(new AnimationCommand((short) 300, (short) 60));
|
||||
// commands.add(new DelayCommand(2));
|
||||
commands.add(new CloseCommand());
|
||||
|
||||
int length = 0;
|
||||
|
||||
for (MicroAppCommand command : commands) length += command.getData().length;
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(
|
||||
3 /* magic bytes */
|
||||
+ 8 /* button header copy */
|
||||
+ 1 /* 0xFF */
|
||||
+ 2 /* payload length */
|
||||
+ length
|
||||
+ 4 /* crc */
|
||||
);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
buffer.put((byte) 0x01);
|
||||
buffer.put((byte) 0x00);
|
||||
buffer.put((byte) 0x08);
|
||||
buffer.put(appData, 3, 8);
|
||||
buffer.put((byte) 0xFF);
|
||||
buffer.putShort((short)(length + 3));
|
||||
|
||||
for(MicroAppCommand command : commands) buffer.put(command.getData());
|
||||
|
||||
CRC32 crc = new CRC32();
|
||||
crc.update(buffer.array(), 0, buffer.position());
|
||||
|
||||
buffer.putInt((int) crc.getValue());
|
||||
|
||||
return buffer.array();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user