Skip to content

Commit

Permalink
Merge pull request #3 from bewest/config/init
Browse files Browse the repository at this point in the history
Config/init
  • Loading branch information
bewest committed May 20, 2014
2 parents a3cc8d2 + c0d8578 commit b16dc50
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 82 deletions.
64 changes: 32 additions & 32 deletions appinfo.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
{
"versionCode": 2,
"shortName": "CGM",
"uuid": "a4e66a45-f30d-4a13-9f0f-59343c6b23a9",
"capabilities": [
"configurable"
],
"appKeys": {
"time": 4,
"delta": 5,
"readtime": 2,
"bg": 1,
"icon": 0,
"alert": 3
},
"resources": {
"media": [
{
"name": "IMAGE_MENU_ICON",
"type": "png",
"name": "IMAGE_NONE",
"file": "images/none.png"
"file": "images/logo.png",
"menuIcon": true
},
{
"name": "IMAGE_UP",
"type": "png",
"name": "IMAGE_DOWN45",
"file": "images/down45.png"
"file": "images/up.png"
},
{
"name": "IMAGE_UPUP",
"type": "png",
"name": "IMAGE_DOWNDOWN",
"file": "images/downdown.png"
"file": "images/upup.png"
},
{
"name": "IMAGE_UP45",
"type": "png",
"name": "IMAGE_DOWN",
"file": "images/down.png"
"file": "images/up45.png"
},
{
"type": "png",
"name": "IMAGE_FLAT",
"type": "png",
"file": "images/flat.png"
},
{
"name": "IMAGE_DOWN",
"type": "png",
"name": "IMAGE_UP45",
"file": "images/up45.png"
"file": "images/down.png"
},
{
"name": "IMAGE_DOWNDOWN",
"type": "png",
"name": "IMAGE_UPUP",
"file": "images/upup.png"
"file": "images/downdown.png"
},
{
"name": "IMAGE_DOWN45",
"type": "png",
"name": "IMAGE_UP",
"file": "images/up.png"
"file": "images/down45.png"
},
{
"menuIcon": true,
"name": "IMAGE_NONE",
"type": "png",
"name": "IMAGE_MENU_ICON",
"file": "images/logo.png"
"file": "images/none.png"
}
]
},
"versionLabel": "2.0.0",
"companyName": "HackingType1-CostikCare,LLC",
"versionCode": 2,
"shortName": "CGM",
"longName": "CGM",
"watchapp": {
"watchface": true
},
"uuid": "a4e66a45-f30d-4a13-9f0f-59343c6b23a9",
"appKeys": {
"alert": 3,
"bg": 1,
"icon": 0,
"readtime": 2,
"delta": 5,
"time": 4
},
"longName": "CGM"
"companyName": "HackingType1-CostikCare,LLC",
"versionLabel": "2.0.0"
}
116 changes: 66 additions & 50 deletions src/js/pebble-js-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function fetchCgmData(lastReadTime, lastBG) {
readtime: timeago(new Date().getTime() - started),
alert: 0,
time: formatDate(new Date()),
delta: 'missing endpoint'
delta: 'SETTINGS'
};

