-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.ts
1888 lines (1760 loc) · 65.2 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file YFSENSORS
* @brief YFROBOT's sensors(lego) makecode library.
* @n This is a MakeCode graphics programming extension for YFROBOT's sensors(lego) module.
*
* @copyright YFROBOT,2021
* @copyright MIT Lesser General Public License
*
* @author [email]([email protected])
* @date 2021-11-23
*/
enum enButton {
//% blockId="Press" block="Press"
Press = 0,
//% blockId="Realse" block="Realse"
Realse = 1
}
enum YFIrProtocol {
//% block="Keyestudio"
Keyestudio = 0,
//% block="NEC"
NEC = 1,
}
enum YFIrButtonAction {
//% block="pressed"
Pressed = 0,
//% block="released"
Released = 1,
}
enum YFIrButton_Handle {
// any button
//% block="Any"
Any = -1,
//IR HANDLE
//% block="↑"
UP = 0x11,
//% block="↓"
DOWN = 0x91,
//% block="←"
LEFT = 0x81,
//% block="→"
RIGHT = 0xa1,
//% block="M1"
M1 = 0xe9,
//% block="M2"
M2 = 0x69,
//% block="A"
A = 0x21,
//% block="B"
B = 0x01
}
enum YFIrButton {
// any button
//% block="Any"
Any = -1,
//% block=" "
Null_01 = -1,
//% block=" "
Null_02 = -1,
// MINI IR
//% block="A"
Mini_A = 0xa2,
//% block="B"
Mini_B = 0x62,
//% block="C"
Mini_C = 0xe2,
//% block="D"
Mini_D = 0x22,
//% block="︿"
Mini_UP = 0x02,
//% block="E"
Mini_E = 0xc2,
//% block="<"
Mini_Left = 0xe0,
//% block="۞"
Mini_SET = 0xa8,
//% block=">"
Mini_Right = 0x90,
//% block="0"
Number_0 = 0x68,
//% block="﹀"
Mini_Down = 0x98,
//% block="F"
Mini_F = 0xb0,
//% block="1"
Number_1 = 0x30,
//% block="2"
Number_2 = 0x18,
//% block="3"
Number_3 = 0x7a,
//% block="4"
Number_4 = 0x10,
//% block="5"
Number_5 = 0x38,
//% block="6"
Number_6 = 0x5a,
//% block="7"
Number_7 = 0x42,
//% block="8"
Number_8 = 0x4a,
//% block="9"
Number_9 = 0x52,
}
/************************* IR *************************/
enum YFADOutputModule {
//% blockId="YFDOM_LED" block="LED"
LED = 0x0,
//% blockId="YFDOM_FAN" block="FAN"
FAN = 0x2,
//% blockId="YFDOM_VIBRATION_MOTOR" block="VIBRATION_MOTOR"
VIBRATION_MOTOR = 0x4,
//% blockId="YFDOM_PUMP" block="PUMP"
PUMP = 0x5,
}
enum YFDigitalOutputModule {
//% blockId="YFDOM_LED" block="LED"
LED = 0x0,
//% blockId="YFDOM_BUZZER" block="BUZZER"
BUZZER = 0x1,
//% blockId="YFDOM_FAN" block="FAN"
FAN = 0x2,
//% blockId="YFDOM_RELAY" block="RELAY"
RELAY = 0x3,
//% blockId="YFDOM_VIBRATION_MOTOR" block="VIBRATION_MOTOR"
VIBRATION_MOTOR = 0x4,
//% blockId="YFDOM_PUMP" block="PUMP"
PUMP = 0x5,
}
/************************* Output - OTP Fixed voice list *************************/
enum YFOTPFixedVoiceList {
//% blockId="YFOTPFVL_00" block="老师"
OTPFVL_00 = 0x00,
//% blockId="YFOTPFVL_01" block="爸爸"
OTPFVL_01 = 0x01,
//% blockId="YFOTPFVL_02" block="妈妈"
OTPFVL_02 = 0x02,
//% blockId="YFOTPFVL_03" block="爷爷"
OTPFVL_03 = 0x03,
//% blockId="YFOTPFVL_04" block="奶奶"
OTPFVL_04 = 0x04,
//% blockId="YFOTPFVL_05" block="姥姥"
OTPFVL_05 = 0x05,
//% blockId="YFOTPFVL_06" block="姥爷"
OTPFVL_06 = 0x06,
//% blockId="YFOTPFVL_07" block="哥哥"
OTPFVL_07 = 0x07,
//% blockId="YFOTPFVL_08" block="姐姐"
OTPFVL_08 = 0x08,
//% blockId="YFOTPFVL_09" block="叔叔"
OTPFVL_09 = 0x09,
//% blockId="YFOTPFVL_0A" block="阿姨"
OTPFVL_0A = 0x0A,
//% blockId="YFOTPFVL_0B" block="上午"
OTPFVL_0B = 0x0B,
//% blockId="YFOTPFVL_0C" block="下午"
OTPFVL_0C = 0x0C,
//% blockId="YFOTPFVL_0D" block="晚上"
OTPFVL_0D = 0x0D,
//% blockId="YFOTPFVL_0E" block="前方"
OTPFVL_0E = 0x0E,
//% blockId="YFOTPFVL_0F" block="厘米"
OTPFVL_0F = 0x0F,
//% blockId="YFOTPFVL_10" block="新年快乐"
OTPFVL_10 = 0x10,
//% blockId="YFOTPFVL_11" block="身体健康"
OTPFVL_11 = 0x11,
//% blockId="YFOTPFVL_12" block="工作顺利"
OTPFVL_12 = 0x12,
//% blockId="YFOTPFVL_13" block="学习进步"
OTPFVL_13 = 0x13,
//% blockId="YFOTPFVL_14" block="您好"
OTPFVL_14 = 0x14,
//% blockId="YFOTPFVL_15" block="谢谢"
OTPFVL_15 = 0x15,
//% blockId="YFOTPFVL_16" block="的"
OTPFVL_16 = 0x16,
//% blockId="YFOTPFVL_17" block="祝"
OTPFVL_17 = 0x17,
//% blockId="YFOTPFVL_18" block="慢走"
OTPFVL_18 = 0x18,
//% blockId="YFOTPFVL_19" block="欢迎光临"
OTPFVL_19 = 0x19,
//% blockId="YFOTPFVL_1A" block="亲爱的""
OTPFVL_1A = 0x1A,
//% blockId="YFOTPFVL_1B" block="同学们"
OTPFVL_1B = 0x1B,
//% blockId="YFOTPFVL_1C" block="工作辛苦了"
OTPFVL_1C = 0x1C,
//% blockId="YFOTPFVL_1D" block="点"
OTPFVL_1D = 0x1D,
//% blockId="YFOTPFVL_1E" block="打开"
OTPFVL_1E = 0x1E,
//% blockId="YFOTPFVL_1F" block="关闭"
OTPFVL_1F = 0x1F,
//% blockId="YFOTPFVL_20" block="千"
OTPFVL_20 = 0x20,
//% blockId="YFOTPFVL_21" block="百"
OTPFVL_21 = 0x21,
//% blockId="YFOTPFVL_22" block="十/时"
OTPFVL_22 = 0x22,
//% blockId="YFOTPFVL_23" block="1"
OTPFVL_23 = 0x23,
//% blockId="YFOTPFVL_24" block="2"
OTPFVL_24 = 0x24,
//% blockId="YFOTPFVL_25" block="3"
OTPFVL_25 = 0x25,
//% blockId="YFOTPFVL_26" block="4"
OTPFVL_26 = 0x26,
//% blockId="YFOTPFVL_27" block="5"
OTPFVL_27 = 0x27,
//% blockId="YFOTPFVL_28" block="6"
OTPFVL_28 = 0x28,
//% blockId="YFOTPFVL_29" block="7"
OTPFVL_29 = 0x29,
//% blockId="YFOTPFVL_2A" block="8"
OTPFVL_2A = 0x2A,
//% blockId="YFOTPFVL_2B" block="9"
OTPFVL_2B = 0x2B,
//% blockId="YFOTPFVL_2C" block="0"
OTPFVL_2C = 0x2C,
//% blockId="YFOTPFVL_2D" block="当前"
OTPFVL_2D = 0x2D,
//% blockId="YFOTPFVL_2E" block="转"
OTPFVL_2E = 0x2E,
//% blockId="YFOTPFVL_2F" block="左"
OTPFVL_2F = 0x2F,
//% blockId="YFOTPFVL_30" block="右"
OTPFVL_30 = 0x30,
//% blockId="YFOTPFVL_31" block="请"
OTPFVL_31 = 0x31,
//% blockId="YFOTPFVL_32" block="已"
OTPFVL_32 = 0x32,
//% blockId="YFOTPFVL_33" block="现在"
OTPFVL_33 = 0x33,
//% blockId="YFOTPFVL_34" block="是"
OTPFVL_34 = 0x34,
//% blockId="YFOTPFVL_35" block="红灯"
OTPFVL_35 = 0x35,
//% blockId="YFOTPFVL_36" block="绿灯"
OTPFVL_36 = 0x36,
//% blockId="YFOTPFVL_37" block="黄灯"
OTPFVL_37 = 0x37,
//% blockId="YFOTPFVL_38" block="温度"
OTPFVL_38 = 0x38,
//% blockId="YFOTPFVL_39" block="湿度"
OTPFVL_39 = 0x39,
//% blockId="YFOTPFVL_3A" block="欢迎常来"
OTPFVL_3A = 0x3A,
//% blockId="YFOTPFVL_3B" block="还有"
OTPFVL_3B = 0x3B,
//% blockId="YFOTPFVL_3C" block="秒"
OTPFVL_3C = 0x3C,
//% blockId="YFOTPFVL_3D" block="分"
OTPFVL_3D = 0x3D,
//% blockId="YFOTPFVL_3E" block="变"
OTPFVL_3E = 0x3E,
//% blockId="YFOTPFVL_3F" block="等"
OTPFVL_3F = 0x3F,
//% blockId="YFOTPFVL_40" block="下一次"
OTPFVL_40 = 0x40,
//% blockId="YFOTPFVL_41" block="功能"
OTPFVL_41 = 0x41,
//% blockId="YFOTPFVL_42" block="障碍物"
OTPFVL_42 = 0x42,
//% blockId="YFOTPFVL_43" block="世界那么大,我想去看看"
OTPFVL_43 = 0x43,
}
enum YFOTPFixedVoiceList2 {
//% blockId="YFOTPFVL_44" block="今天"
OTPFVL_44 = 0x44,
//% blockId="YFOTPFVL_45" block="年"
OTPFVL_45 = 0x45,
//% blockId="YFOTPFVL_46" block="月"
OTPFVL_46 = 0x46,
//% blockId="YFOTPFVL_47" block="日"
OTPFVL_47 = 0x47,
//% blockId="YFOTPFVL_48" block="星期"
OTPFVL_48 = 0x48,
//% blockId="YFOTPFVL_49" block="农历"
OTPFVL_49 = 0x49,
//% blockId="YFOTPFVL_4A" block="现在时刻"
OTPFVL_4A = 0x4A,
//% blockId="YFOTPFVL_4B" block="北京时间"
OTPFVL_4B = 0x4B,
//% blockId="YFOTPFVL_4C" block="整"
OTPFVL_4C = 0x4C,
//% blockId="YFOTPFVL_4D" block="度"
OTPFVL_4D = 0x4D,
//% blockId="YFOTPFVL_4E" block="百分之"
OTPFVL_4E = 0x4E,
//% blockId="YFOTPFVL_4F" block="距离"
OTPFVL_4F = 0x4F,
//% blockId="YFOTPFVL_50" block="厘米"
OTPFVL_50 = 0x50,
//% blockId="YFOTPFVL_51" block="明天"
OTPFVL_51 = 0x51,
//% blockId="YFOTPFVL_52" block="天气"
OTPFVL_52 = 0x52,
//% blockId="YFOTPFVL_53" block="白天"
OTPFVL_53 = 0x53,
//% blockId="YFOTPFVL_54" block="夜间"
OTPFVL_54 = 0x54,
//% blockId="YFOTPFVL_55" block="晴"
OTPFVL_55 = 0x55,
//% blockId="YFOTPFVL_56" block="多云"
OTPFVL_56 = 0x56,
//% blockId="YFOTPFVL_57" block="阴"
OTPFVL_57 = 0x57,
//% blockId="YFOTPFVL_58" block="雨"
OTPFVL_58 = 0x58,
//% blockId="YFOTPFVL_59" block="雷阵"
OTPFVL_59 = 0x59,
//% blockId="YFOTPFVL_5A" block="小"
OTPFVL_5A = 0x5A,
//% blockId="YFOTPFVL_5B" block="中"
OTPFVL_5B = 0x5B,
//% blockId="YFOTPFVL_5C" block="大"
OTPFVL_5C = 0x5C,
//% blockId="YFOTPFVL_5D" block="夹"
OTPFVL_5D = 0x5D,
//% blockId="YFOTPFVL_5E" block="雪""
OTPFVL_5E = 0x5E,
//% blockId="YFOTPFVL_5F" block="雾"
OTPFVL_5F = 0x5F,
//% blockId="YFOTPFVL_60" block="霾"
OTPFVL_60 = 0x60,
//% blockId="YFOTPFVL_61" block="风"
OTPFVL_61 = 0x61,
//% blockId="YFOTPFVL_62" block="东"
OTPFVL_62 = 0x62,
//% blockId="YFOTPFVL_63" block="南"
OTPFVL_63 = 0x63,
//% blockId="YFOTPFVL_64" block="西"
OTPFVL_64 = 0x64,
//% blockId="YFOTPFVL_65" block="北"
OTPFVL_65 = 0x65,
//% blockId="YFOTPFVL_66" block="到"
OTPFVL_66 = 0x66,
//% blockId="YFOTPFVL_67" block="级"
OTPFVL_67 = 0x67,
//% blockId="YFOTPFVL_68" block="偏"
OTPFVL_68 = 0x68,
//% blockId="YFOTPFVL_69" block="方向"
OTPFVL_69 = 0x69,
//% blockId="YFOTPFVL_6A" block="空气质量"
OTPFVL_6A = 0x6A,
//% blockId="YFOTPFVL_6B" block="优"
OTPFVL_6B = 0x6B,
//% blockId="YFOTPFVL_6C" block="良"
OTPFVL_6C = 0x6C,
//% blockId="YFOTPFVL_6D" block="轻度污染"
OTPFVL_6D = 0x6D,
//% blockId="YFOTPFVL_6E" block="中度污染"
OTPFVL_6E = 0x6E,
//% blockId="YFOTPFVL_6F" block="重度污染"
OTPFVL_6F = 0x6F,
//% blockId="YFOTPFVL_70" block="上"
OTPFVL_70 = 0x70,
//% blockId="YFOTPFVL_71" block="下"
OTPFVL_71 = 0x71,
//% blockId="YFOTPFVL_72" block="接近"
OTPFVL_72 = 0x72,
//% blockId="YFOTPFVL_73" block="远离"
OTPFVL_73 = 0x73,
//% blockId="YFOTPFVL_74" block="灯"
OTPFVL_74 = 0x74,
//% blockId="YFOTPFVL_75" block="风扇"
OTPFVL_75 = 0x75,
//% blockId="YFOTPFVL_76" block="红色"
OTPFVL_76 = 0x76,
//% blockId="YFOTPFVL_77" block="绿色"
OTPFVL_77 = 0x77,
//% blockId="YFOTPFVL_78" block="蓝色"
OTPFVL_78 = 0x78,
//% blockId="YFOTPFVL_79" block="黄色"
OTPFVL_79 = 0x79,
//% blockId="YFOTPFVL_7A" block="白色"
OTPFVL_7A = 0x7A,
//% blockId="YFOTPFVL_7B" block="叮音效"
OTPFVL_7B = 0x7B,
//% blockId="YFOTPFVL_7C" block="滴滴滴"
OTPFVL_7C = 0x7C,
//% blockId="YFOTPFVL_7D" block="叮叮音效"
OTPFVL_7D = 0x7D,
//% blockId="YFOTPFVL_7E" block="叮叮音效"
OTPFVL_7E = 0x7E
}
enum YFOTPFixedVoiceFun {
//% blockId="YFOTPFVF_VolumeLevel0" block="设置音量0"
VolumeLevel0 = 0xE0,
//% blockId="YFOTPFVF_VolumeLevel1" block="设置音量1"
VolumeLevel1 = 0xE1,
//% blockId="YFOTPFVF_VolumeLevel2" block="设置音量2"
VolumeLevel2 = 0xE2,
//% blockId="YFOTPFVF_VolumeLevel3" block="设置音量3"
VolumeLevel3 = 0xE3,
//% blockId="YFOTPFVF_VolumeLevel4" block="设置音量4"
VolumeLevel4 = 0xE4,
//% blockId="YFOTPFVF_VolumeLevel5" block="设置音量5"
VolumeLevel5 = 0xE5,
//% blockId="YFOTPFVF_VolumeLevel6" block="设置音量6"
VolumeLevel6 = 0xE6,
//% blockId="YFOTPFVF_VolumeLevel7" block="设置音量7"
VolumeLevel7 = 0xE7,
//% blockId="YFOTPFVF_LOOP" block="循环播放"
Loop = 0xF2,
//% blockId="YFOTPFVF_STOP" block="停止播放"
Stop = 0xFE
}
enum YFOTPFixedVoiceFun2 {
//% blockId="YFOTPFVF_HEADCODE" block="发送连码头码"
HeadCode = 0xF1,
//% blockId="YFOTPFVF_TAILCODE" block="发送连码尾码"
TailCode = 0xF3
}
enum YFOTPFixedVoiceFunMute {
//% blockId="YFOTPFVF_MUTECODE" block="静音(后接数字,单位10ms)"
MuteCode = 0xF4
}
/************************* Output - MP3 audio playback module function *************************/
enum YFAudioPlaybackFunWithNum {
//% blockId="YFAPF_SelectPlay" block="Select Play"
SelectPlay = 0x0B,
//% blockId="YFAPF_SetVolume" block="Set Volume"
SetVolume = 0x0C,
//% blockId="YFAPF_SetEQ" block="Set EQ Mode"
SetEQ = 0x0D,
//% blockId="YFAPF_SetPlayMode" block="Set Play Mode"
SetPlayMode = 0x0E,
//% blockId="YFAPF_SetInsertTrack" block="Set the insert track"
SetInsertTrack = 0x10,
}
enum YFAudioPlaybackFun {
//% blockId="YFAPF_Play" block="Play"
Play = 0x11,
//% blockId="YFAPF_Pause" block="Pause"
Pause = 0x12,
//% blockId="YFAPF_Stop" block="Stop"
Stop = 0x13,
//% blockId="YFAPF_PreviousTrack" block="Previous track"
PreviousTrack = 0x14,
//% blockId="YFAPF_NextTrack" block="Next track"
NextTrack = 0x15,
//% blockId="YFAPF_PreviousContents" block="Previous contents"
PreviousContents = 0x16,
//% blockId="YFAPF_NextContents" block="Next contents"
NextContents = 0x17,
//% blockId="YFAPF_RemoveNumber" block="Remove Number"
RemoveNumber = 0x0A,
//% blockId="YFAPF_StopInsertTrack" block="Stop Insert Track"
StopInsertTrack = 0x1C,
}
enum YFMVModule {
//% blockId="YFMVM_MP3_AUDIO" block="MP3 Audio"
MP3_AUDIO,
//% blockId="YFMVM_VOICE_BROADCAST" block="Voice Broadcast"
VOICE_BROADCAST
}
/************************* Output - Voice Recorder Module *************************/
enum YFVRMFunction {
//% blockId="YFVRM_PLAY_ONCE" block="Play Once"
PLAY_ONCE,
//% blockId="YFVRM_PLAY_LOOP" block="Play loop(Stop with power off)"
PLAY_LOOP,
//% blockId="YFVRM_SPEAKER_ENABLE" block="Speaker Enable"
SPEAKER_ENABLE,
//% blockId="YFVRM_SPEAKER_DISABLE" block="Speaker Disable"
SPEAKER_DISABLE
}
/************************* Output - Traffic Light LED Mode *************************/
enum YFTrafficLightLED {
//% blockId="YFTLL_AllTurnOFF" block="ALL turn off"
AllTurnOFF = 0x00,
//% blockId="YFTLL_RedLED" block="Light red led"
RedLED = 0x01,
//% blockId="YFTLL_YellowLED" block="Light yellow led"
YellowLED = 0x02,
//% blockId="YFTLL_GreenLED" block="Light green led"
GreenLED = 0x03,
}
enum YFAnalogInputModule {
//% blockId="YFAIM_LIGHT" block="LIGHT"
LIGHT = 0x0,
//% blockId="YFAIM_SOUND" block="SOUND"
SOUND = 0x1,
//% blockId="YFAIM_POTENTIOMETER" block="POTENTIOMETER"
POTENTIOMETER = 0x2,
//% blockId="YFAIM_SOIL_HUMIDITY" block="SOIL_HUMIDITY"
SOIL_HUMIDITY = 0x3,
//% blockId="YFAIM_ROCKER_X" block="ROCKER_X"
ROCKER_X = 0x4,
//% blockId="YFAIM_ROCKER_Y" block="ROCKER_Y"
ROCKER_Y = 0x5,
//% blockId="YFAIM_MQ_GAS" block="MQ_GAS"
MQ_GAS = 0x6,
//% blockId="YFAIM_GRAYSCALE" block="GRAYSCALE" 灰度
GRAYSCALE = 0x7,
//% blockId="YFAIM_WATER" block="WATER"
WATER = 0x8,
//% blockId="YFAIM_FLAME" block="FLAME"
FLAME = 0x9,
//% blockId="YFAIM_PRESSURE" block="PRESSURE"
PRESSURE = 0xA,
}
enum YFDigitalInputModule {
//% blockId="YFDIM_MAGNETIC_SENSOR" block="MAGNETIC_SENSOR"
MAGNETIC_SENSOR = 0x0,
//% blockId="YFDIM_TILT_SENSOR" block="TILT_SENSOR"
TILT_SENSOR = 0x1,
//% blockId="YFDIM_INFRARED_PROXIMITY_SENSOR" block="INFRARED_PROXIMITY_SENSOR"
INFRARED_PROXIMITY_SENSOR = 0x2,
//% blockId="YFDIM_VIBRATION_SENSOR" block="VIBRATION_SENSOR"
VIBRATION_SENSOR = 0x3,
//% blockId="YFDIM_PYROELECTRIC_SENSOR" block="PYROELECTRIC_SENSOR"
PYROELECTRIC_SENSOR = 0x4,
//% blockId="YFDIM_TOUCH_SENSOR" block="TOUCH_SENSOR"
TOUCH_SENSOR = 0x5,
//% blockId="YFDIM_BUTTON" block="BUTTON"
BUTTON = 0x6,
//% blockId="YFDIM_COLLISION_SWITCH" block="COLLISION_SWITCH"
COLLISION_SWITCH = 0x7,
//% blockId="YFDIM_PATROL_LEFT" block="PATROL_LEFT"
PATROL_LEFT = 0x08,
//% blockId="YFDIM_PATROL_RIGHT" block="PATROL_RIGHT"
PATROL_RIGHT = 0x09,
//% blockId="YFDIM_PATROL_SINGLE" block="PATROL_SINGLE"
PATROL_SINGLE = 0x0A,
//% blockId="YFDIM_LIQUID_LEVEL" block="LIQUID_LEVEL"
LIQUID_LEVEL = 0x0B,
//% blockId="YFDIM_LTCH_LEDBTN" block="Latching LED Button"
LTCH_LEDBTN = 0x0C,
//% blockId="YFDIM_MOM_LEDBTN" block="Momentary_LED_Button"
MOM_LEDBTN = 0x0D,
}
enum YFDigitalInputModuleE {
//% blockId="YFDIM_BUTTON" block="BUTTON"
BUTTON = 0x0,
//% blockId="YFDIM_COLLISION_SWITCH" block="COLLISION_SWITCH"
COLLISION_SWITCH = 0x1,
}
/** An action on a touch button */
enum YFDigitalInputEvent {
//% block=touched
Clicked = DAL.MICROBIT_BUTTON_EVT_CLICK, // MICROBIT_BUTTON_EVT_CLICK
}
enum YFSwitchState {
//% blockId="YF_OFF" block="OFF"
OFF = 0x0,
//% blockId="YF_ON" block="ON"
ON = 0x1
}
enum YFMotorsPin {
//% blockId="M1Motor" block="M1"
M1 = 0,
//% blockId="M2Motor" block="M2"
M2 = 1
}
enum YFMotors {
//% blockId="M1Motor" block="M1"
M1 = 0,
//% blockId="M2Motor" block="M2"
M2 = 1,
//% blockId="AllMotors" block="All"
MAll = 2
}
enum YFDir {
//% blockId="CW" block="Forward"
CW = 0x0,
//% blockId="CCW" block="Reverse"
CCW = 0x1
}
enum YFPingUnit {
//% block="cm"
Centimeters,
//% block="inches"
Inches,
//% block="μs"
MicroSeconds
}
enum YFDHT11_state {
//% block="temperature(℃)" enumval=0
DHT11_temperature_C,
//% block="humidity(0~100%)" enumval=1
DHT11_humidity,
}
//% color="#45b787" weight=10 icon="\uf12e"
namespace YFSENSORS {
///////////////////// IR ///////////////////////
let irState: IrState
const MICROBIT_MAKERBIT_IR_NEC = 777
const MICROBIT_MAKERBIT_IR_BUTTON_PRESSED_ID = 789
const MICROBIT_MAKERBIT_IR_BUTTON_RELEASED_ID = 790
const IR_REPEAT = 256
const IR_INCOMPLETE = 257
interface IrState {
protocol: YFIrProtocol;
command: number;
hasNewCommand: boolean;
bitsReceived: uint8;
commandBits: uint8;
}
///////////////////// Output - MP3 audio playback module ///////////////////////
let AudioPlaybackPin_data = DigitalPin.P2;
///////////////////// Output - MOTOR DRIVE PIN ///////////////////////
let YFSENSORSMotor1D = DigitalPin.P13
let YFSENSORSMotor1A = AnalogPin.P14
let YFSENSORSMotor2D = DigitalPin.P15
let YFSENSORSMotor2A = AnalogPin.P16
/////////////////////// DigitalTubes ///////////////////////
let PINDIO = DigitalPin.P1;
let PINCLK = DigitalPin.P2;
let CMD_SYSTEM_CONFIG = 0x48
let DIG1_ADDRESS = 0x68
let DIG2_ADDRESS = 0x6A
let DIG3_ADDRESS = 0x6C
let DIG4_ADDRESS = 0x6E
let DatAddressArray = [DIG1_ADDRESS, DIG2_ADDRESS, DIG3_ADDRESS, DIG4_ADDRESS];
let _SEG = [0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71];
let _intensity = 8
let dbuf = [0, 0, 0, 0]
/////////////////////// DigitalTubes ///////////////////////
///////////////////// Output ///////////////////////
/**
* toggle Turn the Digital Output Module ON or OFF.
* @param adom module. eg: YFADOutputModule.LED
* @param adomPin pin. eg: AnalogPin.P1
* @param state switch state.
* @param percentage brightness of LED, Motor vibration strength, fan rotation speed.
*/
//% group="Output"
//% blockId=YFSENSORS_readInfraredSensor weight=100 blockGap=15
//% block="%adom| %adomPin toggle to %state || percentage %percentage \\%"
//% adom.fieldEditor="gridpicker" adom.fieldOptions.columns=2
//% adomPin.fieldEditor="gridpicker" adomPin.fieldOptions.columns=4
//% percentage.min=0 percentage.max=100
//% state.shadow="toggleOnOff"
//% expandableArgumentMode="toggle"
//% inlineInputMode=inline
export function aDOutputModule(adom: YFADOutputModule, adomPin: AnalogPin, state: boolean, percentage: number = 100): void {
let adomM = adom; // no work
if (state) {
pins.analogSetPeriod(adomPin, 100)
pins.analogWritePin(adomPin, Math.map(percentage, 0, 100, 0, 1023))
} else {
pins.analogWritePin(adomPin, 0)
percentage = 0
}
}
/**
* ON or OFF.
* @param num on or off eg: YFSwitchState.ON
*/
//% advanced=true
//% group="Output"
//% blockId=YFSENSORS_domOnOff weight=11 blockGap=15
//% block="%num"
//% num.fieldEditor="gridpicker" num.fieldOptions.columns=2
export function domOnOff(num: YFSwitchState): number {
return num;
}
/**
* Turn the Digital Output Module ON or OFF.
* @param domPin pin. eg: DigitalPin.P2
* @param dom pin. eg: YFDigitalOutputModule.LED
* @param sws switch state.
*/
//% group="Output"
//% blockId=YFSENSORS_digitalOutputModule weight=98 blockGap=15
//% block="%dom| at %domPin| %sws=YFSENSORS_domOnOff"
//% domPin.fieldEditor="gridpicker" domPin.fieldOptions.columns=4
//% dom.fieldEditor="gridpicker" dom.fieldOptions.columns=2
// sws.fieldEditor="gridpicker" sws.fieldOptions.columns=2
export function digitalOutputModule(dom: YFDigitalOutputModule, domPin: DigitalPin, sws: number): void {
let domM = dom; // no work
pins.digitalWritePin(domPin, sws);
}
///////////////////// Output - OTP Fixed voice broadcast module ///////////////////////
/**
* Returns the serial number of OTP fixed voice list.
* @param num serial number. eg: YFOTPFixedVoiceList.OTPFVL_00
*/
//% advanced=true
//% group="Output"
//% blockId=YFSENSORS_OTPFixedVoiceListNum weight=10 blockGap=15
//% block="%num| "
//% num.fieldEditor="gridpicker" num.fieldOptions.columns=10
export function OTPFixedVoiceListNum(num: YFOTPFixedVoiceList): number {
return num;
}
/**
* Returns the serial number of OTP fixed voice list.
* @param num serial number. eg: YFOTPFixedVoiceList2.OTPFVL_44
*/
//% group="Output"
//% blockId=YFSENSORS_OTPFixedVoiceListNum2 weight=94 blockGap=15
//% block="%num"
//% num.fieldEditor="gridpicker" num.fieldOptions.columns=10
export function OTPFixedVoiceListNum2(num: YFOTPFixedVoiceList2): number {
return num;
}
/**
* Get numeric value of colour
* @param color Standard RGB Led Colours eg: #ff0000
*/
//% advanced=true
//% group="Output"
//% blockId="YFSENSORS_bb_colours" weight=0 blockGap=15
//% block=%color
//% shim=TD_ID colorSecondary="#e7660b"
//% color.fieldEditor="colornumber"
//% color.fieldOptions.decompileLiterals=true
//% color.defl='#ff0000'
//% color.fieldOptions.colours='["#FF0000","#659900","#18E600","#80FF00","#00FF00","#FF8000","#D82600","#B24C00","#00FFC0","#00FF80","#FFC000","#FF0080","#FF00FF","#B09EFF","#00FFFF","#FFFF00","#8000FF","#0080FF","#0000FF","#FFFFFF","#FF8080","#80FF80","#40C0FF","#999999","#000000"]'
//% color.fieldOptions.columns=5
//% color.fieldOptions.className='rgbColorPicker'
export function BBColours(color: number): number {
return color;
}
/**
* Fixed voice broadcast module send data with no start bit.
* param vbmPin pin.
* param serial_number voice serial number.
*/
function voiceBroadcastModuleSendData(vbmPin: DigitalPin, serial_number: number): void {
for (let index = 0; index < 8; index++) {
pins.digitalWritePin(vbmPin, 1);
if(serial_number & 1){
control.waitMicros(2400);
pins.digitalWritePin(vbmPin, 0);
control.waitMicros(800);
} else {
control.waitMicros(800);
pins.digitalWritePin(vbmPin, 0);
control.waitMicros(2400);
}
serial_number >>= 1;
}
pins.digitalWritePin(vbmPin, 1);
}
/**
* Fixed voice broadcast module send data with start bit.
* param vbmPin pin.
* param serial_number voice serial number.
*/
function voiceBroadcastModuleSendDataWithS(vbmPin: DigitalPin, serial_number: number): void {
pins.digitalWritePin(vbmPin, 1);
basic.pause(3);
pins.digitalWritePin(vbmPin, 0);
basic.pause(3);
voiceBroadcastModuleSendData(vbmPin, serial_number);
}
/**
* Fixed voice broadcast module play.
* @param vbmPin pin. eg: DigitalPin.P2
* @param serial_number voice serial number.
* @param delayt delay time. eg: 50
*/
//% group="Output"
//% blockId=YFSENSORS_voiceBroadcastModule weight=95 blockGap=15
//% block="voice broadcast %vbmPin| play %serial_number=YFSENSORS_OTPFixedVoiceListNum || delay %delayt| ms"
//% vbmPin.fieldEditor="gridpicker" vbmPin.fieldOptions.columns=4
//% inlineInputMode=inline
export function voiceBroadcastModule(vbmPin: DigitalPin, serial_number: number, delayt: number = 50): void {
voiceBroadcastModuleSendDataWithS(vbmPin, serial_number);
if (delayt > 50 ) {
basic.pause(delayt);
} else
basic.pause(50);
}
/**
* Fixed voice broadcast module function : set volume level(0~7) / Stop play / loop play.
* @param vbmfPin pin. eg: DigitalPin.P2
* @param serial_num voice serial number of function. eg: YFOTPFixedVoiceFun.VolumeLevel4
*/
//% group="Output"
//% blockId=YFSENSORS_voiceBroadcastModuleFun weight=93 blockGap=15
//% block="voice broadcast %vbmfPin| %serial_num"
//% vbmfPin.fieldEditor="gridpicker" vbmfPin.fieldOptions.columns=4
//% serial_num.fieldEditor="gridpicker" serial_num.fieldOptions.columns=4
//% inlineInputMode=inline
export function voiceBroadcastModuleFun(vbmfPin: DigitalPin, serial_num: YFOTPFixedVoiceFun): void {
let snumber = serial_num;
voiceBroadcastModuleSendDataWithS(vbmfPin, snumber);
}
/**
* Fixed voice broadcast module function : Continuous Play.
* @param vbmPin pin. eg: DigitalPin.P2
* @param serial_number voice serial number list array.
*/
//% group="Output"
//% blockId=YFSENSORS_voiceBroadcastModuleFunContPlay weight=92 blockGap=15
//% block="voice broadcast %vbmPin| continuous play %serial_number"
//% vbmPin.fieldEditor="gridpicker" vbmPin.fieldOptions.columns=4
//% inlineInputMode=inline
export function voiceBroadcastModuleFunContPlay(vbmPin: DigitalPin, serial_number: number[]): void {
let checksum = 0;
voiceBroadcastModuleSendDataWithS(vbmPin, YFOTPFixedVoiceFun2.HeadCode); // 头码
checksum += YFOTPFixedVoiceFun2.HeadCode;
for (let index = 0; index < serial_number.length; index++) {
voiceBroadcastModuleSendData(vbmPin, serial_number[index]); // 语音列表码
checksum += serial_number[index];
}
voiceBroadcastModuleSendData(vbmPin, YFOTPFixedVoiceFun2.TailCode); // 尾码
checksum += YFOTPFixedVoiceFun2.TailCode;
voiceBroadcastModuleSendData(vbmPin, (checksum && 0xFF)); // 校验和
}
/**
* Returns the mute code.
* @param mute mute code.
*/
//% group="Output"
//% blockId=YFSENSORS_OTPFixedVoiceMute weight=91 blockGap=15
//% block="%mute"
//% num.fieldEditor="gridpicker" num.fieldOptions.columns=10
export function OTPFixedVoiceMute(mute: YFOTPFixedVoiceFunMute): number {
return mute;
}
///////////////////// Output - MP3 audio playback module ///////////////////////
/**
* Connects the MP3 audio playback module to the specified pin.
* @param pin_data data pin. eg: DigitalPin.P2
*/
//% group="Output"
//% blockId="YFSENSORS_audioPlaybackModule_connectPin" weight=90 blockGap=15
//% block="connect MP3 audio playback module at %pin_data"
//% pin_data.fieldEditor="gridpicker" pin_data.fieldOptions.columns=4 pin_data.fieldOptions.tooltips="false"
export function audioPlaybackModule_connectPin(pin_data: DigitalPin): void {
AudioPlaybackPin_data = pin_data;
}
/**
* MP3 audio playback module send data.
*/
function audioPlaybackModule_sendData(num: number): void {
pins.digitalWritePin(AudioPlaybackPin_data, 1);
basic.pause(1);
pins.digitalWritePin(AudioPlaybackPin_data, 0);
basic.pause(3);
for (let index = 0; index < 8; index++) {
pins.digitalWritePin(AudioPlaybackPin_data, 1);
if (num & 1) {
control.waitMicros(2400);
pins.digitalWritePin(AudioPlaybackPin_data, 0);
control.waitMicros(800);
} else {
control.waitMicros(800);
pins.digitalWritePin(AudioPlaybackPin_data, 0);
control.waitMicros(2400);
}
num >>= 1;
}
pins.digitalWritePin(AudioPlaybackPin_data, 1);
}
/**
* Digital demolition
*/
function splitToDigit (n: number): Array<number> {
let num = []
while (n > 0) {
// serial.writeLine("n--" + n);
num.push(n % 10)
n = Math.floor(n / 10)
}
return num;
}
/**
* MP3 audio playback module select specified track(1-255) with no play.
* @param specified_track mp3 module specified track number. eg: 1
*/
//% advanced=true
//% group="Output"
//% blockId=YFSENSORS_audioPlaybackModuleSelectTrackNum weight=90 blockGap=15
//% block="audio playback select specified track %specified_track| no play"
//% specified_track.min=1 specified_track.max=255
export function audioPlaybackModuleSelectTrackNum(specified_track: number): void {
let s_track = specified_track;
if(s_track >= 10){
let s_track_num = splitToDigit(s_track);
control.waitMicros(10);
for (let index = s_track_num.length-1; index >= 0; index--) {
audioPlaybackModule_sendData(s_track_num[index]); // Select the music
}
} else {
audioPlaybackModule_sendData(s_track); // Select the music
}
}
/**
* MP3 audio playback module Playback settings.
* @param specified_fun mp3 module specified track number. eg: YFAudioPlaybackFunWithNum.SelectPlay
*/
//% advanced=true
//% group="Output"
//% blockId=YFSENSORS_audioPlaybackModuleFunSelect weight=89 blockGap=15
//% block="audio playback %specified_fun"
//% specified_fun.fieldEditor="gridpicker" specified_fun.fieldOptions.columns=2
export function audioPlaybackModuleFunSelect(specified_fun: YFAudioPlaybackFunWithNum): void {
audioPlaybackModule_sendData(specified_fun);
}
/**
* MP3 audio playback module play specified track.
* @param specified_fun mp3 module specified function code. eg: YFAudioPlaybackFunWithNum.SelectPlay
* @param specified_track mp3 module specified track number. eg: 1
*/
//% group="Output"
//% blockId=YFSENSORS_audioPlaybackModuleFunWithNum weight=88 blockGap=15
//% block="audio playback %specified_fun| %specified_track"
//% specified_fun.fieldEditor="gridpicker" specified_fun.fieldOptions.columns=2
export function audioPlaybackModuleFunWithNum(specified_fun: YFAudioPlaybackFunWithNum, specified_track: number): void {
if (specified_fun == YFAudioPlaybackFunWithNum.SelectPlay || specified_fun == YFAudioPlaybackFunWithNum.SetInsertTrack) {
if (specified_track >= 255) specified_track = 255;
} else if (specified_fun == YFAudioPlaybackFunWithNum.SetVolume) {
if (specified_track > 30) specified_track = 30;
} else if (specified_fun == YFAudioPlaybackFunWithNum.SetEQ) {
if (specified_track > 4) specified_track = 4;
} else if (specified_fun == YFAudioPlaybackFunWithNum.SetPlayMode) {
if (specified_track > 7) specified_track = 7;
}
let s_track = specified_track;
if(s_track >= 10){
let s_track_num = splitToDigit(s_track);
control.waitMicros(10);
for (let index = s_track_num.length-1; index >= 0; index--) {
audioPlaybackModule_sendData(s_track_num[index]); // Select the music
}
} else {
audioPlaybackModule_sendData(s_track); // Select the music
}
audioPlaybackModule_sendData(specified_fun);
}
/**
* MP3 audio playback module Playback settings.
* @param specified_fun mp3 module specified function code. eg: YFAudioPlaybackFun.Play
*/
//% group="Output"
//% blockId=YFSENSORS_audioPlaybackModuleFun weight=86 blockGap=15
//% block="audio playback %specified_fun"
//% specified_fun.fieldEditor="gridpicker" specified_fun.fieldOptions.columns=3
export function audioPlaybackModuleFun(specified_fun: YFAudioPlaybackFun): void {