24
24
* THE SOFTWARE.
25
25
*/
26
26
27
+ // @ts -check
28
+ /// <reference path="./jshal.d.ts" />
29
+
27
30
mergeInto ( LibraryManager . library , {
28
31
mp_js_hal_init : async function ( ) {
29
32
Module . board . initialize ( ) ;
@@ -41,20 +44,32 @@ mergeInto(LibraryManager.library, {
41
44
return Module . board . readSerialInput ( ) ;
42
45
} ,
43
46
44
- mp_js_hal_stdout_tx_strn : function ( ptr , len ) {
47
+ mp_js_hal_stdout_tx_strn : function (
48
+ /** @type {number } */ ptr ,
49
+ /** @type {number } */ len
50
+ ) {
45
51
Module . board . writeSerialOutput ( UTF8ToString ( ptr , len ) ) ;
46
52
} ,
47
53
48
- mp_js_hal_filesystem_find : function ( name , len ) {
54
+ mp_js_hal_filesystem_find : function (
55
+ /** @type {number } */ name ,
56
+ /** @type {number } */ len
57
+ ) {
49
58
return Module . fs . find ( UTF8ToString ( name , len ) ) ;
50
59
} ,
51
60
52
- mp_js_hal_filesystem_create : function ( name , len ) {
61
+ mp_js_hal_filesystem_create : function (
62
+ /** @type {number } */ name ,
63
+ /** @type {number } */ len
64
+ ) {
53
65
const filename = UTF8ToString ( name , len ) ;
54
66
return Module . fs . create ( filename ) ;
55
67
} ,
56
68
57
- mp_js_hal_filesystem_name : function ( idx , buf ) {
69
+ mp_js_hal_filesystem_name : function (
70
+ /** @type {number } */ idx ,
71
+ /** @type {number } */ buf
72
+ ) {
58
73
const name = Module . fs . name ( idx ) ;
59
74
if ( name === undefined ) {
60
75
return - 1 ;
@@ -64,52 +79,66 @@ mergeInto(LibraryManager.library, {
64
79
return len ;
65
80
} ,
66
81
67
- mp_js_hal_filesystem_size : function ( idx ) {
82
+ mp_js_hal_filesystem_size : function ( /** @type { number } */ idx ) {
68
83
return Module . fs . size ( idx ) ;
69
84
} ,
70
85
71
- mp_js_hal_filesystem_remove : function ( idx ) {
86
+ mp_js_hal_filesystem_remove : function ( /** @type { number } */ idx ) {
72
87
return Module . fs . remove ( idx ) ;
73
88
} ,
74
89
75
- mp_js_hal_filesystem_readbyte : function ( idx , offset ) {
90
+ mp_js_hal_filesystem_readbyte : function (
91
+ /** @type {number } */ idx ,
92
+ /** @type {number } */ offset
93
+ ) {
76
94
return Module . fs . readbyte ( idx , offset ) ;
77
95
} ,
78
96
79
- mp_js_hal_filesystem_write : function ( idx , buf , len ) {
80
- const data = new Uint8Array ( HEAP8 . buffer , buf , len ) ;
97
+ mp_js_hal_filesystem_write : function (
98
+ /** @type {number } */ idx ,
99
+ /** @type {number } */ buf ,
100
+ /** @type {number } */ len
101
+ ) {
102
+ const data = new Uint8Array ( Module . HEAPU8 . buffer , buf , len ) ;
81
103
return Module . fs . write ( idx , data ) ;
82
104
} ,
83
105
84
106
mp_js_hal_reset : function ( ) {
85
107
Module . board . throwReset ( ) ;
86
108
} ,
87
109
88
- mp_js_hal_panic : function ( code ) {
110
+ mp_js_hal_panic : function ( /** @type { number } */ code ) {
89
111
Module . board . throwPanic ( code ) ;
90
112
} ,
91
113
92
114
mp_js_hal_temperature : function ( ) {
93
115
return Module . board . temperature . value ;
94
116
} ,
95
117
96
- mp_js_hal_button_get_presses : function ( button ) {
118
+ mp_js_hal_button_get_presses : function ( /** @type { number } */ button ) {
97
119
return Module . board . buttons [ button ] . getAndClearPresses ( ) ;
98
120
} ,
99
121
100
- mp_js_hal_button_is_pressed : function ( button ) {
122
+ mp_js_hal_button_is_pressed : function ( /** @type { number } */ button ) {
101
123
return Module . board . buttons [ button ] . isPressed ( ) ;
102
124
} ,
103
125
104
- mp_js_hal_pin_is_touched : function ( pin ) {
126
+ mp_js_hal_pin_is_touched : function ( /** @type { number } */ pin ) {
105
127
return Module . board . pins [ pin ] . isTouched ( ) ;
106
128
} ,
107
129
108
- mp_js_hal_display_get_pixel : function ( x , y ) {
130
+ mp_js_hal_display_get_pixel : function (
131
+ /** @type {number } */ x ,
132
+ /** @type {number } */ y
133
+ ) {
109
134
return Module . board . display . getPixel ( x , y ) ;
110
135
} ,
111
136
112
- mp_js_hal_display_set_pixel : function ( x , y , value ) {
137
+ mp_js_hal_display_set_pixel : function (
138
+ /** @type {number } */ x ,
139
+ /** @type {number } */ y ,
140
+ /** @type {number } */ value
141
+ ) {
113
142
Module . board . display . setPixel ( x , y , value ) ;
114
143
} ,
115
144
@@ -139,7 +168,7 @@ mergeInto(LibraryManager.library, {
139
168
) ;
140
169
} ,
141
170
142
- mp_js_hal_accelerometer_set_range : function ( r ) {
171
+ mp_js_hal_accelerometer_set_range : function ( /** @type { number } */ r ) {
143
172
Module . board . accelerometer . setRange ( r ) ;
144
173
} ,
145
174
@@ -163,51 +192,68 @@ mergeInto(LibraryManager.library, {
163
192
return Module . board . compass . state . compassHeading . value ;
164
193
} ,
165
194
166
- mp_js_hal_audio_set_volume : function ( value ) {
195
+ mp_js_hal_audio_set_volume : function ( /** @type { number } */ value ) {
167
196
Module . board . audio . setVolume ( value ) ;
168
197
} ,
169
198
170
- mp_js_hal_audio_init : function ( sample_rate ) {
199
+ mp_js_hal_audio_init : function ( /** @type {number } */ sample_rate ) {
200
+ // @ts -expect-error
171
201
Module . board . audio . default . init ( sample_rate ) ;
172
202
} ,
173
203
174
- mp_js_hal_audio_write_data : function ( buf , num_samples ) {
204
+ mp_js_hal_audio_write_data : function (
205
+ /** @type {number } */ buf ,
206
+ /** @type {number } */ num_samples
207
+ ) {
208
+ // @ts -expect-error
175
209
Module . board . audio . default . writeData (
176
210
Module . conversions . convertAudioBuffer (
177
211
Module . HEAPU8 ,
178
212
buf ,
213
+ // @ts -expect-error
179
214
Module . board . audio . default . createBuffer ( num_samples )
180
215
)
181
216
) ;
182
217
} ,
183
218
184
- mp_js_hal_audio_speech_init : function ( sample_rate ) {
219
+ mp_js_hal_audio_speech_init : function ( /** @type {number } */ sample_rate ) {
220
+ // @ts -expect-error
185
221
Module . board . audio . speech . init ( sample_rate ) ;
186
222
} ,
187
223
188
- mp_js_hal_audio_speech_write_data : function ( buf , num_samples ) {
224
+ mp_js_hal_audio_speech_write_data : function (
225
+ /** @type {number } */ buf ,
226
+ /** @type {number } */ num_samples
227
+ ) {
228
+ // @ts -expect-error
189
229
Module . board . audio . speech . writeData (
190
230
Module . conversions . convertAudioBuffer (
191
231
Module . HEAPU8 ,
192
232
buf ,
233
+ // @ts -expect-error
193
234
Module . board . audio . speech . createBuffer ( num_samples )
194
235
)
195
236
) ;
196
237
} ,
197
238
198
- mp_js_hal_audio_period_us : function ( period_us ) {
239
+ mp_js_hal_audio_period_us : function ( /** @type { number } */ period_us ) {
199
240
Module . board . audio . setPeriodUs ( period_us ) ;
200
241
} ,
201
242
202
- mp_js_hal_audio_amplitude_u10 : function ( amplitude_u10 ) {
243
+ mp_js_hal_audio_amplitude_u10 : function (
244
+ /** @type {number } */ amplitude_u10
245
+ ) {
203
246
Module . board . audio . setAmplitudeU10 ( amplitude_u10 ) ;
204
247
} ,
205
248
206
249
mp_js_hal_microphone_init : function ( ) {
207
250
Module . board . microphone . microphoneOn ( ) ;
208
251
} ,
209
252
210
- mp_js_hal_microphone_set_threshold : function ( kind , value ) {
253
+ mp_js_hal_microphone_set_threshold : function (
254
+ /** @type {number } */ kind ,
255
+ /** @type {number } */ value
256
+ ) {
211
257
Module . board . microphone . setThreshold (
212
258
Module . conversions . convertSoundThresholdNumberToString ( kind ) ,
213
259
value
@@ -218,7 +264,7 @@ mergeInto(LibraryManager.library, {
218
264
return Module . board . microphone . soundLevel . value ;
219
265
} ,
220
266
221
- mp_js_hal_audio_play_expression : function ( expr ) {
267
+ mp_js_hal_audio_play_expression : function ( /** @type { any } */ expr ) {
222
268
return Module . board . audio . playSoundExpression ( UTF8ToString ( expr ) ) ;
223
269
} ,
224
270
@@ -230,29 +276,42 @@ mergeInto(LibraryManager.library, {
230
276
return Module . board . audio . isSoundExpressionActive ( ) ;
231
277
} ,
232
278
233
- mp_js_radio_enable : function ( group , max_payload , queue ) {
279
+ mp_js_radio_enable : function (
280
+ /** @type {number } */ group ,
281
+ /** @type {number } */ max_payload ,
282
+ /** @type {number } */ queue
283
+ ) {
234
284
Module . board . radio . enable ( { group, maxPayload : max_payload , queue } ) ;
235
285
} ,
236
286
237
287
mp_js_radio_disable : function ( ) {
238
288
Module . board . radio . disable ( ) ;
239
289
} ,
240
290
241
- mp_js_radio_update_config : function ( group , max_payload , queue ) {
291
+ mp_js_radio_update_config : function (
292
+ /** @type {number } */ group ,
293
+ /** @type {number } */ max_payload ,
294
+ /** @type {number } */ queue
295
+ ) {
242
296
Module . board . radio . updateConfig ( { group, maxPayload : max_payload , queue } ) ;
243
297
} ,
244
298
245
- mp_js_radio_send : function ( buf , len , buf2 , len2 ) {
299
+ mp_js_radio_send : function (
300
+ /** @type {number } */ buf ,
301
+ /** @type {number } */ len ,
302
+ /** @type {number } */ buf2 ,
303
+ /** @type {number } */ len2
304
+ ) {
246
305
const data = new Uint8Array ( len + len2 ) ;
247
- data . set ( HEAPU8 . slice ( buf , buf + len ) ) ;
248
- data . set ( HEAPU8 . slice ( buf2 , buf2 + len2 ) , len ) ;
306
+ data . set ( Module . HEAPU8 . slice ( buf , buf + len ) ) ;
307
+ data . set ( Module . HEAPU8 . slice ( buf2 , buf2 + len2 ) , len ) ;
249
308
Module . board . radio . send ( data ) ;
250
309
} ,
251
310
252
311
mp_js_radio_peek : function ( ) {
253
312
const packet = Module . board . radio . peek ( ) ;
254
313
if ( packet ) {
255
- return Module . board . module . writeRadioRxBuffer ( packet ) ;
314
+ return Module . board . writeRadioRxBuffer ( packet ) ;
256
315
}
257
316
return null ;
258
317
} ,
@@ -261,16 +320,16 @@ mergeInto(LibraryManager.library, {
261
320
Module . board . radio . pop ( ) ;
262
321
} ,
263
322
264
- mp_js_hal_log_delete : function ( full_erase ) {
323
+ mp_js_hal_log_delete : function ( /** @type { boolean } */ full_erase ) {
265
324
// We don't have a notion of non-full erase.
266
325
Module . board . dataLogging . delete ( ) ;
267
326
} ,
268
327
269
- mp_js_hal_log_set_mirroring : function ( serial ) {
328
+ mp_js_hal_log_set_mirroring : function ( /** @type { boolean } */ serial ) {
270
329
Module . board . dataLogging . setMirroring ( serial ) ;
271
330
} ,
272
331
273
- mp_js_hal_log_set_timestamp : function ( period ) {
332
+ mp_js_hal_log_set_timestamp : function ( /** @type { number } */ period ) {
274
333
Module . board . dataLogging . setTimestamp ( period ) ;
275
334
} ,
276
335
@@ -282,7 +341,10 @@ mergeInto(LibraryManager.library, {
282
341
return Module . board . dataLogging . endRow ( ) ;
283
342
} ,
284
343
285
- mp_js_hal_log_data : function ( key , value ) {
344
+ mp_js_hal_log_data : function (
345
+ /** @type {number } */ key ,
346
+ /** @type {number } */ value
347
+ ) {
286
348
return Module . board . dataLogging . logData (
287
349
UTF8ToString ( key ) ,
288
350
UTF8ToString ( value )
0 commit comments