Skip to content

Commit

Permalink
Actually fix the problem from previous merge
Browse files Browse the repository at this point in the history
This hunk is also critically needed.
  • Loading branch information
bewest committed May 20, 2014
1 parent 42a6e8b commit c0d8578
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 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,18 +33,21 @@ 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,
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 > 0 ? '+' : '') + currentBGDelta + " mg/dL",
delta = currentBGDelta + " mg/dL",
readingtime = new Date(bgs[0].datetime).getTime(),
readago = now - readingtime;

Expand All @@ -54,9 +57,9 @@ function fetchCgmData(lastReadTime, lastBG) {

if (currentBG < 39) {
if (sinceLastAlert > TIME_10_MINS) alertValue = 2;
} else if (currentBG < 55 && sinceLastAlert > TIME_5_MINS)
} else if (currentBG < 55)
alertValue = 2;
else if (currentBG < 60 && currentBGDelta < 0 && sinceLastAlert > TIME_10_MINS)
else if (currentBG < 60 && currentBGDelta < 0)
alertValue = 2;
else if (currentBG < 70 && sinceLastAlert > TIME_15_MINS)
alertValue = 2;
Expand All @@ -73,7 +76,7 @@ function fetchCgmData(lastReadTime, lastBG) {
else if (currentBG > 300 && sinceLastAlert > TIME_15_MINS)
alertValue = 3;

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

Expand All @@ -89,10 +92,10 @@ function fetchCgmData(lastReadTime, lastBG) {
time: formatDate(new Date()),
delta: delta
};

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

} else {
message = {
icon: 0,
Expand All @@ -101,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 @@ -115,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 c0d8578

Please sign in to comment.