1
0
Fork 0
mirror of https://github.com/sexybiggetje/pixdisp.git synced 2024-11-25 01:21:03 +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";
let { Driver } = require( './driver' );
let fs = require( 'fs' );
class PimoroniUnicorn extends Driver {
constructor() {
super();
this.initializedSpi = false;
this.spi = false;
this.spiPath = '/dev/spidev0.0';
}
write( buffer ) {
if ( this.initializedSpi !== true ) {
this.initializedSpi = true;
let SPI = require( 'pi-spi' );
this.spi = SPI.initialize( '/dev/spidev0.0' );
if ( this.spi === false) {
if ( fs.existsSync( this.spiPath ) ) {
let SPI = require( 'pi-spi' );
this.spi = SPI.initialize( this.spiPath );
} else {
console.warn( 'Device path ' + this.spiPath + ' was unavailable.' );
return;
}
}
this.spi.write(