Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependencies #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions js-pigpio/_callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
3 changes: 1 addition & 2 deletions js-pigpio/definitions.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
14 changes: 7 additions & 7 deletions js-pigpio/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const Put = require('put');
const assert = require('assert');

exports.reverse_string_and_clean = function (str) {
Expand Down Expand Up @@ -66,19 +65,20 @@ 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();

if (next !== undefined) {
socketlock._next[command] = next;
}

if(!socketlock.s.write(cmd.buffer())) {
if(!socketlock.s.write(cmd)) {
next(new Error("Error Sending Command to Pi: "+command));
}

Expand Down