deepsyx / pigpio-mock Goto Github PK
View Code? Open in Web Editor NEWPackage used for locally developing node apps with pigpio.
Package used for locally developing node apps with pigpio.
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
would it be possible to update the version of pigpio-mock on npm?
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.