@@ -70,33 +70,27 @@ namespace user_interface_base {
7070 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_SET_IMAGE_SIZE , width , height ] ) ) ;
7171 }
7272
73- public static waitForAck ( ) {
73+ public static tryToSend ( data : Buffer | String ) {
7474 let received = false ;
75- radio . onReceivedString ( ( _ : String ) => {
76- received = true ;
77- } )
78-
79- while ( ! received ) {
80- basic . pause ( 3 )
81- }
82- }
83-
84- public static tryToSend ( buf : Buffer ) {
85- let received = false ;
86- radio . onReceivedString ( ( _ : String ) => {
87- received = true ;
75+ radio . onReceivedString ( ( s : String ) => {
76+ if ( s == "ACK" )
77+ received = true ;
8878 } )
8979
9080 let timePassed = 0 ;
9181 while ( ! received ) {
92- if ( timePassed % 99 == 0 )
93- radio . sendBuffer ( buf ) ;
94- timePassed += 3 ;
95- basic . pause ( 3 )
82+ if ( timePassed % 99 == 0 ) {
83+ if ( typeof data == "string" ) {
84+ radio . sendString ( data ) ;
85+ } else {
86+ radio . sendBuffer ( data as Buffer ) ;
87+ }
88+ timePassed += 3 ;
89+ basic . pause ( 3 )
90+ }
9691 }
9792 }
9893
99-
10094 public static getBuffer ( bitmap : Bitmap , chunkIndex : number , chunkSize : number ) : Buffer {
10195 const width = bitmap . width
10296 const startIndex = chunkIndex * chunkSize ;
@@ -137,8 +131,7 @@ namespace user_interface_base {
137131 ( bitmap . height * bitmap . width ) / maxPacketBufferSize ;
138132
139133 // Send bitmap size information:
140- radio . sendString ( "" + maxPacketBufferSize + "," + bitmap . width + "," + bitmap . height ) ;
141- this . waitForAck ( ) ;
134+ this . tryToSend ( "" + maxPacketBufferSize + "," + bitmap . width + "," + bitmap . height ) ;
142135
143136 // Send a chunk of the bitmap and wait for ACK, RX will rebuild the bitmap:
144137 for ( let j = 0 ; j < numberOfChunks ; j ++ ) {
@@ -155,9 +148,6 @@ namespace user_interface_base {
155148 public static drawTransparentImage ( from : Bitmap , x : number , y : number ) {
156149 for ( let i = 0 ; i < this . bitmapCache . length ; i ++ ) {
157150 if ( this . bitmapCache [ i ] == from ) {
158- // radio.sendBuffer(Buffer.fromArray([SCREEN_FN_ID_DRAW_TRANSPARENT_IMAGE, i, x, y]));
159- // this.waitForAck();
160-
161151 this . tryToSend ( Buffer . fromArray ( [ SCREEN_FN_ID_DRAW_TRANSPARENT_IMAGE , i , x , y ] ) ) ;
162152 return ;
163153 }
@@ -172,7 +162,6 @@ namespace user_interface_base {
172162 y : number
173163 ) {
174164 const w = xfrm . worldPos
175- // Screen.image.drawTransparentBitmap(
176165 Screen . drawTransparentImage (
177166 from ,
178167 Screen . x ( x + w . x ) ,
@@ -195,7 +184,6 @@ namespace user_interface_base {
195184 c
196185 ] )
197186 )
198- // basic.pause(15)
199187 }
200188
201189 public static drawLineXfrm (
@@ -227,7 +215,6 @@ namespace user_interface_base {
227215 const c = shader ( tx , ty )
228216 if ( c ) {
229217 Screen . setPixel ( x , y , c )
230- // basic.pause(15)
231218 }
232219 }
233220 }
@@ -241,7 +228,6 @@ namespace user_interface_base {
241228 c : number
242229 ) {
243230 this . tryToSend ( Buffer . fromArray ( [ SCREEN_FN_ID_DRAW_RECT , x + Screen . HALF_WIDTH , y + Screen . HALF_HEIGHT , width , height , c ] ) ) ;
244- // basic.pause(15)
245231 }
246232
247233 public static drawRectXfrm (
@@ -261,7 +247,6 @@ namespace user_interface_base {
261247 c : number
262248 ) {
263249 this . tryToSend ( Buffer . fromArray ( [ SCREEN_FN_ID_FILL , c ] ) )
264- // basic.pause(15)
265250 }
266251
267252 public static fillRect (
@@ -272,7 +257,6 @@ namespace user_interface_base {
272257 c : number
273258 ) {
274259 this . tryToSend ( Buffer . fromArray ( [ SCREEN_FN_ID_FILL_RECT , x + Screen . HALF_WIDTH , y + Screen . HALF_HEIGHT , width , height , c ] ) )
275- // basic.pause(15)
276260 }
277261
278262 public static fillRectXfrm (
@@ -459,12 +443,10 @@ namespace user_interface_base {
459443 font ?: bitmaps . Font ,
460444 offsets ?: texteffects . TextEffectState [ ]
461445 ) {
462- radio . sendString ( text ) ;
463- this . waitForAck ( ) ;
446+ this . tryToSend ( text ) ;
464447
465448 const c : number = ( color == null ) ? 0 : color ;
466449 this . tryToSend ( Buffer . fromArray ( [ SCREEN_FN_ID_PRINT , x + Screen . HALF_WIDTH , y + Screen . HALF_HEIGHT , c ] ) ) ;
467- // basic.pause(15)
468450 }
469451 }
470452}
0 commit comments