Skip to content

Commit

Permalink
updated sample/multi support in lcd
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Oct 9, 2023
1 parent c2673e4 commit 9dbda44
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
25 changes: 23 additions & 2 deletions packages/drivers/src/grovergblcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
}
}

Expand Down
23 changes: 15 additions & 8 deletions packages/sampleprj/src/maingrovelcd16x2.ts
Original file line number Diff line number Diff line change
@@ -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)
Binary file added website/static/img/samples/lcd-sims.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9dbda44

Please sign in to comment.