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:
parent
0434fb6b1a
commit
1a7c836ce6
1 changed files with 12 additions and 6 deletions
|
@ -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;
|
||||
|
||||
if ( this.spi === false) {
|
||||
if ( fs.existsSync( this.spiPath ) ) {
|
||||
let SPI = require( 'pi-spi' );
|
||||
this.spi = SPI.initialize( '/dev/spidev0.0' );
|
||||
this.spi = SPI.initialize( this.spiPath );
|
||||
} else {
|
||||
console.warn( 'Device path ' + this.spiPath + ' was unavailable.' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.spi.write(
|
||||
|
|
Loading…
Reference in a new issue