1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Casio: Refactoring

This commit is contained in:
Johannes Krude 2023-07-20 14:28:04 +02:00 committed by José Rebelo
parent 57ef0ded64
commit 91415e2500
18 changed files with 237 additions and 135 deletions

View File

@ -0,0 +1,46 @@
/* Copyright (C) 2023 Johannes Krude
based on code from BlueWatcher, https://github.com/masterjc/bluewatcher
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.casio;
import java.util.Collection;
import java.util.Collections;
import android.bluetooth.le.ScanFilter;
import android.os.ParcelUuid;
import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
public abstract class CasioDeviceCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid casioService = new ParcelUuid(CasioConstants.WATCH_FEATURES_SERVICE_UUID);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(casioService).build();
return Collections.singletonList(filter);
}
@Override
public String getManufacturer() {
return "Casio";
}
}

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2016-2021 Andreas Böhler, Andreas Shimokawa, Carsten
Pfeiffer, Daniele Gobbetti, José Rebelo
/* Copyright (C) 2016-2023 Andreas Böhler, Andreas Shimokawa, Carsten
Pfeiffer, Daniele Gobbetti, José Rebelo, Johannes Krude
based on code from BlueWatcher, https://github.com/masterjc/bluewatcher
@ -29,10 +29,9 @@ import org.slf4j.LoggerFactory;
import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -40,7 +39,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class CasioGB6900DeviceCoordinator extends AbstractBLEDeviceCoordinator {
public class CasioGB6900DeviceCoordinator extends CasioDeviceCoordinator {
protected static final Logger LOG = LoggerFactory.getLogger(CasioGB6900DeviceCoordinator.class);
@NonNull
@ -132,11 +131,6 @@ public class CasioGB6900DeviceCoordinator extends AbstractBLEDeviceCoordinator {
return false;
}
@Override
public String getManufacturer() {
return "Casio";
}
@Override
public boolean supportsAppsManagement(final GBDevice device) {
return false;

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2016-2021 Andreas Böhler, Andreas Shimokawa, Carsten
Pfeiffer, Daniele Gobbetti, José Rebelo
/* Copyright (C) 2016-2023 Andreas Böhler, Andreas Shimokawa, Carsten
Pfeiffer, Daniele Gobbetti, José Rebelo, Johannes Krude
based on code from BlueWatcher, https://github.com/masterjc/bluewatcher
@ -31,10 +31,10 @@ import androidx.annotation.NonNull;
import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioGBX100SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100.CasioGBX100SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.CasioGBX100ActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
@ -43,7 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class CasioGBX100DeviceCoordinator extends AbstractBLEDeviceCoordinator {
public class CasioGBX100DeviceCoordinator extends CasioDeviceCoordinator {
protected static final Logger LOG = LoggerFactory.getLogger(CasioGBX100DeviceCoordinator.class);
@NonNull
@ -136,11 +136,6 @@ public class CasioGBX100DeviceCoordinator extends AbstractBLEDeviceCoordinator {
return false;
}
@Override
public String getManufacturer() {
return "Casio";
}
@Override
public boolean supportsAppsManagement(final GBDevice device) {
return false;

View File

@ -15,7 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.casio;
package nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

View File

@ -32,8 +32,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.asteroidos.AsteroidOSDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.banglejs.BangleJSDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.binary_sensor.BinarySensorSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGB6900DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900.CasioGB6900DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.domyos.DomyosT540Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.fitpro.FitProDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.flipper.zero.support.FlipperZeroSupport;

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2016-2021 Andreas Shimokawa, Carsten Pfeiffer, Daniele
Gobbetti, Lukas Veneziano, Maxim Baz
/* Copyright (C) 2016-2023 Andreas Shimokawa, Carsten Pfeiffer, Daniele
Gobbetti, Lukas Veneziano, Maxim Baz, Johannes Krude
This file is part of Gadgetbridge.
@ -22,6 +22,8 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.threeten.bp.ZonedDateTime;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory;
@ -37,10 +39,11 @@ public class BLETypeConversions {
* Converts a timestamp to the byte sequence to be sent to the current time characteristic
*
* @param timestamp
* @param reason
* @return
* @see GattCharacteristic#UUID_CHARACTERISTIC_CURRENT_TIME
*/
public static byte[] calendarToCurrentTime(Calendar timestamp) {
public static byte[] calendarToCurrentTime(Calendar timestamp, int reason) {
// year,year,month,dayofmonth,hour,minute,second,dayofweek,fractions256,reason
byte[] year = fromUint16(timestamp.get(Calendar.YEAR));
@ -54,7 +57,33 @@ public class BLETypeConversions {
fromUint8(timestamp.get(Calendar.SECOND)),
dayOfWeekToRawBytes(timestamp),
fromUint8((int) (timestamp.get(Calendar.MILLISECOND) / 1000. * 256)),
0, // reason (not set)
(byte) reason, // use 0 if unknown reason
};
}
/**
* Converts a timestamp to the byte sequence to be sent to the current time characteristic
*
* @param timestamp
* @param reason
* @return
* @see GattCharacteristic#UUID_CHARACTERISTIC_CURRENT_TIME
*/
public static byte[] toCurrentTime(ZonedDateTime timestamp, int reason) {
// year,year,month,dayofmonth,hour,minute,second,dayofweek,fractions256,reason
byte[] year = fromUint16(timestamp.getYear());
return new byte[] {
year[0],
year[1],
fromUint8(timestamp.getMonthValue()),
fromUint8(timestamp.getDayOfMonth()),
fromUint8(timestamp.getHour()),
fromUint8(timestamp.getMinute()),
fromUint8(timestamp.getSecond()),
fromUint8(timestamp.getDayOfWeek().getValue()),
fromUint8((int) (timestamp.getNano() / 1000000000. * 256)),
(byte) reason, // use 0 if unknown reason
};
}

View File

@ -0,0 +1,56 @@
/* Copyright (C) 2016-2023 Andreas Böhler, Andreas Shimokawa, Carsten
Pfeiffer, Sebastian Kranz, Johannes Krude
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.ZonedDateTime;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
// this class is for those Casio watches which request reads on the 2C characteristic and write on the 2D characteristic
public abstract class Casio2C2DSupport extends CasioSupport {
public Casio2C2DSupport(Logger logger) {
super(logger);
}
public void writeAllFeatures(TransactionBuilder builder, byte[] arr) {
builder.write(getCharacteristic(CasioConstants.CASIO_ALL_FEATURES_CHARACTERISTIC_UUID), arr);
}
public void writeAllFeaturesRequest(TransactionBuilder builder, byte[] arr) {
builder.write(getCharacteristic(CasioConstants.CASIO_READ_REQUEST_FOR_ALL_FEATURES_CHARACTERISTIC_UUID), arr);
}
public void writeCurrentTime(TransactionBuilder builder, ZonedDateTime time) {
byte[] arr = new byte[11];
arr[0] = CasioConstants.characteristicToByte.get("CASIO_CURRENT_TIME");
byte[] tmp = prepareCurrentTime(time);
System.arraycopy(tmp, 0, arr, 1, 10);
writeAllFeatures(builder, arr);
}
}

View File

@ -1,3 +1,19 @@
/* Copyright (C) 2021-2023 Andreas Böhler, Johannes Krude
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio;
import android.net.Uri;
@ -5,33 +21,19 @@ import android.net.Uri;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.threeten.bp.ZonedDateTime;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
public class CasioSupport extends AbstractBTLEDeviceSupport {
public abstract class CasioSupport extends AbstractBTLEDeviceSupport {
protected boolean mFirstConnect = false;
private static final Logger LOG = LoggerFactory.getLogger(HuamiSupport.class);
public CasioSupport() {
this(LOG);
}
public CasioSupport(Logger logger) {
super(logger);
addSupportedService(CasioConstants.WATCH_FEATURES_SERVICE_UUID);
@ -43,25 +45,9 @@ public class CasioSupport extends AbstractBTLEDeviceSupport {
return connect();
}
protected byte[] prepareCurrentTime() {
byte[] arr = new byte[10];
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
arr[0] = (byte)((year >>> 0) & 0xff);
arr[1] = (byte)((year >>> 8) & 0xff);
arr[2] = (byte)(1 + cal.get(Calendar.MONTH));
arr[3] = (byte)cal.get(Calendar.DAY_OF_MONTH);
arr[4] = (byte)cal.get(Calendar.HOUR_OF_DAY);
arr[5] = (byte)cal.get(Calendar.MINUTE);
arr[6] = (byte)(1 + cal.get(Calendar.SECOND));
byte dayOfWk = (byte)(cal.get(Calendar.DAY_OF_WEEK) - 1);
if(dayOfWk == 0)
dayOfWk = 7;
arr[7] = dayOfWk;
arr[8] = (byte)(int) TimeUnit.MILLISECONDS.toSeconds(256 * cal.get(Calendar.MILLISECOND));
arr[9] = 1; // or 0?
return arr;
static protected byte[] prepareCurrentTime(ZonedDateTime time) {
// somehow everyone uses reason=1 for Casio watches
return BLETypeConversions.toCurrentTime(time, 1);
}
public void setInitialized() {
@ -69,9 +55,4 @@ public class CasioSupport extends AbstractBTLEDeviceSupport {
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());
}
@Override
public boolean useAutoConnect() {
return true;
}
}

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
@ -35,6 +35,8 @@ import java.util.Calendar;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.threeten.bp.ZonedDateTime;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
@ -54,8 +56,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
import nodomain.freeyourgadget.gadgetbridge.service.btle.ServerTransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations.InitOperationGB6900;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations.SetAlarmOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900.CasioGB6900HandlerThread;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900.InitOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900.SetAlarmOperation;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -65,7 +69,7 @@ public class CasioGB6900DeviceSupport extends CasioSupport {
private static final Logger LOG = LoggerFactory.getLogger(CasioGB6900DeviceSupport.class);
private final ArrayList<BluetoothGattCharacteristic> mCasioCharacteristics = new ArrayList<BluetoothGattCharacteristic>();
private CasioHandlerThread mHandlerThread = null;
private CasioGB6900HandlerThread mHandlerThread = null;
private MusicSpec mBufferMusicSpec = null;
private MusicStateSpec mBufferMusicStateSpec = null;
private BluetoothGatt mBtGatt = null;
@ -105,6 +109,11 @@ public class CasioGB6900DeviceSupport extends CasioSupport {
addSupportedServerService(casioGATTService);
}
@Override
public boolean useAutoConnect() {
return true;
}
@Override
public boolean connectFirstTime() {
GB.toast(getContext(), "After first connect, disable and enable bluetooth on your Casio watch to really connect", Toast.LENGTH_SHORT, GB.INFO);
@ -161,7 +170,7 @@ public class CasioGB6900DeviceSupport extends CasioSupport {
// BLE on the watch.
if(mModel != CasioConstants.Model.MODEL_CASIO_STB1000) {
try {
new InitOperationGB6900(this, builder).perform();
new InitOperation(this, builder).perform();
} catch (IOException e) {
GB.toast(getContext(), "Initializing Casio watch failed", Toast.LENGTH_SHORT, GB.ERROR, e);
}
@ -236,7 +245,7 @@ public class CasioGB6900DeviceSupport extends CasioSupport {
}
private void writeCasioCurrentTime(TransactionBuilder builder) {
byte[] arr = prepareCurrentTime();
byte[] arr = prepareCurrentTime(ZonedDateTime.now());
BluetoothGattCharacteristic charact = getCharacteristic(CasioConstants.CURRENT_TIME_CHARACTERISTIC_UUID);
if(charact != null) {
@ -291,7 +300,7 @@ public class CasioGB6900DeviceSupport extends CasioSupport {
mHandlerThread.interrupt();
}
}
mHandlerThread = new CasioHandlerThread(getDevice(), getContext(), this);
mHandlerThread = new CasioGB6900HandlerThread(getDevice(), getContext(), this);
mHandlerThread.start();
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());

View File

@ -15,7 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900;
import android.content.Context;
@ -28,8 +28,8 @@ import java.util.GregorianCalendar;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceIoThread;
public class CasioHandlerThread extends GBDeviceIoThread {
private static final Logger LOG = LoggerFactory.getLogger(CasioHandlerThread.class);
public class CasioGB6900HandlerThread extends GBDeviceIoThread {
private static final Logger LOG = LoggerFactory.getLogger(CasioGB6900HandlerThread.class);
private static final int TX_PERIOD = 60;
private final Object waitObject = new Object();
private boolean mQuit;
@ -38,7 +38,7 @@ public class CasioHandlerThread extends GBDeviceIoThread {
private Calendar mTxTime = GregorianCalendar.getInstance();
public CasioHandlerThread(GBDevice gbDevice, Context context, CasioGB6900DeviceSupport deviceSupport) {
public CasioGB6900HandlerThread(GBDevice gbDevice, Context context, CasioGB6900DeviceSupport deviceSupport) {
super(gbDevice, context);
LOG.info("Initializing Casio Handler Thread");
mQuit = false;
@ -100,7 +100,7 @@ public class CasioHandlerThread extends GBDeviceIoThread {
@Override
public void quit() {
LOG.info("CasioHandlerThread: Quit Handler Thread");
LOG.info("CasioGB6900HandlerThread: Quit Handler Thread");
mQuit = true;
synchronized (waitObject) {
waitObject.notify();

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -30,16 +30,16 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGB6900DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900.CasioGB6900DeviceSupport;
public class InitOperationGB6900 extends AbstractBTLEOperation<CasioGB6900DeviceSupport> {
private static final Logger LOG = LoggerFactory.getLogger(InitOperationGB6900.class);
public class InitOperation extends AbstractBTLEOperation<CasioGB6900DeviceSupport> {
private static final Logger LOG = LoggerFactory.getLogger(InitOperation.class);
private final TransactionBuilder builder;
private byte[] mBleSettings = null;
public InitOperationGB6900(CasioGB6900DeviceSupport support, TransactionBuilder builder) {
public InitOperation(CasioGB6900DeviceSupport support, TransactionBuilder builder) {
super(support);
this.builder = builder;
builder.setCallback(this);

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -30,11 +30,11 @@ import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGB6900DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gb6900.CasioGB6900DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
public class SetAlarmOperation extends AbstractBTLEOperation<CasioGB6900DeviceSupport> {
private static final Logger LOG = LoggerFactory.getLogger(GetConfigurationOperation.class);
private static final Logger LOG = LoggerFactory.getLogger(SetAlarmOperation.class);
private final ArrayList<? extends Alarm> mAlarms;
public SetAlarmOperation(CasioGB6900DeviceSupport support, ArrayList<? extends Alarm> alarms) {

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2016-2021 Andreas Böhler, Andreas Shimokawa, Carsten
Pfeiffer, Sebastian Kranz
/* Copyright (C) 2016-2023 Andreas Böhler, Andreas Shimokawa, Carsten
Pfeiffer, Sebastian Kranz, Johannes Krude
This file is part of Gadgetbridge.
@ -15,7 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -27,16 +27,19 @@ import android.widget.Toast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.ZonedDateTime;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.threeten.bp.ZonedDateTime;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
@ -44,7 +47,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioGBX100SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100.CasioGBX100SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Constants;
import nodomain.freeyourgadget.gadgetbridge.entities.CasioGBX100ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
@ -59,12 +62,12 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations.FetchStepCountDataOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations.GetConfigurationOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations.InitOperationGBX100;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations.SetConfigurationOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.Casio2C2DSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.FetchStepCountDataOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.GetConfigurationOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.InitOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.SetConfigurationOperation;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_AUTOLIGHT;
@ -84,7 +87,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH;
public class CasioGBX100DeviceSupport extends CasioSupport implements SharedPreferences.OnSharedPreferenceChangeListener {
public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(CasioGBX100DeviceSupport.class);
@ -99,14 +102,18 @@ public class CasioGBX100DeviceSupport extends CasioSupport implements SharedPref
public CasioGBX100DeviceSupport() {
super(LOG);
}
@Override
public boolean useAutoConnect() {
return true;
}
@Override
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
try {
new InitOperationGBX100(this, builder, mFirstConnect).perform();
new InitOperation(this, builder, mFirstConnect).perform();
} catch (IOException e) {
GB.toast(getContext(), "Initializing Casio watch failed", Toast.LENGTH_SHORT, GB.ERROR, e);
}
@ -225,7 +232,7 @@ public class CasioGBX100DeviceSupport extends CasioSupport implements SharedPref
if(data[1] == 0x00) {
try {
TransactionBuilder builder = performInitialized("writeCurrentTime");
writeCurrentTime(builder);
writeCurrentTime(builder, ZonedDateTime.now());
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn("writing current time failed: " + e.getMessage());
@ -423,23 +430,6 @@ public class CasioGBX100DeviceSupport extends CasioSupport implements SharedPref
}
}
public void writeCurrentTime(TransactionBuilder builder) {
byte[] arr = new byte[11];
arr[0] = CasioConstants.characteristicToByte.get("CASIO_CURRENT_TIME");
byte[] tmp = prepareCurrentTime();
System.arraycopy(tmp, 0, arr, 1, 10);
writeAllFeatures(builder, arr);
}
public void writeAllFeatures(TransactionBuilder builder, byte[] arr) {
builder.write(getCharacteristic(CasioConstants.CASIO_ALL_FEATURES_CHARACTERISTIC_UUID), arr);
}
public void writeAllFeaturesRequest(TransactionBuilder builder, byte[] arr) {
builder.write(getCharacteristic(CasioConstants.CASIO_READ_REQUEST_FOR_ALL_FEATURES_CHARACTERISTIC_UUID), arr);
}
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
byte[] data1 = new byte[5];
@ -484,7 +474,7 @@ public class CasioGBX100DeviceSupport extends CasioSupport implements SharedPref
LOG.debug("onSetTime called");
try {
TransactionBuilder builder = performInitialized("onSetTime");
writeCurrentTime(builder);
writeCurrentTime(builder, ZonedDateTime.now());
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn("onSetTime failed: " + e.getMessage());

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -34,7 +34,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.CasioGBX100ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
import nodomain.freeyourgadget.gadgetbridge.util.GB;

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -30,7 +30,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
import nodomain.freeyourgadget.gadgetbridge.util.BcdUtil;

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -22,6 +22,8 @@ import android.bluetooth.BluetoothGattCharacteristic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.ZonedDateTime;
import java.io.IOException;
import java.util.Calendar;
import java.util.UUID;
@ -32,17 +34,17 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport;
public class InitOperationGBX100 extends AbstractBTLEOperation<CasioGBX100DeviceSupport> {
private static final Logger LOG = LoggerFactory.getLogger(InitOperationGBX100.class);
public class InitOperation extends AbstractBTLEOperation<CasioGBX100DeviceSupport> {
private static final Logger LOG = LoggerFactory.getLogger(InitOperation.class);
private final TransactionBuilder builder;
private final CasioGBX100DeviceSupport support;
private final boolean mFirstConnect;
private boolean mWriteAllFeaturesInitPending = false;
public InitOperationGBX100(CasioGBX100DeviceSupport support, TransactionBuilder builder, boolean firstConnect) {
public InitOperation(CasioGBX100DeviceSupport support, TransactionBuilder builder, boolean firstConnect) {
super(support);
this.builder = builder;
this.support = support;
@ -339,7 +341,7 @@ public class InitOperationGBX100 extends AbstractBTLEOperation<CasioGBX100Device
LOG.debug("We need to bond here. This is actually the request for the link loss service.");
try {
TransactionBuilder builder = createTransactionBuilder("writeCurrentTime");
support.writeCurrentTime(builder);
support.writeCurrentTime(builder, ZonedDateTime.now());
writeAllFeaturesInit(builder);
support.performImmediately(builder);
} catch(IOException e) {
@ -381,4 +383,4 @@ public class InitOperationGBX100 extends AbstractBTLEOperation<CasioGBX100Device
return super.onCharacteristicRead(gatt, characteristic, status);
}
}
}

View File

@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -33,7 +33,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
import nodomain.freeyourgadget.gadgetbridge.util.BcdUtil;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
@ -323,4 +323,4 @@ public class SetConfigurationOperation extends AbstractBTLEOperation<CasioGBX10
}
return super.onCharacteristicWrite(gatt, characteristic, status);
}
}
}

View File

@ -391,7 +391,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
public void onSetTime() {
// Since this is a standard we should generalize this in Gadgetbridge (properly)
GregorianCalendar now = BLETypeConversions.createCalendar();
byte[] bytesCurrentTime = BLETypeConversions.calendarToCurrentTime(now);
byte[] bytesCurrentTime = BLETypeConversions.calendarToCurrentTime(now, 0);
byte[] bytesLocalTime = BLETypeConversions.calendarToLocalTime(now);
TransactionBuilder builder = new TransactionBuilder("set time");