diff --git a/packages/drivers/src/grovergblcd.ts b/packages/drivers/src/grovergblcd.ts index c0caa823a1..307f7f2037 100644 --- a/packages/drivers/src/grovergblcd.ts +++ b/packages/drivers/src/grovergblcd.ts @@ -148,10 +148,31 @@ export class GroveRGBLCD extends I2CDriver { async render(message: string) { await this.clear() - if (message?.length > 0) + if (message?.length > 0) { + let col = 0 + let row = 0 for (let i = 0; i < message.length; ++i) { - await this.write(message.charCodeAt(i)) + const c = message.charCodeAt(i) + if (c === 10) { // \n + col = 0 + row += 1 + await this.newLine(col, row) + } + else if (c === 13) { + // skip + } else { + // in bounds + if (col < this.columns && row < this.lines) + await this.write(c) + col += 1 + } } + } + } + + private async newLine(col: number, row: number) { + col = row === 0 ? col | 0x80 : col | 0xc0 + await this.writeBuf(Buffer.from([0x80, col])) } } diff --git a/packages/sampleprj/src/maingrovelcd16x2.ts b/packages/sampleprj/src/maingrovelcd16x2.ts index d1386ddd8a..1ee70e2fe9 100644 --- a/packages/sampleprj/src/maingrovelcd16x2.ts +++ b/packages/sampleprj/src/maingrovelcd16x2.ts @@ -1,16 +1,23 @@ -import "@dsboard/seeed_xiao_esp32c3" -import * as ds from "@devicescript/core" import { - XiaoGroveShield, startGroveRGBLCD16x2, startBME680, + XiaoGroveShield, } from "@devicescript/drivers" +import { ValueDashboard } from "@devicescript/runtime" + +const shield = new XiaoGroveShield() +const { temperature, humidity } = await startBME680({ + address: 0x76, +}) +const screen = await startGroveRGBLCD16x2() -const board = new XiaoGroveShield() +const dashboard = new ValueDashboard(screen, { + temp: { digits: 1, unit: "C" }, + humi: { digits: 0, unit: "%" }, +}) -const { temperature } = await startBME680() -const lcd = await startGroveRGBLCD16x2() setInterval(async () => { - const temp = Math.round(await temperature.reading.read()) - await lcd.message.write(`temp: ${temp}C`) + dashboard.values.temp = await temperature.reading.read() + dashboard.values.humi = await humidity.reading.read() + await dashboard.show() }, 1000) diff --git a/website/static/img/samples/lcd-sims.png b/website/static/img/samples/lcd-sims.png new file mode 100644 index 0000000000..e8c8bb805c Binary files /dev/null and b/website/static/img/samples/lcd-sims.png differ