Bump version to 0.2.13
This commit is contained in:
parent
74f15fe9c3
commit
304c022828
@ -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": [
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user