Git Product home page Git Product logo

pigpio-mock's Issues

extend eventemitter

For me to use mock and to be compatible with pigpio which "inherts" event emitter and thus for use when mocking interrupts (which I am doing) your Gpio class should extend eventemitter. A simple change.

class Gpio extends EventEmitter {
  constructor(pin, options) {
    super()

pr to follow

Update on npm

would it be possible to update the version of pigpio-mock on npm?

pwmRange is not a function

It looks like the mock Gpio object uses a variable called "pwmRange" as well as a function called "pwmRange".

When the constructor is executed, the pwmRange variable replaces the pwmRange function of the Gpio object.

Sample code to demonstrate:

const Gpio = require( "pigpio-mock" ).Gpio;

PWM_FREQ = 50;
PWM_RANGE = 1000;

VAL_MIN = 10;
VAL_MAX = 100;

// Output the pwmRange value of the Gpio object prototype
// This should be (and is) the pwmRange function
console.log( "Gpio prototype pwmRange is:", Gpio.prototype.pwmRange );

// Create a Gpio (mock) object
const servo = new Gpio( 17, { mode: Gpio.OUTPUT } );

// Output the pwmRange value of a Gpio instance
// This *should* be a function, but it is actually the current pwmRange value (default=0)
console.log( "Gpio instance pwmRange is:", servo.pwmRange );

// Set PWM freq
servo.pwmFrequency( PWM_FREQ );

// This will fail because it is a function call on an integer value, rather than on the
// desired pwmRange function
servo.pwmRange( PWM_RANGE );

// Write some PWM values
servo.pwmWrite( VAL_MIN );
servo.pwmWrite( VAL_MAX );

A fix would probably be to change the internal pwmRange variable to include a prefix such as an underscore (e.g., _pwmrange) to separate it from the function with the same name.

initialize and terminate methods

Hello.

Congratulations by mock.

Can you implements initialize and terminate methods, for I can use your lib?

Or need I make a fork and implements it?

Pigpio.initialize() and Pigpio.terminate();

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.