diff --git a/index.js b/index.js index d1561df..206dca4 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ const i2c = require('i2c-bus'); const path = require('path'); const pngparse = require('pngparse'); const extend = require('extend'); +var fs = require('fs'); var i2cBus = i2c.openSync(1); @@ -21,7 +22,7 @@ try { var display = require('./lib/display/ssd1306')(displayConfig); displayImage('./static/unicorn.png'); //display logo } catch (e) { - console.warn("Could not setup display:", e); + console.warn("Could not setup display:", e); } // setup battery voltage monitor @@ -44,7 +45,18 @@ socketServer }) .on('displaystatus', function () { if (display) { - graphicalStatus(display); + var preferences; + fs.readFile('/root/myopenaps/preferences.json', function (err, data) { + if (err) throw err; + preferences = JSON.parse(data); + if (preferences.status_screen == "bigbgstatus") { + bigBGStatus(display); + } else if (preferences.status_screen == "off") { + //don't auto-update the screen if it's turned off + } else { + graphStatus(display); //default to graph status + } + }); } }) @@ -58,8 +70,9 @@ function displayImage(pathToImage) { } // load up graphical status scripts -const graphicalStatus = require('./scripts/status.js'); +const graphStatus = require('./scripts/status.js'); const bigBGStatus = require('./scripts/big_bg_status.js'); +// if you want to add your own status display script, it will be easiest to replace one of the above! // setup the menus var buttonsConfig = require('./config/buttons.json'); @@ -78,8 +91,8 @@ var hidMenu = require('./lib/hid-menu/hid-menu')(buttonsConfig, menuConfig); hidMenu .on('nothing', function () { }) -.on('showGFXstatus', function () { - graphicalStatus(display); +.on('showgraphstatus', function () { + graphStatus(display); }) .on('showbigBGstatus', function () { bigBGStatus(display); @@ -108,16 +121,18 @@ hidMenu // display the current menu on the display function showMenu(menu) { - display.clear(); - var text = ''; + if (display) { + display.clear(); + var text = ''; - var p = menu.getParentSelect(); - text += p ? '[' + p.label + ']\n' : ''; - var c = menu.getCurrentSelect(); - menu.getActiveMenu().forEach(function (m) { - text += (m.selected ? '>' : ' ') + m.label + '\n'; - }); + var p = menu.getParentSelect(); + text += p ? '[' + p.label + ']\n' : ''; + var c = menu.getCurrentSelect(); + menu.getActiveMenu().forEach(function (m) { + text += (m.selected ? '>' : ' ') + m.label + '\n'; + }); -// console.log(text); - display.write(text); + // console.log(text); + display.write(text); + } } diff --git a/package.json b/package.json index 3fb697e..0ab2c55 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "i2c-bus": "^1.2.2", "menube": "^1.0.3", "oled-font-5x7": "^1.0.0", - "oled-i2c-bus": "git+https://github.com/bnielsen1965/oled-i2c-bus.git", + "oled-i2c-bus": "git+https://github.com/baltazorr/oled-i2c-bus.git", "pngparse": "^2.0.1", "node-pi-buttons": "git+https://github.com/bnielsen1965/node-pi-buttons.git", "rpi-gpio": "^0.9.1" diff --git a/scripts/status.js b/scripts/status.js index 7b1399a..ee97a61 100644 --- a/scripts/status.js +++ b/scripts/status.js @@ -39,7 +39,7 @@ module.exports = graphicalStatus; function graphicalStatus(display) { -display.oled.clearDisplay(false); //clear display buffer +display.oled.clearDisplay(true); //clear display buffer //Parse all the .json files we need try { @@ -116,6 +116,10 @@ if (status && suggested) { display.oled.writeString(font, 1, "CGM data unchanged", 1, false, 0, false); yOffset = 3; } + else if (notLoopingReason.includes("BG data is too old")) { + display.oled.writeString(font, 1, "BG data too old", 1, false, 0, false); + yOffset = 3; + } //add more on-screen warnings/messages, maybe some special ones for xdrip-js users? }