Skip to content

Commit

Permalink
Introduced separate config files for screen configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mistau committed Dec 6, 2019
1 parent d090534 commit d60384a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The following properties can be configured:
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `botToken` | The token of the Telegram Bot, which will recieve the images. How to create a bot and get the token is explained [here](https://core.telegram.org/bots#6-botfather). |
| `whitelistChats` | Use this to only allow certain users to send photos to your TeleFrame. See hints below. |
| `screenConfig` | Points to the configuration file of your screen, see folder TeleFrame/config/screens for possible configurations. Default: config/screens/hdmi_standard.js |
| `playSoundOnRecieve` | Play a sound on recieving a message, set `false` to turn off. |
| `showVideos` | When set to true, videos that are send to the bot are also shown. |
| `playVideoAudio` | If recieved videos should be played with sound or not. |
Expand Down
1 change: 1 addition & 0 deletions config/config.example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var config = {
botToken: "",
whitelistChats: [],
screenConfig: "./config/screens/dsi_raspberry_7inch.js",
playSoundOnRecieve: "sound1.mp3",
showVideos: true,
playVideoAudio: false,
Expand Down
21 changes: 21 additions & 0 deletions config/screens/dsi_raspberry_7inch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* settings for the official Raspberry Pi 7'' screen connected via DSI
*
*/
var screen = {
name: "Raspberry Pi 7'' DSI screen",
xres: 800,
yres: 480,
hasTouch: true,
hasBacklightCtl: true,
hasBacklightDimming: true,
cmdInit: "sudo chmod 666 /sys/class/backlight/rpi_backlight/bl_power /sys/class/backlight/rpi_backlight/brightness",
cmdBacklightOff: "sudo echo 1 > /sys/class/backlight/rpi_backlight/bl_power",
cmdBacklightOn: "sudo echo 0 > /sys/class/backlight/rpi_backlight/bl_power",
cmdBacklightDimming: "sudo echo %% >/sys/class/backlight/rpi_backlight/brightness",
};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
module.exports = screen;
}
21 changes: 21 additions & 0 deletions config/screens/hdmi_default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* settings for standard screen connected via HDMI
*
*/
var screen = {
name: "Standard HDMI screen",
xres: 1024,
yres: 600,
hasTouch: true,
hasBacklightCtl: true,
hasBacklightDimming: false,
cmdInit: "",
cmdBacklightOff: "tvservice -o",
cmdBacklightOn: "tvservice --preferred && sudo chvt 6 && sudo chvt 7",
cmdBacklightDimming: "",
};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
module.exports = screen;
}
16 changes: 12 additions & 4 deletions js/schedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ var schedule = require('node-schedule');
const exec = require("child_process").exec;

var schedules = class {
constructor(config, logger) {
constructor(config, screen, logger) {
this.turnOnHour = config.turnOnHour;
this.turnOffHour = config.turnOffHour;
this.screen = screen;
this.logger = logger;
this.opts = {timeout: 15000};
var self = this;

// initialize the monitor control if required
if(this.screen.cmdInit.length >0){
exec(this.screen.cmdInit , this.opts, function(error, stdout, stderr) {
self.checkForExecError(error, stdout, stderr);
});
}

//generate schedule for turning the monitor on
this.monitorOnSchedule = schedule.scheduleJob('* * ' + this.turnOnHour.toString() + ' * * *', function() {
self.turnMonitorOn();
Expand All @@ -26,15 +34,15 @@ var schedules = class {
//execute command for turning the monitor on
turnMonitorOn() {
var self = this;
exec("tvservice --preferred && sudo chvt 6 && sudo chvt 7", self.opts, function(error, stdout, stderr) {
exec(self.screen.cmdBacklightOn, self.opts, function(error, stdout, stderr) {
self.checkForExecError(error, stdout, stderr);
});
}

//execute command for turning the monitor off
turnMonitorOff() {
var self = this;
exec("tvservice -o", self.opts, function(error, stdout, stderr) {
var self = this;
exec(self.screen.cmdBacklightOff, self.opts, function(error, stdout, stderr) {
self.checkForExecError(error, stdout, stderr);
});
}
Expand Down
14 changes: 13 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
const { app, BrowserWindow, ipcMain } = require("electron");
const { logger, rendererLogger } = require("./js/logger");
const config = require("./config/config");

var myscreenConfig="";
if(config.hasOwnProperty("screenConfig"))
{
myscreenConfig = config.screenConfig;
}else{
myscreenConfig = "./config/screens/hdmi_default";
}
const screen = require(myscreenConfig);
logger.info("Configuring for: " + screen.name + " (" + myscreenConfig + ")");

const telebot = require("./js/bot");
const imagewatcher = require("./js/imageWatchdog");
const inputhandler = require("./js/inputHandler");
Expand All @@ -9,6 +20,7 @@ const schedules = require("./js/schedules");

//create global variables
global.config = config;
global.screen = screen;
global.rendererLogger = rendererLogger;
global.images = [];

Expand Down Expand Up @@ -67,7 +79,7 @@ function createWindow() {
// generate scheduler, when times for turning monitor off and on
// are given in the config file
if (config.toggleMonitor) {
var scheduler = new schedules(config, logger);
var scheduler = new schedules(config, screen, logger);
}

// Open the DevTools.
Expand Down

0 comments on commit d60384a

Please sign in to comment.