mirror of
https://github.com/kou029w/megabit.git
synced 2025-01-30 21:58:04 +00:00
feat: ssd1306
This commit is contained in:
parent
ef614003f9
commit
9a5942e31b
1 changed files with 30 additions and 0 deletions
30
src/ssd1306.ts
Normal file
30
src/ssd1306.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import Device from "@chirimen/grove-oled-display";
|
||||||
|
import { WritableDevice } from "./Device";
|
||||||
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
|
export function ssd1306(
|
||||||
|
bus: I2C = i2c(),
|
||||||
|
address: number = 0x3c
|
||||||
|
): WritableDevice<boolean | number | string> {
|
||||||
|
const device = new Device(bus, address);
|
||||||
|
|
||||||
|
return {
|
||||||
|
/** @param value Object to be output */
|
||||||
|
async write(value: boolean | number | string): Promise<void> {
|
||||||
|
if (device.i2cSlave == null) {
|
||||||
|
await device.init(true);
|
||||||
|
}
|
||||||
|
await device.clearDisplay();
|
||||||
|
const messages =
|
||||||
|
typeof value === "string"
|
||||||
|
? value.split("\n")
|
||||||
|
: JSON.stringify(value, null, " ").split("\n");
|
||||||
|
messages.forEach((message, index) => {
|
||||||
|
device.drawStringQ(index, 0, message);
|
||||||
|
});
|
||||||
|
await device.playSequence();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ssd1308;
|
Loading…
Add table
Reference in a new issue