From 304c0228288754d7e1b63099262b0eb82d224ab0 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Thu, 5 Oct 2023 23:34:03 +0300 Subject: [PATCH] Bump version to 0.2.13 --- package.json | 2 +- thermostat.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8e96d73..09501fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vvzvlad/node-red-contrib-rn-combined-nodes", - "version": "0.2.12", + "version": "0.2.13", "description": "", "main": "index.js", "keywords": [ diff --git a/thermostat.js b/thermostat.js index d7bd146..3387dd1 100644 --- a/thermostat.js +++ b/thermostat.js @@ -12,20 +12,22 @@ module.exports = function(RED) { let debug = "" let pwm_timer = null; - context.set("pwm_period", 10000); // 10 секунд - context.set("pwm_tick", 1000); // 1 секунда + context.set("pwm_period", 10000); // 10 seconds + context.set("pwm_tick", 1000); // 1 second function manage_pwm(duty_cycle_percent) { if (duty_cycle_percent === -1) { if (pwm_timer !== null) { clearInterval(pwm_timer); pwm_timer = null; + node.log("PWM stopped"); } return; } const pwm_duty_cycle = Math.max(0, Math.min(1, duty_cycle_percent / 100)); context.set("pwm_duty_cycle", pwm_duty_cycle); + node.log(`PWM duty cycle set to ${pwm_duty_cycle}`); if (pwm_timer === null) { let cycle_start_time = Date.now(); @@ -33,8 +35,11 @@ module.exports = function(RED) { pwm_timer = setInterval(() => { const pwm_period = context.get("pwm_period"); + const pwm_duty_cycle = context.get("pwm_duty_cycle"); // Retrieve each time const elapsed_time = Date.now() - cycle_start_time; - const on_time = pwm_period * context.get("pwm_duty_cycle"); + const on_time = pwm_period * pwm_duty_cycle; + + node.log(`Elapsed: ${elapsed_time}, On Time: ${on_time}`); if (elapsed_time >= pwm_period) { cycle_start_time = Date.now(); @@ -42,8 +47,10 @@ module.exports = function(RED) { if (elapsed_time < on_time) { node.send([null, { payload: 1 }]); + console.log("Sending 1"); } else { node.send([null, { payload: 0 }]); + console.log("Sending 0"); } }, pwm_tick); @@ -51,6 +58,7 @@ module.exports = function(RED) { } + function debug_text(text) { if (text === "return_debug") { let debug_tmp = debug