From 6fc97805cff1f331ba09afffbd5dcb777c961640 Mon Sep 17 00:00:00 2001 From: dduransseau Date: Fri, 7 Jun 2024 00:51:05 +0200 Subject: [PATCH] Remove dependencies --- js-pigpio/_callback.js | 14 ++++++-------- js-pigpio/definitions.js | 3 +-- js-pigpio/utils.js | 14 +++++++------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/js-pigpio/_callback.js b/js-pigpio/_callback.js index af23feb..2fad757 100644 --- a/js-pigpio/_callback.js +++ b/js-pigpio/_callback.js @@ -3,10 +3,8 @@ const net = require('net'); const _pi_gpio_command = require('./utils.js')._pi_gpio_command; const _socklock = require('./utils.js')._socklock; const def = require('./definitions.js'); -const Put = require('put'); const reverse_string = require('./utils.js').reverse_string; const reverse_string_and_clean = require('./utils.js').reverse_string_and_clean; -const Set = require('es6-set'); const TIMEOUT = 2; @@ -334,12 +332,12 @@ class _callback_thread { this.run(); } stop () { - const cmd = Put() - .word32le(def.PI_CMD_NC) - .word32le(this.handle) - .word32le(0) - .word32le(0); - this.sl.s.write(cmd.buffer()); + const cmd = Buffer.alloc(16); // Crée un tampon de 16 octets + cmd.writeUInt32LE(def.PI_CMD_NC, 0); + cmd.writeUInt32LE(this.handle, 4); + cmd.writeUInt32LE(0, 8); + cmd.writeUInt32LE(0, 12); + this.sl.s.write(cmd); this.sl.s.close(); } diff --git a/js-pigpio/definitions.js b/js-pigpio/definitions.js index 579f454..e834937 100644 --- a/js-pigpio/definitions.js +++ b/js-pigpio/definitions.js @@ -1,9 +1,8 @@ /** * Translated from https://github.com/joan2937/pigpio/blob/master/pigpio.h */ -const define = require("node-constants")(exports); -define({ +module.exports = Object.freeze({ PI_CMD_MODES : 0, PI_CMD_MODEG : 1, PI_CMD_PUD : 2, diff --git a/js-pigpio/utils.js b/js-pigpio/utils.js index 31569da..4a56afe 100644 --- a/js-pigpio/utils.js +++ b/js-pigpio/utils.js @@ -1,4 +1,3 @@ -const Put = require('put'); const assert = require('assert'); exports.reverse_string_and_clean = function (str) { @@ -66,11 +65,12 @@ exports._socklock = _socklock; exports._pi_gpio_command = function(socketlock, command, parameter1, parameter2, next, wait_for_response) { "use strict"; assert(command !== undefined, "No command specified"); - const cmd = Put() - .word32le(command) - .word32le(parameter1) - .word32le(parameter2) - .word32le(0); + // console.log("Receviced _pi_gpio_command "+command+" | "+parameter1+" | "+parameter2) + const cmd = Buffer.alloc(16); // Crée un tampon de 16 octets + cmd.writeUInt32LE(command, 0); + cmd.writeUInt32LE(parameter1, 4); + cmd.writeUInt32LE(parameter2, 8); + cmd.writeUInt32LE(0, 12); socketlock._acquireLock(); @@ -78,7 +78,7 @@ exports._pi_gpio_command = function(socketlock, command, parameter1, parameter2, socketlock._next[command] = next; } - if(!socketlock.s.write(cmd.buffer())) { + if(!socketlock.s.write(cmd)) { next(new Error("Error Sending Command to Pi: "+command)); }