@@ -9,10 +9,34 @@ namespace microdata {
99 }
1010
1111 export function sendAllAssetsOverRadio ( ) {
12+ // const iconNames: string[] = [
13+ // "wordLogo",
14+ // "microbitLogo",
15+ // "edit_program",
16+ // "MISSING",
17+ // "largeDisk",
18+ // "linear_graph_1",
19+ // "led_light_sensor",
20+ // "thermometer",
21+ // "accelerometer",
22+ // "finger_press",
23+ // "green_tick",
24+ // "magnet",
25+ // "pin_0",
26+ // "pin_1",
27+ // "pin_2",
28+ // "right_turn",
29+ // "right_spin",
30+ // "microphone",
31+ // "tile_button_a",
32+ // "tile_button_b",
33+ // "compass",
34+ // "radio_set_group",
35+ // "largeSettingsGear",
36+ // "microbitLogoWhiteBackground"
37+ // ];
38+
1239 const iconNames : string [ ] = [
13- "wordLogo" ,
14- "microbitLogo" ,
15- "edit_program" ,
1640 "MISSING" ,
1741 "largeDisk" ,
1842 "linear_graph_1" ,
@@ -27,57 +51,71 @@ namespace microdata {
2751 "pin_2" ,
2852 "right_turn" ,
2953 "right_spin" ,
30- "microphone" ,
31- "tile_button_a" ,
32- "tile_button_b" ,
33- "compass" ,
34- "radio_set_group" ,
35- "largeSettingsGear" ,
36- "microbitLogoWhiteBackground"
54+ "microphone"
3755 ] ;
3856
57+ // const iconNames: string[] = [
58+ // "green_tick"
59+ // // "wordLogo"
60+ // ]
3961
40- const waitForAck = ( ) => {
41- basic . showString ( "W" )
62+ // Get the number of bitmaps:
63+ radio . sendString ( "BITMAPS," + iconNames . length ) ;
64+ waitForAck ( ) ;
4265
43- let ackReceived = false ;
44- radio . onReceivedString ( _ => {
45- ackReceived = true ;
46- } )
66+ for ( let i = 0 ; i < iconNames . length ; i ++ ) {
67+ Screen . sendBitmap ( icons . get ( iconNames [ i ] ) ) ;
68+ }
4769
48- // timeout:
49- for ( let timeChunk = 0 ; timeChunk < 500 ; timeChunk += 25 ) {
50- if ( ackReceived )
51- break
52- basic . pause ( 25 )
53- }
70+ basic . showString ( "F" )
71+ }
5472
55- radio . onReceivedValue ( _ => { } ) // reset radio
56- return ackReceived ;
57- } ;
73+ function waitForAck ( ) {
74+ let received = false ;
75+ radio . onReceivedString ( ( _ : String ) => {
76+ received = true ;
77+ } )
5878
79+ while ( ! received ) {
80+ basic . pause ( 3 )
81+ }
82+ }
5983
60- basic . showString ( "St" )
61- radio . sendString ( "ASSET_TX_START" + ", " + iconNames . length )
62- basic . pause ( 10 )
84+ function getBuffer ( bitmap : Bitmap , chunkIndex : number , chunkSize : number ) : Buffer {
85+ const width = bitmap . width
86+ const startIndex = chunkIndex * chunkSize ;
87+ const startingRow = ( startIndex / width | 0 ) ;
6388
64- while ( ! waitForAck ( ) ) {
65- radio . sendString ( "ASSET_TX_START" + ", " + iconNames . length )
66- basic . pause ( 10 )
67- }
89+ const endIndex = startIndex + chunkSize ;
90+ const endingRow = ( endIndex / width | 0 ) ;
6891
69- // iconNames.forEach(name => {
70- for ( let i = 0 ; i < 1 ; i ++ ) {
71- Screen . sendBitmap ( iconNames [ i ] , icons . get ( iconNames [ i ] ) )
72- // Screen.sendBitmap(name, icons.get(name))
73- // })
92+ // Buffer crosses multiple rows:
93+ if ( startingRow != endingRow ) {
94+ const rowBuf1 = Buffer . create ( bitmap . width ) ;
95+ const rowBuf2 = Buffer . create ( bitmap . width ) ;
96+
97+ bitmap . getRows ( startingRow , rowBuf1 ) ;
98+ bitmap . getRows ( startingRow + 1 , rowBuf2 ) ;
99+
100+ const overhead = width - ( startIndex % width ) ;
101+ const chunkBuf1 = rowBuf1 . slice ( startIndex % width , overhead ) ;
102+ const chunkBuf2 = rowBuf2 . slice ( 0 , chunkSize - overhead ) ;
103+
104+ const res = chunkBuf1 . concat ( chunkBuf2 ) ;
105+ // basic.showNumber(res.length)
106+ return res
74107 }
75108
76- // radio.sendString("ASSET_TX_END")
77- basic . showString ( "D" )
109+ // Simply get the row, slice off the required bytes:
110+ else {
111+ const rowBuf = Buffer . create ( bitmap . width ) ;
112+ bitmap . getRows ( startingRow , rowBuf ) ;
113+ const res = rowBuf . slice ( startIndex % width , chunkSize ) ;
114+ // basic.showNumber(res.length)
115+ return res
116+ }
78117 }
79118
80-
81119 // All unused assets have been cut since the flash storage limit has been approached
82120
83121 export class icons {
0 commit comments