Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
FreeAPSXWatchApp/bin
FreeAPSXWatchface/bin
FreeAPSXWatchface/bin
FreeAPSXDataField/bin

.vscode

.DS_Store

developer_key
Empty file added FreeAPSXDataField/WARNING
Empty file.
8 changes: 8 additions & 0 deletions FreeAPSXDataField/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"glucose": "130",
"lastLoopDateInterval": 1682179861,
"delta": "-2",
"iob": "2.3",
"cob": "70",
"eventualBGRaw": "100"
}
48 changes: 48 additions & 0 deletions FreeAPSXDataField/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. -->
<iq:manifest version="3" xmlns:iq="http://www.garmin.com/xml/connectiq">
<!--
Use "Monkey C: Edit Application" from the Visual Studio Code command palette
to update the application attributes.
-->
<iq:application id="71cf0982-ca41-42a5-8441-ea81d36056c3" type="datafield" name="@Strings.AppName" entry="FreeAPSXDataFieldApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
<!--71cf0982-ca41-42a5-8441-ea81d36056c3
Use the following from the Visual Studio Code comand palette to edit
the build targets:
"Monkey C: Set Products by Version" - Lets you add all producs that meet the
minimum SDK version of the application
"Monkey C: Edit Products" - Lets you add or remove any product
-->
<iq:products>
<iq:product id="edge1030plus"/>
<iq:product id="fenix5"/>
<iq:product id="fenix5plus"/>
<iq:product id="fenix5s"/>
<iq:product id="fenix5splus"/>
<iq:product id="fenix5x"/>
<iq:product id="fenix5xplus"/>
<iq:product id="fr245"/>
</iq:products>
<!--
Use "Monkey C: Edit Permissions" from the Visual Studio Code command
palette to update permissions.
-->
<iq:permissions>
<iq:uses-permission id="Background"/>
<iq:uses-permission id="BluetoothLowEnergy"/>
<iq:uses-permission id="Communications"/>
</iq:permissions>
<!--
Use "Monkey C: Edit Languages" from the Visual Studio Code command
palette to edit your compatible language list.
-->
<iq:languages>
<iq:language>eng</iq:language>
</iq:languages>
<!--
Use "Monkey C: Configure Monkey Barrel" from the Visual Studio Code
command palette to edit the included barrels.
-->
<iq:barrels/>
</iq:application>
</iq:manifest>
1 change: 1 addition & 0 deletions FreeAPSXDataField/monkey.jungle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.manifest = manifest.xml
3 changes: 3 additions & 0 deletions FreeAPSXDataField/resources/drawables/drawables.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<drawables>
<bitmap id="LauncherIcon" filename="launcher_40_40.png" />
</drawables>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions FreeAPSXDataField/resources/layouts/layouts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<layouts>
<!-- A generic, centered layout. -->
<layout id="MainLayout">
<drawable class="Background" />
<label id="label" x="center" y="center" color="Graphics.COLOR_DK_GRAY" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_SYSTEM_XTINY" />
<label id="value" x="center" y="center" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_SYSTEM_LARGE" />
<label id="valueDelta" x="center" y="center" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_SYSTEM_SMALL" />
<label id="valueTime" x="center" y="center" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" font="Graphics.FONT_SYSTEM_XTINY" />
</layout>

<!-- Layouts used for the for the four quadrants. -->
<layout id="TopLeftLayout">
<drawable class="Background"/>
<label id="label" x="95" y="75" color="Graphics.COLOR_DK_GRAY" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_XTINY" />
<label id="value" x="95" y="42" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_LARGE" />
<label id="valueDelta" x="30" y="5" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_XTINY" />
</layout>
<layout id="TopRightLayout">
<drawable class="Background" />
<label id="label" x="14" y="75" color="Graphics.COLOR_DK_GRAY" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_XTINY" />
<label id="value" x="14" y="42" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_LARGE" />
<label id="valueDelta" x="14" y="5" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_XTINY" />

</layout>
<layout id="BottomLeftLayout">
<drawable class="Background" />
<label id="label" x="95" y="10" color="Graphics.COLOR_LT_GRAY" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_XTINY" />
<label id="value" x="95" y="27" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_RIGHT" font="Graphics.FONT_LARGE" />
<label id="valueDelta" x="95" y="40" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_XTINY" />

