Skip to content

Commit

Permalink
Add support for DebugNode button
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphwetzel committed Nov 3, 2022
1 parent c68638d commit 1f6dd20
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions mcu_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ function get_require_path(req_path) {
// End: "Patch support ..."
// *****

// *****
// Make available the Node-RED typeRegistry

const typeRegistryPath = get_require_path("node_modules/@node-red/registry");
console.log(typeRegistryPath);
const typeRegistry = require(typeRegistryPath);

// *****
// Apply patch to get access to additional node related information
// This has to happen immediately when this file is required, before any Node-RED logic kicks in...
Expand Down Expand Up @@ -280,18 +287,41 @@ module.exports = function(RED) {
registerMCUModeType("inject", "__mcu*inject")

function mcu_debug(config) {
RED.nodes.createNode(this, config);
// console.log(config);

let node = this;
node.on('input', function(msg, send, done) {
let dn;

console.log("@mcu*debug", msg);
// Create a standard DebugNode
let debugNodeConstructor = typeRegistry.get("debug");
if (!debugNodeConstructor)
return;

});
dn = new debugNodeConstructor(config);

// patch the "active" property for getter & setter !
if (dn.active) {
dn._active = dn.active;
delete dn.active;
Object.defineProperty(dn, "active", {
get() {
return this._active;
},
set(status) {
this._active = status ? true : false;
if (this.__getProxy) {
let p = this.__getProxy();
if (p) {
p.send2mcu("debug", this.z, this.id, this._active);
}
}

}
})
}
return dn;
}
RED.nodes.registerType("__mcu*debug", mcu_debug);
registerMCUModeType("debug", "debug")
// registerMCUModeType("debug", "debug")
registerMCUModeType("debug", "__mcu*debug")

// End "Hook ..."
// *****
Expand Down Expand Up @@ -324,10 +354,12 @@ module.exports = function(RED) {
// console.log(config);

// replacement table NR=>MCU
/*
let replace = {
'inject': '__mcu*inject',
'debug': 'debug'
}
*/

/*
if (flows2build) {
Expand Down Expand Up @@ -1014,8 +1046,6 @@ module.exports = function(RED) {
console.log(`Type "${n.type}" = Node-RED core node: No manifest added.`);
}
return;
return;
return;

case "node-red-node-pi-gpio":
console.log(`Type "${n.type}" = node-red-mcu core node: No manifest added.`);
Expand Down

0 comments on commit 1f6dd20

Please sign in to comment.