Changed interface switching to use .env
This commit is contained in:
parent
c01e18c644
commit
a59dd3fe6f
@ -1,21 +1,21 @@
|
||||
const { exec } = require('child_process');
|
||||
const config = require('./config.json');
|
||||
let gpioScript = new String();
|
||||
|
||||
if (process.env.GPIO_MODE === 'EMULATED') {
|
||||
gpioScript = 'src/python/fake_gpio_interface.py';
|
||||
} else if (process.env.GPIO_MODE === 'PHYSICAL') {
|
||||
gpioScript = 'src/python/gpio_interface.py';
|
||||
} else {
|
||||
throw new Error('GPIO_MODE environment variable not set');
|
||||
}
|
||||
|
||||
console.log(`GPIO_MODE: ${process.env.GPIO_MODE}`);
|
||||
|
||||
module.exports = {
|
||||
// Calls the GPIO Interface script to toggle a pin's state opposite of its current state
|
||||
// togglePin(pin) {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// exec(`python3 ${config.gpioScript} toggle ${pin}`, (error, stdout, stderr) => {
|
||||
// if (error) reject(error);
|
||||
// if (stderr) reject(new Error(stderr));
|
||||
// resolve();
|
||||
// });
|
||||
// });
|
||||
// },
|
||||
// Calls the GPIO Interface script to read a pin's state
|
||||
readPin(pin) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`python3 ${config.gpioScript} read ${pin}`, (error, stdout, stderr) => {
|
||||
exec(`python3 ${gpioScript} read ${pin}`, (error, stdout, stderr) => {
|
||||
if (error) reject(error);
|
||||
if (stderr) reject(new Error(stderr));
|
||||
resolve(stdout.trim());
|
||||
@ -25,7 +25,7 @@ module.exports = {
|
||||
// Calls the GPIO Interface script to set a pin's state regardless of its current state
|
||||
setPin(pin, state) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`python3 ${config.gpioScript} set ${pin} ${state}`, (error, stdout, stderr) => {
|
||||
exec(`python3 ${gpioScript} set ${pin} ${state}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***************************************************************************************/
|
||||
// Import modules
|
||||
/***************************************************************************************/
|
||||
const dotenv = require('dotenv');
|
||||
dotenv.config();
|
||||
const gpio = require('./custom_modules/VoidGPIO.js');
|
||||
const config = require('./custom_modules/config.json');
|
||||
const fn = require('./custom_modules/functions.js');
|
||||
|
Loading…
Reference in New Issue
Block a user