diff --git a/index.js b/index.js index 206dca4..a65e74c 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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 } }); } @@ -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'); diff --git a/scripts/big_bg_status.js b/scripts/big_bg_status.js index db1145f..3e9483b 100644 --- a/scripts/big_bg_status.js +++ b/scripts/big_bg_status.js @@ -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'); @@ -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); } @@ -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 diff --git a/scripts/status.js b/scripts/status.js index ee97a61..5f727f6 100644 --- a/scripts/status.js +++ b/scripts/status.js @@ -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) @@ -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 @@ -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