Skip to content
Merged
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
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var fs = require('fs');

var i2cBus = i2c.openSync(1);

var openapsDir = "/root/myopenaps"; //if you're using a nonstandard OpenAPS directory, set that here. NOT RECOMMENDED.

// setup the display
var displayConfig = require('./config/display.json');
displayConfig.i2cBus = i2cBus;
Expand Down Expand Up @@ -46,15 +48,15 @@ socketServer
.on('displaystatus', function () {
if (display) {
var preferences;
fs.readFile('/root/myopenaps/preferences.json', function (err, data) {
fs.readFile(openapsDir+'/preferences.json', function (err, data) {
if (err) throw err;
preferences = JSON.parse(data);
if (preferences.status_screen == "bigbgstatus") {
bigBGStatus(display);
bigBGStatus(display, openapsDir);
} else if (preferences.status_screen == "off") {
//don't auto-update the screen if it's turned off
} else {
graphStatus(display); //default to graph status
graphStatus(display, openapsDir); //default to graph status
}
});
}
Expand Down Expand Up @@ -92,10 +94,10 @@ hidMenu
.on('nothing', function () {
})
.on('showgraphstatus', function () {
graphStatus(display);
graphStatus(display, openapsDir);
})
.on('showbigBGstatus', function () {
bigBGStatus(display);
bigBGStatus(display, openapsDir);
})
.on('showlogo', function () {
displayImage('./static/unicorn.png');
Expand Down
51 changes: 31 additions & 20 deletions scripts/big_bg_status.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
module.exports = bigbgstatus;

function bigbgstatus(display) {

const path = require('path');
const extend = require('extend');
var os = require('os');
var fs = require('fs');
var font = require('oled-font-5x7');

Expand Down Expand Up @@ -34,38 +27,45 @@ function stripLeadingZero(value)
return value.toString().replace( re, '$1');
}

display.oled.dimDisplay(true); //dim the display
display.oled.clearDisplay(false); //clear the buffer
module.exports = bigbgstatus;

//
//Start of status display function
//

function bigbgstatus(display, openapsDir) {

display.oled.clearDisplay(true); //clear the buffer

//Parse all the .json files we need
try {
var profile = JSON.parse(fs.readFileSync("/root/myopenaps/settings/profile.json"));
var profile = JSON.parse(fs.readFileSync(openapsDir+"/settings/profile.json"));
} catch (e) {
// Note: profile.json is optional as it's only needed for mmol conversion for now. Print an error, but not return
console.error("Status screen display error: could not parse profile.json: ", e);
}
try {
var batterylevel = JSON.parse(fs.readFileSync("/root/myopenaps/monitor/edison-battery.json"));
var batterylevel = JSON.parse(fs.readFileSync(openapsDir+"/monitor/edison-battery.json"));
} catch (e) {
console.error("Status screen display error: could not parse edison-battery.json: ", e);
}
try {
var suggested = JSON.parse(fs.readFileSync("/root/myopenaps/enact/suggested.json"));
var suggested = JSON.parse(fs.readFileSync(openapsDir+"/enact/suggested.json"));
} catch (e) {
console.error("Status screen display error: could not parse suggested.json: ", e);
}
try {
var bg = JSON.parse(fs.readFileSync("/root/myopenaps/monitor/glucose.json"));
var bg = JSON.parse(fs.readFileSync(openapsDir+"/monitor/glucose.json"));
} catch (e) {
console.error("Status screen display error: could not parse glucose.json: ", e);
}
try {
var iob = JSON.parse(fs.readFileSync("/root/myopenaps/monitor/iob.json"));
var iob = JSON.parse(fs.readFileSync(openapsDir+"/monitor/iob.json"));
} catch (e) {
console.error("Status screen display error: could not parse iob.json: ", e);
}
try {
var cob = JSON.parse(fs.readFileSync("/root/myopenaps/monitor/meal.json"));
var cob = JSON.parse(fs.readFileSync(openapsDir+"/monitor/meal.json"));
} catch (e) {
console.error("Status screen display error: could not parse meal.json: ", e);
}
Expand Down Expand Up @@ -139,10 +139,21 @@ if(iob && cob) {
display.oled.writeString(font, 2, " "+cob.mealCOB+'g', 1, false, 0, false);
}

//display everything in the buffer
display.oled.update();
display.oled.dimDisplay(true); //dim the display
display.oled.update(); // write buffer to the screen

fs.readFile(openapsDir+"/preferences.json", function (err, data) {
if (err) throw err;
preferences = JSON.parse(data);
if (preferences.wearOLEDevenly == false) {
display.oled.invertDisplay(false);
} else {
display.oled.invertDisplay((endDate % 2 == 1));
}
});

//
}//End of status display function
//

//fandomly invert display to evenly wear the OLED diodes
display.oled.invertDisplay((endDate % 2 == 1));

} //from start of function
16 changes: 9 additions & 7 deletions scripts/status.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
var fs = require('fs');
var font = require('oled-font-5x7');
const homeDir = require('os').homedir();

var openapsDir = "/root/myopenaps"; //if you're using a nonstandard OpenAPS directory, set that here
var evenOLEDwear = true; //if you want to prevent OLED burn-in symptoms by inverting the screen, set this to true

// Rounds value to 'digits' decimal places
function round(value, digits)
Expand Down Expand Up @@ -37,7 +33,7 @@ module.exports = graphicalStatus;
//Start of status display function
//

function graphicalStatus(display) {
function graphicalStatus(display, openapsDir) {

display.oled.clearDisplay(true); //clear display buffer

Expand Down Expand Up @@ -233,9 +229,15 @@ display.oled.writeString(font, 1, clockHour+":"+clockMin, 1, false, 0, false);
display.oled.dimDisplay(true); //dim the display
display.oled.update(); //write buffer to the screen

if (evenOLEDwear == true) {
fs.readFile(openapsDir+"/preferences.json", function (err, data) {
if (err) throw err;
preferences = JSON.parse(data);
if (preferences.wearOLEDevenly == false) {
display.oled.invertDisplay(false);
} else {
display.oled.invertDisplay((endDate % 2 == 1));
}
}
});

//
}//End of status display function
Expand Down