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
45 changes: 30 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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
}
});
}
})

Expand All @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion scripts/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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?
}

Expand Down