pad serial.writeLine to the 32byte boundary (#676)

* pad writeline with zeros

* added padded for serial writline
This commit is contained in:
Peli de Halleux 2018-02-25 09:15:15 -08:00 committed by GitHub
parent bc886db97a
commit cc2d8b0b6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,14 @@ namespace serial {
//% help=serial/write-line blockGap=8
//% blockId=serial_writeline block="serial|write line %text"
export function writeLine(text: string): void {
writeString(text + "\r\n");
if (!text) text = "";
// pad data to the 32 byte boundary
// to ensure apps receive the packet
let r = (32 - (text.length + 2) % 32) % 32;
serial.writeString(text);
for (let i = 0; i < r; ++i)
serial.writeString(" ");
serial.writeString("\r\n");
}
/**
@ -34,7 +41,7 @@ namespace serial {
//% help=serial/write-value
//% blockId=serial_writevalue block="serial|write value %name|= %value"
export function writeValue(name: string, value: number): void {
writeString(name + ":" + value + "\r\n");
writeLine(name + ":" + value);
}
/**