-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
const stream = require('stream'); | ||
const EventEmitter = require('events').EventEmitter; | ||
// let lib = require('bindings')('vcd.node'); | ||
|
||
|
||
module.exports = async () => { | ||
|
||
const lib = require('../lib/wrapper.js')(); | ||
await lib.start(); | ||
|
||
const wires = {}; | ||
const info = {stack: [wires], wires: wires}; | ||
|
||
const s = new stream.Writable(); | ||
|
||
|
||
// gets called by c with 1 argument, a number | ||
const lifemit = s.emit.bind(s); | ||
|
||
const triee = new EventEmitter(); | ||
|
||
// gets called by c with 5 arguments | ||
// string eventName | ||
// number state->time | ||
// int command | ||
// int state->value | ||
// int state->mask | ||
|
||
const triemit = triee.emit.bind(triee); | ||
let triemit2 = triemit; | ||
|
||
const cxt = lib.init(lifemit, triemit, info); | ||
|
||
s._write = function (chunk, encoding, callback) { | ||
console.log('about to write', chunk); | ||
lib.execute(cxt, lifemit, triemit2, info, chunk); | ||
callback(); | ||
}; | ||
|
||
s.change = { | ||
on: (id, fn) => { | ||
triemit2 = triemit; | ||
triee.on(id, fn); | ||
const triggerString = triee.eventNames().join(' ') + ' '; | ||
lib.setTrigger(cxt, triggerString); | ||
}, | ||
any: fn => { | ||
triemit2 = fn; | ||
lib.setTrigger(cxt, '\0'); | ||
} | ||
}; | ||
|
||
s.info = info; | ||
|
||
s.getTime = () => lib.getTime(cxt); | ||
|
||
s.start = lib.start; | ||
|
||
return s; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters