This repository has been archived on 2022-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
zeropod/src/menu/oled.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

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';
/*const i2cbus = openSync(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
}
}