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";
|
"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(
|
||||||
|
|
Loading…
Reference in a new issue