2022-04-22 13:53:26 -05:00
import { openSync } from 'i2c-bus' ;
2022-04-19 21:02:08 -05:00
import Oled from 'oled-i2c-bus' ;
2022-04-22 13:53:26 -05:00
import font from 'oled-font-5x7' ;
2022-04-19 21:02:08 -05:00
import { MenuConfig , MenuPrinter } from './interface' ;
/ * c o n s t i 2 c b u s = o p e n S y n c ( 1 ) ;
const opts = {
width : 128 ,
height : 64 ,
address : 0x3C ,
} ;
const oled = new Oled ( i2cbus , opts ) ;
oled . clearDisplay ( ) ;
oled . setCursor ( 1 , 1 ) ;
oled . writeString ( font , 1 , "This is a string I am writing to the screen" , 1 , true ) ;
oled . turnOffDisplay ( ) ; * /
export class OledPrinter implements MenuPrinter {
2022-04-22 13:53:26 -05:00
// private _path: number[] = [];
// private _selectedIndex: number = 0;
2022-04-19 21:02:08 -05:00
private _config : MenuConfig [ ] ;
2022-04-22 13:53:26 -05:00
// private _curMenu: MenuConfig[];
private _oled : Oled ;
2022-04-19 21:02:08 -05:00
constructor ( config : MenuConfig [ ] ) {
this . _config = config ;
2022-04-22 13:53:26 -05:00
// this._curMenu = config;
const i2cbus = openSync ( 1 ) ;
const opts = {
width : 128 ,
height : 64 ,
address : 0x3C ,
} ;
this . _oled = new Oled ( i2cbus , opts ) ;
this . _oled . clearDisplay ( ) ;
}
private printMenu ( ) : void {
this . _oled . writeString ( font , 1 , "how many lines does this display hold let's write a whole bunch of stuff with wrapping on and then count the number of lines" , 1 , true ) ;
2022-04-19 21:02:08 -05:00
}
2022-04-20 08:05:21 -05:00
public async getSelection ( ) : Promise < MenuConfig > {
2022-04-22 13:53:26 -05:00
return new Promise ( ( resolve ) = > {
this . printMenu ( ) ;
while ( true ) {
}
resolve ( this . _config [ 0 ] ) ;
} ) ;
2022-04-19 21:02:08 -05:00
}
}