forked from NightscoutFoundation/xDrip
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/NightscoutFoundation/xDrip …
…into jamorhamvoice
- Loading branch information
Showing
9 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/AmazfitAlarm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.eveningoutpost.dexdrip.wearintegration; | ||
|
||
public class AmazfitAlarm extends Amazfitservice { | ||
//todo | ||
} |
138 changes: 138 additions & 0 deletions
138
app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package com.eveningoutpost.dexdrip.wearintegration; | ||
|
||
import com.eveningoutpost.dexdrip.Models.BgReading; | ||
import com.eveningoutpost.dexdrip.Models.JoH; | ||
import com.eveningoutpost.dexdrip.Models.UserError; | ||
import android.app.Service; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import com.eveningoutpost.dexdrip.Models.HeartRate; | ||
import com.eveningoutpost.dexdrip.Models.StepCounter; | ||
|
||
import android.os.IBinder; | ||
import android.support.annotation.Nullable; | ||
|
||
import android.util.Log; | ||
|
||
import com.eveningoutpost.dexdrip.BestGlucose; | ||
import com.eveningoutpost.dexdrip.Models.UserError; | ||
import com.huami.watch.transport.DataBundle; | ||
import com.huami.watch.transport.TransportDataItem; | ||
|
||
|
||
import com.kieronquinn.library.amazfitcommunication.Transporter; | ||
import com.kieronquinn.library.amazfitcommunication.TransporterClassic; | ||
import com.kieronquinn.library.amazfitcommunication.Utils; | ||
|
||
import android.os.Handler; | ||
|
||
|
||
|
||
|
||
/** | ||
* Created by klaus3d3. | ||
*/ | ||
|
||
public class Amazfitservice extends Service { | ||
BestGlucose.DisplayGlucose dg; | ||
private Transporter transporter; | ||
private Context context; | ||
DataBundle dataBundle = new DataBundle(); | ||
private HeartRate heartrate; | ||
private StepCounter stepcounter; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
|
||
transporter = (TransporterClassic)Transporter.get(getApplicationContext(), "com.eveningoutpost.dexdrip.wearintegration"); | ||
transporter.connectTransportService(); | ||
transporter.addChannelListener(new Transporter.ChannelListener() { | ||
@Override | ||
public void onChannelChanged(boolean ready) { | ||
//Transporter is ready if ready is true, send an action now. This will **NOT** work before the transporter is ready! | ||
//You can change the action to whatever you want, there's also an option for a data bundle to be added (see below) | ||
if(ready) UserError.Log.e("Amazfitservice", "channel changed "); | ||
} | ||
}); | ||
|
||
transporter.addDataListener(new Transporter.DataListener() { | ||
@Override | ||
public void onDataReceived(TransportDataItem item) { | ||
if (item.getAction().equals("Amazfit_Healthdata")) { | ||
DataBundle databundle = item.getData(); | ||
final StepCounter pm = StepCounter.createEfficientRecord(JoH.tsl(), databundle.getInt("steps")); | ||
HeartRate.create(JoH.tsl(),databundle.getInt("heart_rate"), databundle.getInt("heart_acuracy")); | ||
|
||
}else UserError.Log.e("Amazfitservice", item.getAction()); | ||
} | ||
|
||
|
||
}); | ||
|
||
} | ||
|
||
|
||
@Nullable | ||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
|
||
|
||
transporter.disconnectTransportService(); | ||
UserError.Log.e("Amazfitservice", "killing service "); | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
|
||
|
||
if (!transporter.isTransportServiceConnected()){ | ||
UserError.Log.e("Amazfitservice", "Service not connected - trying to reconnect "); | ||
transporter.connectTransportService(); | ||
try { | ||
wait(1000); | ||
} catch (Exception e) {} | ||
} | ||
|
||
|
||
if (!transporter.isTransportServiceConnected()) { | ||
UserError.Log.e("Amazfitservice", "Service is not connectable "); | ||
; | ||
}else{ | ||
UserError.Log.e("Amazfitservice", "Service is connected "); | ||
|
||
transporter.send("Xdrip_synced_SGV_data", getDataBundle()); | ||
UserError.Log.e("Amazfitservice", "Send Data to watch " ); | ||
} | ||
return START_STICKY; | ||
|
||
} | ||
|
||
|
||
public DataBundle getDataBundle() { | ||
BestGlucose.DisplayGlucose dg = BestGlucose.getDisplayGlucose(); | ||
//UserError.Log.e("Amazfitservice", "putting data together "); | ||
|
||
dataBundle.putLong("date", dg.timestamp); | ||
dataBundle.putString("sgv", String.valueOf(dg.unitized)+" "+ dg.delta_arrow); | ||
dataBundle.putString("delta", String.valueOf(dg.spannableString(dg.unitized_delta))); | ||
dataBundle.putBoolean("ishigh", dg.isHigh()); | ||
dataBundle.putBoolean("islow", dg.isLow()); | ||
dataBundle.putBoolean("isstale", dg.isStale()); | ||
dataBundle.putBoolean("fromplugin", dg.from_plugin); | ||
dataBundle.putString("extra_string", dg.extra_string); | ||
dataBundle.putString("plugin_name", dg.plugin_name); | ||
dataBundle.putInt("warning", dg.warning); | ||
|
||
|
||
return dataBundle; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters