1
0
Fork 0
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:
Martijn de Boer 2018-07-03 19:39:50 +02:00
parent 13961a2f8e
commit c5a169729d
6 changed files with 3752 additions and 2605 deletions

View file

@ -21,6 +21,10 @@ Navigate to http://localhost:8080/
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
This application has some unit tests, making use of [Jest](http://facebook.github.io/jest/). Jest is configured as a dev dependency.

View file

@ -5,6 +5,7 @@ let { DriverFactory } = require( '../drivers/driverfactory' );
let { Dummy } = require( '../drivers/dummy' );
let { PimoroniUnicorn } = require( '../drivers/pimoroniunicorn' );
let { MotionJPEG } = require( '../drivers/motionjpeg' );
beforeEach(() => {
driverFactory = new DriverFactory();
@ -37,3 +38,12 @@ test( 'Pimoroni Unicorn driver to be properly created', () => {
expect( driver ).toBeInstanceOf( PimoroniUnicorn );
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();
} );

View file

@ -25,6 +25,11 @@ class DriverFactory {
driver = new PimoroniUnicorn();
break;
case 'motionjpeg':
let { MotionJPEG } = require( './motionjpeg' );
driver = new MotionJPEG();
break;
}
driver.setSize( config.matrix.width, config.matrix.height );

50
drivers/motionjpeg.js Normal file
View 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;

6260
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -7,14 +7,16 @@
},
"license": "MIT",
"dependencies": {
"jpeg-js": "^0.3.4",
"mjpeg-server": "^0.3.0",
"pi-spi": "^1.0.2",
"restify": "^6.3.4",
"vm2": "^3.5.2"
"restify": "^6.4.0",
"vm2": "^3.6.1"
},
"devDependencies": {
"eslint": "^4.15.0",
"eslint": "^4.19.1",
"eslint-plugin-security": "^1.4.0",
"jest": "^22.0.4"
"jest": "^22.4.4"
},
"scripts": {
"test": "jest",