feat: verbose logging

This commit is contained in:
Mateusz Pstrucha committed 2021-10-21 01:31:59 +02:00
1 parent 7073aac85b
commit c94fa0a9b8
1 file changed
+7 -2
+7 -2
View File
@@ -1,6 +1,10 @@
import { spawn } from 'child_process'
import dotenv from 'dotenv'
const radio = spawn('python', ['modules/radio.py'])
dotenv.config()
const radio = spawn('python', ['modules/radio.py']),
verbose = Number(process.env.VERBOSE)
var busy = true,
waiting = []
@@ -10,7 +14,7 @@ radio.stdout.on('data', (data) => {
for (let line of lines) {
let [status, ...data] = JSON.parse(line)
console.log(' -> ', status, data)
verbose > 0 && console.log(' -> ', status, data)
if (status == 'waiting')
if (data[0]) {
@@ -31,6 +35,7 @@ radio.on('close', (code) => {
})
function sendCommand(comm, data = [null]) {
verbose > 1 && console.log(' <- ', comm, data)
busy = true
radio.stdin.write(JSON.stringify(['command', comm, ...data]) + '\n')
}