mirror of
https://github.com/sexybiggetje/pixdisp.git
synced 2024-11-21 21:51:02 +01:00
Add simplistic motion jpeg driver, hardcoded addr/port
This commit is contained in:
parent
13961a2f8e
commit
c5a169729d
6 changed files with 3752 additions and 2605 deletions
|
@ -21,6 +21,10 @@ Navigate to http://localhost:8080/
|
||||||
|
|
||||||
Matrix driver & Unicorn Hat HD driver inspired by https://github.com/vesteraas/node-unicornhathd
|
Matrix driver & Unicorn Hat HD driver inspired by https://github.com/vesteraas/node-unicornhathd
|
||||||
|
|
||||||
|
JPEG encoding by https://github.com/eugeneware/jpeg-js
|
||||||
|
|
||||||
|
mjpeg-server by https://www.npmjs.com/package/mjpeg-server
|
||||||
|
|
||||||
### Unit tests
|
### Unit tests
|
||||||
This application has some unit tests, making use of [Jest](http://facebook.github.io/jest/). Jest is configured as a dev dependency.
|
This application has some unit tests, making use of [Jest](http://facebook.github.io/jest/). Jest is configured as a dev dependency.
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ let { DriverFactory } = require( '../drivers/driverfactory' );
|
||||||
|
|
||||||
let { Dummy } = require( '../drivers/dummy' );
|
let { Dummy } = require( '../drivers/dummy' );
|
||||||
let { PimoroniUnicorn } = require( '../drivers/pimoroniunicorn' );
|
let { PimoroniUnicorn } = require( '../drivers/pimoroniunicorn' );
|
||||||
|
let { MotionJPEG } = require( '../drivers/motionjpeg' );
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
driverFactory = new DriverFactory();
|
driverFactory = new DriverFactory();
|
||||||
|
@ -36,4 +37,13 @@ test( 'Pimoroni Unicorn driver to be properly created', () => {
|
||||||
|
|
||||||
expect( driver ).toBeInstanceOf( PimoroniUnicorn );
|
expect( driver ).toBeInstanceOf( PimoroniUnicorn );
|
||||||
expect( driver.write( driver.getBuffer() ) ).toBeUndefined();
|
expect( driver.write( driver.getBuffer() ) ).toBeUndefined();
|
||||||
|
} );
|
||||||
|
|
||||||
|
test( 'MotionJPEG driver to be properly created', () => {
|
||||||
|
config.driver = "motionjpeg";
|
||||||
|
|
||||||
|
let driver = driverFactory.createFromConfig( config );
|
||||||
|
|
||||||
|
expect( driver ).toBeInstanceOf( MotionJPEG );
|
||||||
|
expect( driver.write( driver.getBuffer() ) ).toBeUndefined();
|
||||||
} );
|
} );
|
|
@ -25,6 +25,11 @@ class DriverFactory {
|
||||||
driver = new PimoroniUnicorn();
|
driver = new PimoroniUnicorn();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'motionjpeg':
|
||||||
|
let { MotionJPEG } = require( './motionjpeg' );
|
||||||
|
driver = new MotionJPEG();
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
driver.setSize( config.matrix.width, config.matrix.height );
|
driver.setSize( config.matrix.width, config.matrix.height );
|
||||||
|
|
50
drivers/motionjpeg.js
Normal file
50
drivers/motionjpeg.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
let { Driver } = require( './driver' );
|
||||||
|
let fs = require( 'fs' );
|
||||||
|
let http = require( 'http' );
|
||||||
|
let mjpegServer = require( 'mjpeg-server' );
|
||||||
|
let jpeg = require( 'jpeg-js' );
|
||||||
|
|
||||||
|
let mjpegReqHandler = undefined;
|
||||||
|
|
||||||
|
class MotionJPEG extends Driver {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.httpServer = http.createServer( function( req, res ) {
|
||||||
|
mjpegReqHandler = mjpegServer.createReqHandler( req, res );
|
||||||
|
} ).listen( 8081, '0.0.0.0' );
|
||||||
|
}
|
||||||
|
|
||||||
|
write( buffer = false ) {
|
||||||
|
if ( mjpegReqHandler === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = new Buffer( this.width * this.height * 4 );
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
let size = this.getSize();
|
||||||
|
|
||||||
|
for ( let y = 0; y < size.height; y++ ) {
|
||||||
|
for ( let x = 0; x < size.width; x++ ) {
|
||||||
|
buffer[ i++ ] = this.matrix[ x ][ y ].r * this.matrix[ x ][ y ].a * this.brightness;
|
||||||
|
buffer[ i++ ] = this.matrix[ x ][ y ].g * this.matrix[ x ][ y ].a * this.brightness;
|
||||||
|
buffer[ i++ ] = this.matrix[ x ][ y ].b * this.matrix[ x ][ y ].a * this.brightness;
|
||||||
|
buffer[ i++ ] = 0xFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var imageData = {
|
||||||
|
data: buffer,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
};
|
||||||
|
|
||||||
|
var dt = jpeg.encode( imageData, 50 );
|
||||||
|
mjpegReqHandler.write( dt.data );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.MotionJPEG = MotionJPEG;
|
6278
package-lock.json
generated
6278
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
@ -7,14 +7,16 @@
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"jpeg-js": "^0.3.4",
|
||||||
|
"mjpeg-server": "^0.3.0",
|
||||||
"pi-spi": "^1.0.2",
|
"pi-spi": "^1.0.2",
|
||||||
"restify": "^6.3.4",
|
"restify": "^6.4.0",
|
||||||
"vm2": "^3.5.2"
|
"vm2": "^3.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^4.15.0",
|
"eslint": "^4.19.1",
|
||||||
"eslint-plugin-security": "^1.4.0",
|
"eslint-plugin-security": "^1.4.0",
|
||||||
"jest": "^22.0.4"
|
"jest": "^22.4.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
|
|
Loading…
Reference in a new issue