mirror of
https://github.com/sexybiggetje/pixdisp.git
synced 2024-11-22 09:11:02 +01:00
Dynamically load display size from the driver to the canvas on app init
This commit is contained in:
parent
7c212e22ee
commit
0e5c06006e
3 changed files with 28 additions and 5 deletions
|
@ -2,9 +2,11 @@ NEEDS BETTER README!
|
||||||
|
|
||||||
Make sure you are on a recent nodejs version. Raspbian has old version. Use nodesource ;).
|
Make sure you are on a recent nodejs version. Raspbian has old version. Use nodesource ;).
|
||||||
|
|
||||||
|
copy config.example.json to config.json and pick a driver + display size.
|
||||||
|
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
node pixdisp.js
|
nodejs pixdisp.js
|
||||||
|
|
||||||
http://localhost:8080/
|
http://localhost:8080/
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,14 @@ class ApiController {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
|
|
||||||
this.server.post( { path: '/api/writecanvas' }, this.writecanvas.bind( this ) );
|
this.server.post( { path: '/api/writecanvas' }, this.writeCanvas.bind( this ) );
|
||||||
this.server.get( { path: '/api/write' }, this.write.bind( this ) );
|
this.server.get( { path: '/api/write' }, this.write.bind( this ) );
|
||||||
|
this.server.get( { path: '/api/getdisplaysize' }, this.getDisplaySize.bind( this ) );
|
||||||
this.server.get( { path: '/api/setpixel/:x/:y/:r/:g/:b' }, this.setPixel.bind( this ) );
|
this.server.get( { path: '/api/setpixel/:x/:y/:r/:g/:b' }, this.setPixel.bind( this ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writecanvas( request, resource, next ) {
|
writeCanvas( request, resource, next ) {
|
||||||
|
|
||||||
this.driver.clearMatrix();
|
this.driver.clearMatrix();
|
||||||
|
|
||||||
|
@ -45,6 +46,15 @@ class ApiController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDisplaySize( request, resource, next ) {
|
||||||
|
|
||||||
|
resource.setHeader( 'Access-Control-Allow-Origin', '*' );
|
||||||
|
|
||||||
|
resource.json( 200, this.driver.getSize() );
|
||||||
|
return next();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
setPixel( request, resource, next ) {
|
setPixel( request, resource, next ) {
|
||||||
|
|
||||||
resource.setHeader( 'Access-Control-Allow-Origin', '*' );
|
resource.setHeader( 'Access-Control-Allow-Origin', '*' );
|
||||||
|
|
|
@ -3,8 +3,19 @@
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
constructor() {
|
constructor() {
|
||||||
this.createCanvas(16,16);
|
let request = new XMLHttpRequest();
|
||||||
this.createPalette();
|
request.open( 'GET', '/api/getdisplaysize', true );
|
||||||
|
request.onload = this.onGetDisplaySizeFinished;
|
||||||
|
request.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
onGetDisplaySizeFinished() {
|
||||||
|
if ( this.status >= 200 && this.status < 400 ) {
|
||||||
|
let resp = JSON.parse( this.responseText );
|
||||||
|
|
||||||
|
app.createCanvas( resp.width, resp.height );
|
||||||
|
app.createPalette();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createCanvas( width, height ) {
|
createCanvas( width, height ) {
|
||||||
|
|
Loading…
Reference in a new issue