@@ -61,82 +61,28 @@ namespace user_interface_base {
6161 return Screen . image_
6262 }
6363 public static resetScreenImage ( ) {
64- // Screen.image_ = screen()
65- // Screen.updateBounds()
66- // basic.showNumber(SCREEN_FN_ID_RESET_SCREEN_IMAGE);
6764 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_RESET_SCREEN_IMAGE ] ) ) ;
6865 }
6966
7067 public static setImageSize ( width : number , height : number ) {
71- // Screen.image_ = bitmaps.create(width, height)
72- // Screen.updateBounds()
73- // basic.showNumber(SCREEN_FN_ID_SET_IMAGE_SIZE);
7468 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_SET_IMAGE_SIZE , width , height ] ) ) ;
7569 }
7670
77-
7871 public static sendBitmap ( name : string , bitmap : Bitmap ) {
79- // Returns true on succesful acknowledgement reception.
80- // Returns false on timeout (250ms)
81- const waitForAck = ( ) => {
82- // basic.showString("W")
83-
84- let ackReceived = false ;
85- radio . onReceivedString ( _ => {
86- ackReceived = true ;
72+ function waitForAck ( ) {
73+ let received = false ;
74+ radio . onReceivedString ( ( _ : String ) => {
75+ received = true ;
8776 } )
8877
89- // timeout:
90- for ( let timeChunk = 0 ; timeChunk < 500 ; timeChunk += 10 ) {
91- if ( ackReceived )
92- break
93- basic . pause ( 10 )
94- }
95-
96- // radio.onReceivedValue(_ => { }) // reset radio
97- return ackReceived ;
98- } ;
99-
100- // bitmap information:
101- radio . sendString ( name + "," + bitmap . height )
102- basic . pause ( 10 )
103-
104- basic . showString ( "W" )
105- while ( waitForAck ( ) ) {
106- radio . sendString ( name + "," + bitmap . height ) ;
107- basic . pause ( 10 )
108- }
109- basic . showString ( "R" )
110-
111- // Send each row of the bitmap:
112- // basic.showString("S")
113- let rowBuffer = Buffer . create ( bitmap . width * 8 ) ;
114- for ( let row = 0 ; row < bitmap . height ; row ++ ) {
115- // Fill buffer & send it over radio:
116- bitmap . getRows ( row , rowBuffer ) ;
117-
118- // basic.showString("B")
119- radio . sendBuffer ( rowBuffer ) ;
120- basic . pause ( 10 )
121-
122- while ( waitForAck ( ) ) {
123- // basic.showString("B")
124- radio . sendBuffer ( rowBuffer ) ;
125-
126- // basic.showString("W")
127- basic . pause ( 10 )
78+ while ( ! received ) {
79+ basic . pause ( 3 )
12880 }
129-
130- // basic.showString("A")
13181 }
132-
133- // basic.showString("D")
13482 }
13583
13684
13785 public static drawTransparentImage ( from : Bitmap , x : number , y : number ) {
138- // Screen.image.drawTransparentBitmap(from, Screen.x(x), Screen.y(y));
139- // basic.showString("S")
14086 let b = Buffer . create ( from . width / 8 ) ;
14187
14288 for ( let row = 0 ; row < from . height ; row ++ ) {
@@ -169,16 +115,6 @@ namespace user_interface_base {
169115 y1 : number ,
170116 c : number
171117 ) {
172- // Screen.image.drawLine(
173- // Screen.x(x0),
174- // Screen.y(y0),
175- // Screen.x(x1),
176- // Screen.y(y1),
177- // c
178- // )
179-
180- // basic.showNumber(SCREEN_FN_ID_DRAW_LINE);
181- // radio.sendNumber(SCREEN_FN_ID_DRAW_LINE);
182118 radio . sendBuffer (
183119 Buffer . fromArray ( [
184120 SCREEN_FN_ID_DRAW_LINE ,
@@ -230,9 +166,6 @@ namespace user_interface_base {
230166 height : number ,
231167 c : number
232168 ) {
233- // Screen.image.drawRect(Screen.x(x), Screen.y(y), width, height, c)
234- // basic.showString("S");
235- // basic.showNumber(SCREEN_FN_ID_DRAW_RECT);
236169 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_DRAW_RECT , x + Screen . HALF_WIDTH , y + Screen . HALF_HEIGHT , width , height , c ] ) ) ;
237170 basic . clearScreen ( )
238171 }
@@ -253,8 +186,6 @@ namespace user_interface_base {
253186 public static fill (
254187 c : number
255188 ) {
256- // basic.showString("S");
257- // basic.showNumber(SCREEN_FN_ID_FILL);
258189 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_FILL , c ] ) ) ;
259190 basic . clearScreen ( )
260191 }
@@ -266,9 +197,6 @@ namespace user_interface_base {
266197 height : number ,
267198 c : number
268199 ) {
269- // basic.showNumber(SCREEN_FN_ID_FILL_RECT);
270- // basic.showString("S") ;
271-
272200 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_FILL_RECT , x + Screen . HALF_WIDTH , y + Screen . HALF_HEIGHT , width , height , c ] ) )
273201 basic . clearScreen ( )
274202 }
@@ -435,8 +363,6 @@ namespace user_interface_base {
435363
436364 public static setPixel ( x : number , y : number , c : number ) {
437365 if ( c ) {
438- // Screen.image.setPixel(Screen.x(x), Screen.y(y), c)
439- // basic.showNumber(SCREEN_FN_ID_SET_PIXEL);
440366 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_SET_PIXEL , x + Screen . HALF_WIDTH , y + Screen . HALF_HEIGHT , c ] ) ) ;
441367 }
442368 }
@@ -459,21 +385,10 @@ namespace user_interface_base {
459385 font ?: bitmaps . Font ,
460386 offsets ?: texteffects . TextEffectState [ ]
461387 ) {
462- // basic.showString("P");
463388 radio . sendString ( text ) ;
464389
465390 const c : number = ( color == null ) ? 0 : color ;
466391 radio . sendBuffer ( Buffer . fromArray ( [ SCREEN_FN_ID_PRINT , x + Screen . HALF_WIDTH , y + Screen . HALF_HEIGHT , c ] ) ) ;
467-
468- // Screen.image.print(
469- // text,
470- // Screen.x(x),
471- // Screen.y(y),
472- // color,
473- // font,
474- // offsets
475- // )
476- // basic.clearScreen()
477392 }
478393 }
479394}
0 commit comments