Skip to content

Commit

Permalink
Added disabling alerts and setting unit type from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rytiggy committed May 5, 2018
1 parent 1c03023 commit 92be51a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 39 deletions.
62 changes: 34 additions & 28 deletions Glance/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,41 +258,52 @@ inbox.onnewfile = () => {
document.getElementById("bg").style.fill="white"

// High || Low alert

// data.BGD[count].sgv = 50
// data.BGD[count].delta = -4
let sgv = data.BGD[count].sgv;

if( data.BGD[CONST_COUNT].units_hint == 'mmol' ){
sgv = mmol(sgv)
}


if( sgv >= data.settings.highThreshold) {
if((data.BGD[count].delta > 0)){
console.log('BG HIGH')
startVibration("nudge", 3000, sgv)
document.getElementById("bg").style.fill="#e2574c"
} else {
console.log('BG still HIGH, But you are going down')
showAlertModal = true;
}
}

if(sgv <= data.settings.lowThreshold) {
if((data.BGD[count].delta < 0)){
console.log('BG LOW')

if(!(data.settings.disableAlert)) {
if( sgv >= data.settings.highThreshold) {
if((data.BGD[count].delta > 0)){
console.log('BG HIGH')
startVibration("nudge", 3000, sgv)
document.getElementById("bg").style.fill="#e2574c"
} else {
console.log('BG still LOW, But you are going UP')
showAlertModal = true;
} else {
console.log('BG still HIGH, But you are going down')
showAlertModal = true;
}
}

if(sgv <= data.settings.lowThreshold) {
if((data.BGD[count].delta < 0)){
console.log('BG LOW')

startVibration("nudge", 3000, sgv)
document.getElementById("bg").style.fill="#e2574c"
} else {
console.log('BG still LOW, But you are going UP')
showAlertModal = true;
}
}
}
//End High || Low alert

processOneBg(data.BGD[count])

settings(data.settings, data.BGD[count].units_hint)

timeFormat = data.settings.timeFormat
let highThreshold = data.settings.highThreshold
let lowThreshold = data.settings.lowThreshold

if(data.BGD[count].units_hint === "mmol") {
highThreshold = mgdl( data.settings.highThreshold )
lowThreshold = mgdl( data.settings.lowThreshold )
}
// settings(data.settings, data.BGD[count].units_hint)


// Added by NiVZ
Expand Down Expand Up @@ -374,14 +385,9 @@ inbox.onnewfile = () => {
//
//----------------------------------------------------------
function settings(settings, unitsHint){
timeFormat = settings.timeFormat
let highThreshold = settings.highThreshold
let lowThreshold = settings.lowThreshold

if(unitsHint === "mmol") {
highThreshold = mgdl( settings.highThreshold )
lowThreshold = mgdl( settings.lowThreshold )
}

// console.log(settings.disableAlert)
// //document.getElementById("high").y = returnPoint(highThreshold)
// document.getElementById("high").text = settings.highThreshold

Expand Down
30 changes: 19 additions & 11 deletions Glance/companion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function queryOpenWeather() {
}


function queryBGD() {
function queryBGD(unitsHint) {
let url = getSgvURL()
console.log(url)
return fetch(url)
Expand Down Expand Up @@ -68,15 +68,22 @@ function queryBGD() {
let delta = 0;
let count = data.length - 1;
if(!data[count].delta) {
delta = data[count].sgv - data[count - 1].sgv
delta = data[count].sgv - data[count - 1].sgv // DEBUGGGG LOOK HERERERERERERER
}


data.forEach(function(bg, index){
bloodSugars.push({
let unitType = unitsHint;
if(unitType == null) {
unitType = bg.units_hint
} else {
unitType = unitType.values[0].name
}
bloodSugars.push({
sgv: bg.sgv,
delta: ((Math.round(bg.delta)) ? Math.round(bg.delta) : delta),
nextPull: diffMs,
units_hint: ((bg.units_hint) ? bg.units_hint : 'mgdl')
units_hint: unitType

})
})
Expand All @@ -103,25 +110,25 @@ function formatReturnData() {
});

let BGDPromise = new Promise(function(resolve, reject) {
resolve( queryBGD() );
resolve( queryBGD(getSettings("units") ) );
});
let highThreshold = null
let lowThreshold = null

if(getSettings("highThreshold")){
highThreshold = getSettings("highThreshold").name
}
if(getSettings("highThreshold").name == ""){
} else {
highThreshold = 200
}

if(getSettings("lowThreshold")){
lowThreshold = getSettings("lowThreshold").name
}
if(getSettings("lowThreshold").name == ""){
} else {
lowThreshold = 70
}

console.log("disableAlert")

console.log( getSettings('disableAlert'))
Promise.all([weatherPromise, BGDPromise]).then(function(values) {
let dataToSend = {
'weather':values[0],
Expand All @@ -130,7 +137,8 @@ function formatReturnData() {
'bgColor': getSettings('bgColor'),
'highThreshold': highThreshold,
'lowThreshold': lowThreshold,
'timeFormat' : getSettings('timeFormat')
'timeFormat' : getSettings('timeFormat'),
'disableAlert' : getSettings('disableAlert')
}
}
returnData(dataToSend)
Expand Down
12 changes: 12 additions & 0 deletions Glance/settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ function mySettings(props) {
label="Low threshold"
settingsKey="lowThreshold"
/>
<Select
label={`Glucose Units`}
settingsKey="units"
options={[
{name:"mgdl"},
{name:"mmol"}
]}
/>
<Toggle
settingsKey="disableAlert"
label="Disable Alerts"
/>
<Toggle
label="12hr | 24hr"
settingsKey="timeFormat"
Expand Down
Binary file renamed GlanceV1.1.3.fba → GlanceV1.1.4.fba
Binary file not shown.

0 comments on commit 92be51a

Please sign in to comment.