</layout>
<layout id="BottomRightLayout">
<drawable class="Background" />
<label id="label" x="5" y="5" color="Graphics.COLOR_DK_GRAY" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_XTINY" />
<label id="value" x="14" y="5" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_LARGE" />
<label id="valueDelta" x="30" y="5" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_XTINY" />
</layout>
</layouts>
4 changes: 4 additions & 0 deletions FreeAPSXDataField/resources/strings/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<strings>
<string id="AppName">iAPSDataField</string>
<string id="label">BG</string>
</strings>
20 changes: 20 additions & 0 deletions FreeAPSXDataField/source/CommsRealy.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Toybox.Communications as Comms;
import Toybox.Background;

(:background)
class CommsRelay extends Comms.ConnectionListener {
hidden var mCallback;

function initialize(callback) {
ConnectionListener.initialize();
mCallback = callback;
}

function onComplete() {
mCallback.invoke(true);
}

function onError() {
mCallback.invoke(false);
}
}
58 changes: 58 additions & 0 deletions FreeAPSXDataField/source/FreeAPSXDataFieldApp.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;
import Toybox.Background;
import Toybox.Time;
import Toybox.System;
import Toybox.Communications;

class FreeAPSXDataFieldApp extends Application.AppBase {

var phoneCallback;

function initialize() {
AppBase.initialize();
}

// onStart() is called on application start up
function onStart(state as Dictionary?) as Void {
//register for temporal events if they are supported
if(Toybox.System has :ServiceDelegate) {
// canDoBG=true;
Background.registerForTemporalEvent(new Time.Duration(5 * 60));
if (Background has :registerForPhoneAppMessageEvent) {
Background.registerForPhoneAppMessageEvent();
System.println("****background is ok****");
} else {
System.println("****registerForPhoneAppMessageEvent is not available****");
}

} else {
System.println("****background not available on this device****");
}
}

function onBackgroundData(data) {
Application.Storage.setValue("status", data as Dictionary);
WatchUi.requestUpdate();
}

// onStop() is called when your application is exiting
function onStop(state as Dictionary?) as Void {
}

//! Return the initial view of your application here
function getInitialView() as Array<Views or InputDelegates>? {
return [ new FreeAPSXDataFieldView() ] as Array<Views or InputDelegates>;
}

function getServiceDelegate() {
return [new FreeAPSXBGServiceDelegate()];
}


}

function getApp() as FreeAPSXDataFieldApp {
return Application.getApp() as FreeAPSXDataFieldApp;
}
28 changes: 28 additions & 0 deletions FreeAPSXDataField/source/FreeAPSXDataFieldBackground.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Toybox.Application;
import Toybox.Graphics;
import Toybox.WatchUi;

class Background extends WatchUi.Drawable {

hidden var mColor as ColorValue;

function initialize() {
var dictionary = {
:identifier => "Background"
};

Drawable.initialize(dictionary);

mColor = Graphics.COLOR_WHITE;
}

function setColor(color as ColorValue) as Void {
mColor = color;
}

function draw(dc as Dc) as Void {
dc.setColor(Graphics.COLOR_WHITE, mColor);
dc.clear();
}

}
163 changes: 163 additions & 0 deletions FreeAPSXDataField/source/FreeAPSXDataFieldView.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import Toybox.Activity;
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;


