1
0
Fork 0
mirror of https://github.com/kou029w/megabit.git synced 2025-01-30 21:58:04 +00:00

feat: ssd1306

This commit is contained in:
Nebel 2020-02-20 09:22:45 +09:00
parent ef614003f9
commit 9a5942e31b

30
src/ssd1306.ts Normal file
View 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;