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

46 lines
766 B
JavaScript
Raw Normal View History

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