Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit 9dbda44

Browse files
committed
updated sample/multi support in lcd
1 parent c2673e4 commit 9dbda44

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

packages/drivers/src/grovergblcd.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,31 @@ export class GroveRGBLCD extends I2CDriver {
148148

149149
async render(message: string) {
150150
await this.clear()
151-
if (message?.length > 0)
151+
if (message?.length > 0) {
152+
let col = 0
153+
let row = 0
152154
for (let i = 0; i < message.length; ++i) {
153-
await this.write(message.charCodeAt(i))
155+
const c = message.charCodeAt(i)
156+
if (c === 10) { // \n
157+
col = 0
158+
row += 1
159+
await this.newLine(col, row)
160+
}
161+
else if (c === 13) {
162+
// skip
163+
} else {
164+
// in bounds
165+
if (col < this.columns && row < this.lines)
166+
await this.write(c)
167+
col += 1
168+
}
154169
}
170+
}
171+
}
172+
173+
private async newLine(col: number, row: number) {
174+
col = row === 0 ? col | 0x80 : col | 0xc0
175+
await this.writeBuf(Buffer.from([0x80, col]))
155176
}
156177
}
157178

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import "@dsboard/seeed_xiao_esp32c3"
2-
import * as ds from "@devicescript/core"
31
import {
4-
XiaoGroveShield,
52
startGroveRGBLCD16x2,
63
startBME680,
4+
XiaoGroveShield,
75
} from "@devicescript/drivers"
6+
import { ValueDashboard } from "@devicescript/runtime"
7+
8+
const shield = new XiaoGroveShield()
9+
const { temperature, humidity } = await startBME680({
10+
address: 0x76,
11+
})
12+
const screen = await startGroveRGBLCD16x2()
813

9-
const board = new XiaoGroveShield()
14+
const dashboard = new ValueDashboard(screen, {
15+
temp: { digits: 1, unit: "C" },
16+
humi: { digits: 0, unit: "%" },
17+
})
1018

11-
const { temperature } = await startBME680()
12-
const lcd = await startGroveRGBLCD16x2()
1319
setInterval(async () => {
14-
const temp = Math.round(await temperature.reading.read())
15-
await lcd.message.write(`temp: ${temp}C`)
20+
dashboard.values.temp = await temperature.reading.read()
21+
dashboard.values.humi = await humidity.reading.read()
22+
await dashboard.show()
1623
}, 1000)
51.9 KB
Loading

0 commit comments

Comments
 (0)