From c4de5372511fd6bb87a5f6dc6c32612feac56920 Mon Sep 17 00:00:00 2001 From: fscherwi Date: Fri, 29 Dec 2017 18:57:01 +0100 Subject: [PATCH] improvements --- src/weather.js | 86 +++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/src/weather.js b/src/weather.js index 9997e75..2261e0b 100644 --- a/src/weather.js +++ b/src/weather.js @@ -125,48 +125,56 @@ function error_output(code) { } } /* istanbul ignore next */ -exports.get = function tfget(HOST, PORT, WAIT, live) { - get_uid(HOST, PORT); - if (live) { +function simple(HOST, PORT, WAIT) { + setTimeout(function () { + tfinit(HOST, PORT); + ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED, + function () { + tfdata_get(); + } + ); setTimeout(function () { + console.log('\nRelative Humidity:\t' + output_data[0] + '\n' + + 'Air pressure:\t\t' + output_data[1] + '\n' + + 'Temperature:\t\t' + output_data[2] + '\n' + + 'Illuminance:\t\t' + output_data[3] + '\n' + + '\nTime:\t\t\t' + getTime(new Date()) + '\n'); ipcon.disconnect(); - tfinit(HOST, PORT); - }, 150); - setTimeout(function () { - process.stdin.on('data', - function () { - ipcon.disconnect(); - process.exit(); - } - ); + process.exit(0); + }, 10); + }, 25); +} +/* istanbul ignore next */ +function live(HOST, PORT, WAIT) { + setTimeout(function () { + ipcon.disconnect(); + tfinit(HOST, PORT); + }, 150); + setTimeout(function () { + process.stdin.on('data', + function () { + ipcon.disconnect(); + process.exit(); + } + ); + tfdata_get(); + setInterval(function () { tfdata_get(); - setInterval(function () { - tfdata_get(); - console.log('\033[2J'); - console.log('\nRelative Humidity:\t' + output_data[0] + '\n' + - 'Air pressure:\t\t' + output_data[1] + '\n' + - 'Temperature:\t\t' + output_data[2] + '\n' + - 'Illuminance:\t\t' + output_data[3] + '\n' + - '\nTime:\t\t\t' + getTime(new Date()) + '\n'); - }, WAIT); - }, 25); + console.log('\033[2J'); + console.log('\nRelative Humidity:\t' + output_data[0] + '\n' + + 'Air pressure:\t\t' + output_data[1] + '\n' + + 'Temperature:\t\t' + output_data[2] + '\n' + + 'Illuminance:\t\t' + output_data[3] + '\n' + + '\nTime:\t\t\t' + getTime(new Date()) + '\n'); + }, WAIT); + }, 25); +} +/* istanbul ignore next */ +exports.get = function tfget(HOST, PORT, WAIT, live) { + get_uid(HOST, PORT); + if (live) { + live(HOST, PORT, WAIT); } else { - setTimeout(function () { - tfinit(HOST, PORT); - ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED, - function () { - tfdata_get(); - } - ); - setTimeout(function () { - console.log('\nRelative Humidity:\t' + output_data[0] + '\n' + - 'Air pressure:\t\t' + output_data[1] + '\n' + - 'Temperature:\t\t' + output_data[2] + '\n' + - 'Illuminance:\t\t' + output_data[3] + '\n' + - '\nTime:\t\t\t' + getTime(new Date()) + '\n'); - ipcon.disconnect(); - process.exit(0); - }, 10); - }, 25); + simple(HOST, PORT, WAIT); } };