Bump version to 0.2.14

This commit is contained in:
vvzvlad 2023-10-05 23:41:35 +03:00
parent 304c022828
commit 19b19157a0
2 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@vvzvlad/node-red-contrib-rn-combined-nodes", "name": "@vvzvlad/node-red-contrib-rn-combined-nodes",
"version": "0.2.13", "version": "0.2.14",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [

View File

@ -11,7 +11,9 @@ module.exports = function(RED) {
const HEAT_OFF_THRESHOLD = 0.2 const HEAT_OFF_THRESHOLD = 0.2
let debug = "" let debug = ""
let pwm_timer = null; let pwm_timer = null;
let last_state = null;
context.set("pwm_period", 10000); // 10 seconds context.set("pwm_period", 10000); // 10 seconds
context.set("pwm_tick", 1000); // 1 second context.set("pwm_tick", 1000); // 1 second
@ -20,6 +22,7 @@ module.exports = function(RED) {
if (pwm_timer !== null) { if (pwm_timer !== null) {
clearInterval(pwm_timer); clearInterval(pwm_timer);
pwm_timer = null; pwm_timer = null;
last_state = null;
node.log("PWM stopped"); node.log("PWM stopped");
} }
return; return;
@ -35,7 +38,7 @@ module.exports = function(RED) {
pwm_timer = setInterval(() => { pwm_timer = setInterval(() => {
const pwm_period = context.get("pwm_period"); const pwm_period = context.get("pwm_period");
const pwm_duty_cycle = context.get("pwm_duty_cycle"); // Retrieve each time const pwm_duty_cycle = context.get("pwm_duty_cycle");
const elapsed_time = Date.now() - cycle_start_time; const elapsed_time = Date.now() - cycle_start_time;
const on_time = pwm_period * pwm_duty_cycle; const on_time = pwm_period * pwm_duty_cycle;
@ -45,12 +48,12 @@ module.exports = function(RED) {
cycle_start_time = Date.now(); cycle_start_time = Date.now();
} }
if (elapsed_time < on_time) { let current_state = elapsed_time < on_time ? 1 : 0;
node.send([null, { payload: 1 }]);
console.log("Sending 1"); if (current_state !== last_state) {
} else { node.send([null, { payload: current_state }]);
node.send([null, { payload: 0 }]); node.log(`Sending ${current_state}`);
console.log("Sending 0"); last_state = current_state;
} }
}, pwm_tick); }, pwm_tick);
@ -59,6 +62,7 @@ module.exports = function(RED) {
function debug_text(text) { function debug_text(text) {
if (text === "return_debug") { if (text === "return_debug") {
let debug_tmp = debug let debug_tmp = debug