Skip to content

Commit 6b8287d

Browse files
committed
screen.ts: sendAndWaitForAck() added
1 parent 14c64ce commit 6b8287d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

screen.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ namespace user_interface_base {
9494
// radio.onReceivedString((_: String) => { }); // Reset
9595
}
9696

97+
98+
public static sendAndWaitForAck(data: Buffer | String) {
99+
let received = false;
100+
radio.onReceivedString((s: String) => {
101+
// basic.showString("R")
102+
if (s == "ACK")
103+
received = true;
104+
})
105+
106+
107+
if (typeof data == "string")
108+
radio.sendString(data);
109+
else
110+
radio.sendBuffer(data as Buffer);
111+
112+
113+
let timePassed = 0;
114+
while (!received) {
115+
// if (timePassed % 100 == 0) {
116+
117+
// }
118+
// timePassed += 10;
119+
basic.pause(3)
120+
}
121+
122+
radio.onReceivedString((_: String) => { }); // Reset
123+
}
124+
97125
public static getBuffer(bitmap: Bitmap, chunkIndex: number, chunkSize: number): Buffer {
98126
const width = bitmap.width
99127
const startIndex = chunkIndex * chunkSize;
@@ -134,12 +162,12 @@ namespace user_interface_base {
134162
(bitmap.height * bitmap.width) / maxPacketBufferSize;
135163

136164
// Send bitmap size information:
137-
this.tryToSend("" + maxPacketBufferSize + "," + bitmap.width + "," + bitmap.height);
165+
this.sendAndWaitForAck("" + maxPacketBufferSize + "," + bitmap.width + "," + bitmap.height);
138166

139167
// Send a chunk of the bitmap and wait for ACK, RX will rebuild the bitmap:
140168
for (let j = 0; j < numberOfChunks; j++) {
141169
const rowBuffer = this.getBuffer(bitmap, j, maxPacketBufferSize);
142-
this.tryToSend(rowBuffer);
170+
this.sendAndWaitForAck(rowBuffer);
143171
}
144172
this.bitmapCache.push(bitmap);
145173
}

0 commit comments

Comments
 (0)