sendTextToFrame method
create the TextSpriteBlock for the specified text, then send the TSB header and line sprites one by one
Implementation
Future<void> sendTextToFrame(String text) async {
if (text.isEmpty) {
// just send a Clear Display message
await frame!.sendMessage(TxCode(msgCode: 0x10));
return;
}
var tsb = TxTextSpriteBlock(
msgCode: 0x20,
width: 620,
fontSize: _textSizeValues[_textSizeIndex],
maxDisplayRows: 10,
textDirection: _textDir,
textAlign: TextAlign.start,
text: text,
);
// rasterize the text to sprites
await tsb.rasterize(startLine: 0, endLine: tsb.numLines - 1);
// send the TxTextSpriteBlock lines to Frame for display
// block header first
await frame!.sendMessage(tsb);
// send over the lines one by one
// note that the sprites have the same message code, so they need to be handled by the text_sprite_block parser
for (var sprite in tsb.rasterizedSprites) {
await frame!.sendMessage(sprite);
}
}