class FreeAPSXDataFieldView extends WatchUi.DataField {


function initialize() {
DataField.initialize();

}

// Set your layout here. Anytime the size of obscurity of
// the draw context is changed this will be called.
function onLayout(dc as Dc) as Void {
var obscurityFlags = DataField.getObscurityFlags();

// Top left quadrant so we'll use the top left layout
if (obscurityFlags == (OBSCURE_TOP | OBSCURE_LEFT)) {
View.setLayout(Rez.Layouts.TopLeftLayout(dc));

// Top right quadrant so we'll use the top right layout
} else if (obscurityFlags == (OBSCURE_TOP | OBSCURE_RIGHT)) {
View.setLayout(Rez.Layouts.TopRightLayout(dc));

// Bottom left quadrant so we'll use the bottom left layout
} else if (obscurityFlags == (OBSCURE_BOTTOM | OBSCURE_LEFT)) {
View.setLayout(Rez.Layouts.BottomLeftLayout(dc));

// Bottom right quadrant so we'll use the bottom right layout
} else if (obscurityFlags == (OBSCURE_BOTTOM | OBSCURE_RIGHT)) {
View.setLayout(Rez.Layouts.BottomRightLayout(dc));

// Use the generic, centered layout
} else {
View.setLayout(Rez.Layouts.MainLayout(dc));
var labelView = View.findDrawableById("label");
labelView.locX = labelView.locX - 40;
labelView.locY = labelView.locY - 10;
var valueView = View.findDrawableById("value");
valueView.locX = valueView.locX + 5;
valueView.locY = valueView.locY - 10;
var valueViewTime = View.findDrawableById("valueTime");
valueViewTime.locX = valueViewTime.locX + 10 ;
valueViewTime.locY = valueViewTime.locY + 20;
var valueViewDelta = View.findDrawableById("valueDelta");
valueViewDelta.locX = valueViewDelta.locX - 40;
valueViewDelta.locY = valueViewDelta.locY + 20;

}

(View.findDrawableById("label") as Text).setText(Rez.Strings.label);
}

// The given info object contains all the current workout information.
// Calculate a value and save it locally in this method.
// Note that compute() and onUpdate() are asynchronous, and there is no
// guarantee that compute() will be called before onUpdate().
function compute(info as Activity.Info) as Void {
// See Activity.Info in the documentation for available information.

}

// Display the value you computed here. This will be called
// once a second when the data field is visible.
function onUpdate(dc as Dc) as Void {
var bgString;
var loopColor;
var loopString;
var deltaString;

var status = Application.Storage.getValue("status") as Dictionary;

if (status == null) {
bgString = "---";
loopColor = getLoopColor(-1);
loopString = "(xx)";
deltaString = "??";
} else {
var bg = status["glucose"] as String;
bgString = (bg == null) ? "--" : bg as String;
var min = getMinutes(status);
loopColor = getLoopColor(min);
loopString = (min < 0 ? "(--)" : "(" + min.format("%d")) + " mn)" as String;
deltaString = getDeltaText(status) as String;
}
// Set the background color
//View.findDrawableById("Background").setColor(loopColor);
(View.findDrawableById("Background") as Text).setColor(loopColor); //getBackgroundColor());

// Set the foreground color and value
var value = View.findDrawableById("value") as Text;
var valueTime = View.findDrawableById("valueTime") as Text;
var valueDelta = View.findDrawableById("valueDelta") as Text;
if (getBackgroundColor() == Graphics.COLOR_BLACK) {
value.setColor(Graphics.COLOR_WHITE);
valueTime.setColor(Graphics.COLOR_WHITE);
valueDelta.setColor(Graphics.COLOR_WHITE);
} else {
value.setColor(Graphics.COLOR_BLACK);
valueTime.setColor(Graphics.COLOR_BLACK);
valueDelta.setColor(Graphics.COLOR_BLACK);
}
value.setText(bgString);
valueDelta.setText(deltaString);
valueTime.setText(loopString);

// Call parent's onUpdate(dc) to redraw the layout
View.onUpdate(dc);
}

function getMinutes(status as Dictionary) as Number {
//var status = Application.Storage.getValue("status") as Dictionary;
//System.print(Time.now().value());
if (status == null) {
return -1;
}
var lastLoopDate = status["lastLoopDateInterval"] as Number;

if (lastLoopDate == null) {
return -1;
}

if (lastLoopDate instanceof Number) {


var now = Time.now().value() as Number;

var min = (now - lastLoopDate) / 60;
return min;
} else {
return -1;
}
}

function getLoopColor(min as Number) as Number {
if (min < 0) {
return Graphics.COLOR_WHITE as Number;
} else if (min <= 5) {
return Graphics.COLOR_WHITE as Number;
// return Graphics.COLOR_GREEN as Number;
} else if (min <= 10) {
return Graphics.COLOR_YELLOW as Number;
} else {
return Graphics.COLOR_RED as Number;
}
}

function getDeltaText(status as Dictionary) as String {
// var status = Application.Storage.getValue("status") as Dictionary;
if (status == null) {
return "--";
}
var delta = status["delta"] as String;

var deltaString = (delta == null) ? "--" : delta;

return deltaString;
}

}
Loading