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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ This is the repository holding the menu-based software code, which you may choos

See [here](https://github.com/EnhancedRadioDevices/Explorer-HAT) for more details on the Explorer HAT hardware.

You can set your preferred auto-updating status screen using the following setting in your `~/myopenaps/preferences.json`:

`"status_screen": "bigbgstatus"` will display the big BG status screen (no graph).

`"status_screen": "off"` will turn the auto-updating screen off.


By default, the auto-updating status script will invert the display about 50% of the time, to prevent burn-in on the OLED screen. You can turn this off with the following setting in your `~/myopenaps/preferences.json`:

`"wearOLEDevenly": "off"`

Or you can have it invert the display from 8pm to 8am with:

`"wearOLEDevenly": "nightandday"`


## Example screen outputs (Note: these are examples. The latest code may yield different menu items and screen displays)

### Status screen:
Expand Down
10 changes: 5 additions & 5 deletions config/buttons.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"pins": {
"buttonUp": 11,
"buttonDown": 13
"gpios": {
"buttonUp": 17,
"buttonDown": 27
},
"options": {
"pressed": 200,
"clicked": 400
"socketPath": "/var/run/pi-buttons.sock",
"reconnectTimeout": 3000
}
}
10 changes: 6 additions & 4 deletions config/menus/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"menu": [
{
"label": "Status Graph",
"command": "node scripts/status.js",
"emit": "nothing"
"emit": "showgraphstatus"
},
{
"label": "Big BG Status",
"emit": "showbigBGstatus"
},
{
"label": "Set Temp Target",
Expand Down Expand Up @@ -54,8 +57,7 @@
},
{
"label": "Unicorn Logo",
"command": "node scripts/unicorn.js",
"emit": "nothing"
"emit": "showlogo"
}
]
},
Expand Down
76 changes: 58 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ 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);

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;
var display = require('./lib/display/ssd1306')(displayConfig);

// display the logo
pngparse.parseFile('./static/unicorn.png', function(err, image) {
if(err)
throw err
display.clear();
display.oled.drawBitmap(image.data);
});
try {
var display = require('./lib/display/ssd1306')(displayConfig);
displayImage('./static/unicorn.png'); //display logo
} catch (e) {
console.warn("Could not setup display:", e);
}

// setup battery voltage monitor
var voltageConfig = require('./config/voltage.json')
Expand All @@ -44,8 +45,36 @@ socketServer
.on('warning', (warn) => {
console.log('socket-server warning: ', warn.reason)
})
.on('displaystatus', function () {
if (display) {
var preferences;
fs.readFile(openapsDir+'/preferences.json', function (err, data) {
if (err) throw err;
preferences = JSON.parse(data);
if (preferences.status_screen == "bigbgstatus") {
bigBGStatus(display, openapsDir);
} else if (preferences.status_screen == "off") {
//don't auto-update the screen if it's turned off
} else {
graphStatus(display, openapsDir); //default to graph status
}
});
}
})

function displayImage(pathToImage) {
pngparse.parseFile(pathToImage, function(err, image) {
if(err)
throw err
display.clear();
display.oled.drawBitmap(image.data);
});
}

// load up graphical status scripts
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 @@ -64,6 +93,15 @@ var hidMenu = require('./lib/hid-menu/hid-menu')(buttonsConfig, menuConfig);
hidMenu
.on('nothing', function () {
})
.on('showgraphstatus', function () {
graphStatus(display, openapsDir);
})
.on('showbigBGstatus', function () {
bigBGStatus(display, openapsDir);
})
.on('showlogo', function () {
displayImage('./static/unicorn.png');
})
.on('showvoltage', function () {
voltage()
.then(function (v) {
Expand All @@ -85,16 +123,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);
}
}
29 changes: 15 additions & 14 deletions lib/hid-menu/hid-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,71 @@
const Menube = require('menube');

function createHIDMenu(configButtons, configMenus) {
if (!configButtons.pins || !configButtons.pins.buttonUp || !configButtons.pins.buttonDown) {
if (!configButtons.gpios || !configButtons.gpios.buttonUp || !configButtons.gpios.buttonDown) {
throw new Error('Incomplete pins definition in configuration.');
}
var pins = configButtons.pins;
var gpios = configButtons.gpios;
var buttonOptions = configButtons.options || {};
var onChange = configMenus.onChange;
var menu = Menube(configMenus.menuFile, configMenus.menuSettings);
var displayDirty = false;
// var buttons = require('rpi-gpio-buttons')([pins.buttonUp, pins.buttonDown], buttonOptions);
var piButtons = require('../pi-buttons');
var piButtons = require('node-pi-buttons')(configButtons.options);

menu.on('menu_changed', function () {
displayDirty = false; // the parent will redraw the display
});

// buttons
piButtons
.on('clicked', function (pin) {
.on('clicked', function (gpio, data) {
if (displayDirty) {
// fake menu changed to force redraw
menu.emit('menu_changed');
displayDirty = false;
}
else {
switch(pin) {
case pins.buttonUp:
switch(parseInt(gpio, 10)) {
case gpios.buttonUp:
if (!displayDirty) {
menu.menuUp();
}
break;

case pins.buttonDown:
case gpios.buttonDown:
if (!displayDirty) {
menu.menuDown();
}
break;
}
}
})
.on('double_clicked', function (pin) {
.on('double_clicked', function (gpio, data) {
if (displayDirty) {
// fake menu changed to force redraw
menu.emit('menu_changed');
displayDirty = false;
}
else {
switch (pin) {
case pins.buttonUp:
switch (parseInt(gpio, 10)) {
case gpios.buttonUp:
menu.menuBack();
break;

case pins.buttonDown:
case gpios.buttonDown:
displayDirty = true; // activate may write something to the display
menu.activateSelect();
break;
}
}
})
.on('released', function (pin) {
.on('released', function (gpio, data) {
if (displayDirty) {
// fake menu changed to force redraw
menu.emit('menu_changed');
displayDirty = false;
}
})
.on('error', function (data) {
console.log('ERROR: ', data.error);
});

return menu;
Expand Down
Binary file removed lib/pi-buttons/a.out
Binary file not shown.
5 changes: 0 additions & 5 deletions lib/pi-buttons/build.sh

This file was deleted.

Loading