console.log("sending message", JSON.stringify(message));
Expand All @@ -33,53 +33,69 @@ function fetchCgmData(lastReadTime, lastBG) {
console.log(req.readyState);
if (req.readyState == 4) {
var now = new Date().getTime();
console.log(req.status);
if(req.status == 200) {
console.log("status: " + req.status);
response = JSON.parse(req.responseText);

var sinceLastAlert = now - lastAlert,
alertValue = 0,
bgs = response.bgs,
currentBG = bgs[0].sgv,
currentBGDelta = bgs[0].bgdelta,
currentTrend = bgs[0].trend,
delta = (currentBGDelta > 0 ? '+' : '') + currentBGDelta + " mg/dL",
readingtime = new Date(bgs[0].datetime).getTime(),
readago = now - readingtime;

console.log(req.status);
if(req.status == 200) {
console.log("status: " + req.status);
response = JSON.parse(req.responseText);

console.log("now: " + now);
console.log("readingtime: " + readingtime);
console.log("readago: " + readago);

if (currentBG < 39) {
if (sinceLastAlert > TIME_10_MINS) alertValue = 2;
} else if (currentBG < 55 && sinceLastAlert > TIME_5_MINS)
alertValue = 2;
else if (currentBG < 60 && currentBGDelta < 0 && sinceLastAlert > TIME_10_MINS)
alertValue = 2;
else if (currentBG < 70 && sinceLastAlert > TIME_15_MINS)
alertValue = 2;
else if (currentBG < 120 && currentTrend == 7 && sinceLastAlert > TIME_5_MINS) //DBL_DOWN
var sinceLastAlert = now - lastAlert,
alertValue = 0,
bgs = response.bgs;
if (bgs && bgs.length > 0) {
console.log('got bgs', JSON.stringify(bgs));
var currentBG = bgs[0].sgv,
currentBGDelta = bgs[0].bgdelta,
currentTrend = bgs[0].trend,
delta = currentBGDelta + " mg/dL",
readingtime = new Date(bgs[0].datetime).getTime(),
readago = now - readingtime;

console.log("now: " + now);
console.log("readingtime: " + readingtime);
console.log("readago: " + readago);

if (currentBG < 39) {
if (sinceLastAlert > TIME_10_MINS) alertValue = 2;
} else if (currentBG < 55)
alertValue = 2;
else if (currentBG < 60 && currentBGDelta < 0)
alertValue = 2;
else if (currentBG < 70 && sinceLastAlert > TIME_15_MINS)
alertValue = 2;
else if (currentBG == 100 && currentTrend == 4 && sinceLastAlert > TIME_15_MINS) //PERFECT SCORE
alertValue = 1;
else if (currentBG > 120 && currentTrend == 1 && sinceLastAlert > TIME_15_MINS) //DBL_UP
alertValue = 3;
else if (currentBG > 200 && sinceLastAlert > TIME_30_MINS && currentBGDelta > 0)
alertValue = 3;
else if (currentBG > 250 && sinceLastAlert > TIME_30_MINS)
alertValue = 3;
else if (currentBG > 300 && sinceLastAlert > TIME_15_MINS)
alertValue = 3;

if (alertValue === 0 && readago > TIME_10_MINS && sinceLastAlert > TIME_15_MINS) {
alertValue = 1;
}
else if (currentBG < 120 && currentTrend == 7 && sinceLastAlert > TIME_5_MINS) //DBL_DOWN
alertValue = 2;
else if (currentBG == 100 && currentTrend == 4 && sinceLastAlert > TIME_15_MINS) //PERFECT SCORE
alertValue = 1;
else if (currentBG > 120 && currentTrend == 1 && sinceLastAlert > TIME_15_MINS) //DBL_UP
alertValue = 3;
else if (currentBG > 200 && sinceLastAlert > TIME_30_MINS && currentBGDelta > 0)
alertValue = 3;
else if (currentBG > 250 && sinceLastAlert > TIME_30_MINS)
alertValue = 3;
else if (currentBG > 300 && sinceLastAlert > TIME_15_MINS)
alertValue = 3;

if (alertValue === 0 && readago > TIME_10_MINS) {
alertValue = 1;
}

if (alertValue > 0) {
lastAlert = now;
}

message = {
icon: bgs[0].trend,
bg: currentBG,
readtime: timeago(new Date().getTime() - (new Date(bgs[0].datetime).getTime())),
alert: alertValue,
time: formatDate(new Date()),
delta: delta
};

console.log("message: " + JSON.stringify(message));
Pebble.sendAppMessage(message);

} else {
message = {
icon: 0,
Expand All @@ -88,11 +104,11 @@ function fetchCgmData(lastReadTime, lastBG) {
alert: 1,
time: formatDate(new Date()),
delta: 'offline'

};
console.log("sending message", JSON.stringify(message));
Pebble.sendAppMessage(message);

}
}
}
Expand All @@ -102,14 +118,14 @@ function fetchCgmData(lastReadTime, lastBG) {

function formatDate(date) {
var minutes = date.getMinutes(),
hours = date.getHours(),
meridiem = (hours >= 12) ? ' PM' : ' AM',
hours = date.getHours() || 12,
meridiem = " PM",
formatted;

if (hours === 0)
hours = 12;
else if (hours > 12)
if (hours > 12)
hours = hours - 12;
else
meridiem = " AM";

if (minutes < 10)
formatted = hours + ":0" + date.getMinutes() + meridiem;
Expand Down

0 comments on commit b16dc50

Please sign in to comment.