2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2017-2020 Andreas Shimokawa, Carsten Pfeiffer, DerFetzer,
|
2019-11-23 21:52:46 +01:00
|
|
|
Matthieu Baerts, Roi Greenberg
|
2017-08-13 16:31:11 +02:00
|
|
|
|
|
|
|
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/>. */
|
2018-06-14 18:16:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip;
|
2017-08-13 16:31:11 +02:00
|
|
|
|
2017-10-24 22:01:25 +02:00
|
|
|
import android.content.Context;
|
2017-08-25 00:21:47 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
|
2017-08-21 23:47:47 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-08-19 20:58:13 +02:00
|
|
|
import java.io.IOException;
|
2020-11-07 10:19:28 +01:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
2017-08-19 20:58:13 +02:00
|
|
|
|
2020-05-12 22:42:19 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2017-10-24 22:01:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
2018-08-05 15:26:12 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
|
2017-10-24 22:01:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper;
|
2017-08-16 20:55:20 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
2017-08-18 16:21:54 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
2018-03-31 16:21:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
2017-08-19 20:58:13 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
2018-08-01 22:56:01 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchActivityOperation;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation;
|
2019-08-25 09:55:23 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.HuamiFetchDebugLogsOperation;
|
2018-07-16 14:36:52 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
2017-08-13 16:31:11 +02:00
|
|
|
|
2018-08-01 22:56:01 +02:00
|
|
|
public class AmazfitBipSupport extends HuamiSupport {
|
2017-08-21 23:47:47 +02:00
|
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSupport.class);
|
|
|
|
|
2017-09-27 21:46:23 +02:00
|
|
|
public AmazfitBipSupport() {
|
|
|
|
super(LOG);
|
|
|
|
}
|
|
|
|
|
2017-08-13 16:31:11 +02:00
|
|
|
@Override
|
|
|
|
public NotificationStrategy getNotificationStrategy() {
|
|
|
|
return new AmazfitBipTextNotificationStrategy(this);
|
|
|
|
}
|
|
|
|
|
2017-08-18 16:21:54 +02:00
|
|
|
@Override
|
|
|
|
public void onNotification(NotificationSpec notificationSpec) {
|
2019-10-31 14:28:24 +01:00
|
|
|
super.sendNotificationNew(notificationSpec, false);
|
2017-08-18 16:21:54 +02:00
|
|
|
}
|
|
|
|
|
2017-08-13 16:31:11 +02:00
|
|
|
@Override
|
|
|
|
public void onFindDevice(boolean start) {
|
2017-08-16 20:55:20 +02:00
|
|
|
CallSpec callSpec = new CallSpec();
|
|
|
|
callSpec.command = start ? CallSpec.CALL_INCOMING : CallSpec.CALL_END;
|
|
|
|
callSpec.name = "Gadgetbridge";
|
|
|
|
onSetCallState(callSpec);
|
2017-08-13 16:31:11 +02:00
|
|
|
}
|
2017-08-15 17:23:12 +02:00
|
|
|
|
2018-01-20 01:34:40 +01:00
|
|
|
@Override
|
|
|
|
protected AmazfitBipSupport setDisplayItems(TransactionBuilder builder) {
|
2020-11-07 10:19:28 +01:00
|
|
|
Map<String, Integer> keyPosMap = new LinkedHashMap<>();
|
|
|
|
keyPosMap.put("status", 1);
|
|
|
|
keyPosMap.put("activity", 2);
|
|
|
|
keyPosMap.put("weather", 3);
|
|
|
|
keyPosMap.put("alarm", 4);
|
|
|
|
keyPosMap.put("timer", 5);
|
|
|
|
keyPosMap.put("compass", 6);
|
|
|
|
keyPosMap.put("settings", 7);
|
|
|
|
keyPosMap.put("alipay", 8);
|
|
|
|
|
|
|
|
setDisplayItemsOld(builder, false, R.array.pref_bip_display_items_default, keyPosMap);
|
|
|
|
//setShortcuts(builder, shortcut_weather, shortcut_alipay);
|
2018-01-20 01:34:40 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-05-15 23:12:18 +02:00
|
|
|
private void setShortcuts(TransactionBuilder builder, boolean weather, boolean alipay) {
|
|
|
|
LOG.info("Setting shortcuts: weather=" + weather + " alipay=" + alipay);
|
|
|
|
|
|
|
|
// Basically a hack to put weather first always, if alipay is the only enabled one
|
|
|
|
// there are actually two alipays set but the second one disabled.... :P
|
|
|
|
byte[] command = new byte[]{0x10,
|
|
|
|
(byte) ((alipay || weather) ? 0x80 : 0x00), (byte) (weather ? 0x02 : 0x01),
|
|
|
|
(byte) ((alipay && weather) ? 0x81 : 0x01), 0x01,
|
|
|
|
};
|
|
|
|
|
2018-08-02 10:55:30 +02:00
|
|
|
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
|
2018-05-15 23:12:18 +02:00
|
|
|
}
|
|
|
|
|
2017-09-18 23:24:11 +02:00
|
|
|
@Override
|
2018-03-31 16:21:25 +02:00
|
|
|
public void onFetchRecordedData(int dataTypes) {
|
2017-09-18 23:24:11 +02:00
|
|
|
try {
|
2018-03-31 16:21:25 +02:00
|
|
|
// FIXME: currently only one data type supported, these are meant to be flags
|
|
|
|
if (dataTypes == RecordedDataTypes.TYPE_ACTIVITY) {
|
|
|
|
new FetchActivityOperation(this).perform();
|
|
|
|
} else if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS) {
|
|
|
|
new FetchSportsSummaryOperation(this).perform();
|
|
|
|
} else if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) {
|
2019-08-13 22:04:52 +02:00
|
|
|
new HuamiFetchDebugLogsOperation(this).perform();
|
2019-08-25 09:55:23 +02:00
|
|
|
} else {
|
2018-03-31 16:21:25 +02:00
|
|
|
LOG.warn("fetching multiple data types at once is not supported yet");
|
|
|
|
}
|
2017-09-18 23:24:11 +02:00
|
|
|
} catch (IOException ex) {
|
2018-03-31 16:21:25 +02:00
|
|
|
LOG.error("Unable to fetch recorded data types" + dataTypes, ex);
|
2017-09-18 23:24:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 22:16:59 +02:00
|
|
|
@Override
|
|
|
|
public void phase2Initialize(TransactionBuilder builder) {
|
|
|
|
super.phase2Initialize(builder);
|
|
|
|
LOG.info("phase2Initialize...");
|
2017-09-28 15:44:07 +02:00
|
|
|
setLanguage(builder);
|
2017-08-29 22:16:59 +02:00
|
|
|
requestGPSVersion(builder);
|
|
|
|
}
|
2017-10-24 22:01:25 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
|
|
|
|
return new AmazfitBipFWHelper(uri, context);
|
|
|
|
}
|
2017-08-29 22:16:59 +02:00
|
|
|
}
|