From 4d682ae984aab9ac628d2bcd559618761449e6ca Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 6 Dec 2022 00:05:35 -0500 Subject: [PATCH] Adding new gpio assignments --- .vscode/pssnippets.code-snippets | 25 +++++++++++++++ functions.js | 52 ++++++++++++++++++++++++++++---- main.js | 9 ++++++ package.json | 2 +- 4 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 .vscode/pssnippets.code-snippets diff --git a/.vscode/pssnippets.code-snippets b/.vscode/pssnippets.code-snippets new file mode 100644 index 0000000..0408c76 --- /dev/null +++ b/.vscode/pssnippets.code-snippets @@ -0,0 +1,25 @@ +{ + // Place your pscontrolpanel workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and + // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope + // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is + // used to trigger the snippet and the body will be expanded and inserted. Possible variables are: + // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. + // Placeholders with the same ids are connected. + // Example: + // "Print to console": { + // "scope": "javascript,typescript", + // "prefix": "log", + // "body": [ + // "console.log('$1');", + // "$2" + // ], + // "description": "Log output to console" + // } + + "Log if in Debug mode": { + "scope": "javascript", + "prefix": "log", + "body": "if (process.env.DEBUG == 'true') console.log('$1');\n$0", + "description": "Log output to console if in debug mode" + } +} \ No newline at end of file diff --git a/functions.js b/functions.js index ce59f1d..c273d6a 100644 --- a/functions.js +++ b/functions.js @@ -1,3 +1,11 @@ +// Physical Pin numbers for GPIO +const augerPin = 7; // Pin for controlling the relay for the pellet auger motor. +const igniterPin = 13; // Pin for controlling the relay for the igniter. +const blowerPin = 15; // Pin for controlling the relay for the combustion blower/exhaust. +const pofPin = 16; // Pin for sensing the status (open/closed) of the Proof of Fire switch. +const tempPin = 18; // Pin for receiving data from a DS18B20 OneWire temperature sensor. +const vacuumPin = 22; // Pin for sensing the status (open/closed) of the vacuum switch. + // Get environment variables const dotenv = require('dotenv').config(); // Module for working with files @@ -140,7 +148,7 @@ const functions = { process.exit(); }, }, - // Sleeps for any given milliseconds, call with await + // Sleeps for any given milliseconds sleep(ms) { return new Promise((resolve) => { if (process.env.DEBUG == "true") console.log(`Sleeping for ${ms}ms`); @@ -157,14 +165,46 @@ const functions = { init(gpio) { return new Promise((resolve, reject) => { // Write the current env vars to console - console.log('Environment variables:'); - console.log(`ONTIME=${process.env.ONTIME}\nOFFTIME=${process.env.OFFTIME}\nPAUSETIME=${process.env.PAUSETIME}\nDEBUG=${process.env.DEBUG}\nONPI=${process.env.ONPI}`); + console.log(`Environment variables:\n + ONTIME=${process.env.ONTIME}\n + OFFTIME=${process.env.OFFTIME}\n + PAUSETIME=${process.env.PAUSETIME}\n + DEBUG=${process.env.DEBUG}\n + ONPI=${process.env.ONPI} + `); // Set up GPIO 4 (pysical pin 7) as output, then call functions.auger.ready() if (process.env.ONPI == 'true') { - gpio.setup(7, gpio.DIR_OUT, (err) => { + // Init the Auger pin + gpio.setup(augerPin, gpio.DIR_OUT, (err) => { if (err) reject(err); - // Resolve the promise - resolve('GPIO Initialized'); + if (process.env.DEBUG == 'true') console.log('Auger pin initialized.'); + // Init the igniter pin + gpio.setup(igniterPin, gpio.DIR_OUT, (err) => { + if (err) reject(err); + if (process.env.DEBUG == 'true') console.log('Igniter pin initialized.'); + // Init the blower pin + gpio.setup(blowerPin, gpio.DIR_OUT, (err) => { + if (err) reject(err); + if (process.env.DEBUG == 'true') console.log('Combustion blower pin initialized.'); + // Init the Proof of Fire pin + gpio.setup(pofPin, gpio.DIR_IN, (err) => { + if (err) reject(err); + if (process.env.DEBUG == 'true') console.log('Proof of Fire pin initialized.'); + // Init the Temp Sensor pin + gpio.setup(tempPin, gpio.DIR_IN, (err) => { + if (err) reject(err); + if (process.env.DEBUG == 'true') console.log('Temperature pin initialized.'); + // Init the Vacuum Switch pin + gpio.setup(vacuumPin, gpio.DIR_IN, (err) => { + if (err) reject(err); + if (process.env.DEBUG == 'true') console.log('Vacuum Switch pin initialized.'); + // Resolve the promise now that all pins have been initialized + resolve('GPIO Initialized.'); + }); + }); + }); + }); + }); }); } else { // Resolve the promise diff --git a/main.js b/main.js index 0a791f6..2cd16b9 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,12 @@ +/* Pellet Stove Control Panel + * Written by Skylar Grant + * v0.2.0 + * + * TODO: + * Add logic for other sensors + * More documentation? + */ + // Custom functions module to keep main script clean const fn = require('./functions.js').functions; diff --git a/package.json b/package.json index 0922555..e47ccd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pscontrolpanel", - "version": "0.1.0", + "version": "0.2.0", "requires": true, "packages": {}, "dependencies": {