2017-12-12 20:41:32 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
let { Driver } = require( './driver' );
|
|
|
|
|
2017-12-18 20:39:51 +01:00
|
|
|
class PimoroniUnicorn extends Driver {
|
2017-12-12 20:41:32 +01:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2018-01-05 19:43:39 +01:00
|
|
|
this.initializedSpi = false;
|
2017-12-12 20:41:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
write( buffer ) {
|
2018-01-05 19:43:39 +01:00
|
|
|
if ( this.initializedSpi !== true ) {
|
|
|
|
this.initializedSpi = true;
|
|
|
|
|
|
|
|
let SPI = require( 'pi-spi' );
|
|
|
|
this.spi = SPI.initialize( '/dev/spidev0.0' );
|
|
|
|
}
|
|
|
|
|
2017-12-12 20:41:32 +01:00
|
|
|
this.spi.write(
|
|
|
|
Buffer.concat(
|
|
|
|
[ new Buffer( [ 0x72 ] ),
|
|
|
|
buffer ]
|
|
|
|
),
|
|
|
|
|
|
|
|
function ( err ) {
|
|
|
|
if ( err ) {
|
|
|
|
throw 'Failed writing buffer';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 20:39:51 +01:00
|
|
|
exports.PimoroniUnicorn = PimoroniUnicorn;
|