1
0
Fork 0
mirror of https://github.com/sexybiggetje/pixdisp.git synced 2024-11-14 23:31:02 +01:00
pixdisp/drivers/pimoroniunicorn.js

46 lines
No EOL
766 B
JavaScript

'use strict';
let { Driver } = require( './driver' );
let fs = require( 'fs' );
class PimoroniUnicorn extends Driver {
constructor() {
super();
this.spi = false;
}
write( buffer = false ) {
if ( this.spi === false) {
if ( fs.existsSync( '/dev/spidev0.0' ) ) {
let SPI = require( 'pi-spi' );
this.spi = SPI.initialize( '/dev/spidev0.0' );
} else {
console.warn( 'Device path \'/dev/spidev0.0\' was unavailable.' );
return;
}
}
if ( buffer === false ) {
buffer = this.getBuffer();
}
this.spi.write(
Buffer.concat(
[
new Buffer( [ 0x72 ] ),
buffer
]
),
function ( err ) {
if ( err ) {
throw 'Failed writing buffer';
}
}
);
}
}
exports.PimoroniUnicorn = PimoroniUnicorn;