1
0
Fork 0
mirror of https://github.com/sexybiggetje/pixdisp.git synced 2024-11-25 04:41:02 +01:00

Make Pimoroni Unicorn driver test the spiPath before executing the full write()

This commit is contained in:
Martijn de Boer 2018-01-05 21:51:33 +01:00
parent 0434fb6b1a
commit 1a7c836ce6

View file

@ -1,20 +1,26 @@
"use strict"; "use strict";
let { Driver } = require( './driver' ); let { Driver } = require( './driver' );
let fs = require( 'fs' );
class PimoroniUnicorn extends Driver { class PimoroniUnicorn extends Driver {
constructor() { constructor() {
super(); super();
this.initializedSpi = false; this.spi = false;
this.spiPath = '/dev/spidev0.0';
} }
write( buffer ) { write( buffer ) {
if ( this.initializedSpi !== true ) { if ( this.spi === false) {
this.initializedSpi = true; if ( fs.existsSync( this.spiPath ) ) {
let SPI = require( 'pi-spi' );
let SPI = require( 'pi-spi' ); this.spi = SPI.initialize( this.spiPath );
this.spi = SPI.initialize( '/dev/spidev0.0' ); } else {
console.warn( 'Device path ' + this.spiPath + ' was unavailable.' );
return;
}
} }
this.spi.write( this.spi.write(