-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbosonKit.ts
2077 lines (1880 loc) · 76.4 KB
/
bosonKit.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
//% block="bosonKit"
//% weight=100 color=#0fbc11 icon="\uf0b2"
//% groups="['Sensor', 'Actuator', 'Display', 'Obloq']"
namespace bosonKit {
export enum BosonSensorAnalogRead {
//% blockId="bosonAnalogReadRotation" block="rotation module (i1)"
BosonRotation = 1,
//% blockId="bosonAnalogReadLightIntensity" block="light intensity (i4)"
BosonLightIntensity = 2,
//% blockId="bosonAnalogReadSteam" block="steam sensor (i6)"
BosonSteam = 3,
//% blockId="bosonAnalogReadFlame" block="flame sensor (i7)"
BosonFlame = 4,
//% blockId="bosonAnalogReadSound" block="sound sensor (i9)"
BosonSound = 5,
//% blockId="bosonAnalogReadGrayscale" block="grayscale sensor (i10)"
BosonGrayscale = 6,
//% blockId="bosonAnalogReadTemperature" block="temperature (i11)"
BosonTemperature = 7,
//% blockId="bosonAnalogReadSoilMoisture" block="soil moisture(i16)"
BosonSoilMoisture = 8,
//% blockId="bosonAnalogReadHumidity" block="humidity sensor (i18)"
BosonHumidity = 9,
//% blockId="bosonAnalogReadWaterproofTemperature" block="waterproof temperature (i19)"
BosonWaterproofTemperature = 10,
//% blockId="bosonAnalogReadUltrasonicDistance" block="ultrasonic distance sensor (i22)"
BosonUltrasonicDistance = 11,
//% blockId="bosonAnalogReadSHT30Humidity" block="SHT30 humidity (i27)"
BosonSHT30Humidity = 12,
//% blockId="bosonAnalogReadPhV2" block="pH sensor V2 (i28)"
BosonV2Ph = 13,
//% blockId="bosonAnalogReadWaterLevel" block="water level sensor (i31)"
BosonWaterLevel = 14
}
export enum BosonSensorAnalogWrite {
//% blockId="bosonAnalogWriteBrightLightLed" block="bright light LED (o1)"
BosonBrightLightLed = 1,
//% blockId="bosonAnalogWriteLed" block="LED module (o2r o2g o2b)"
BosonLed = 2,
//% blockId="bosonAnalogWriteRgbStripLights" block="RGB LED strip lights(o4)"
BosonRgbStripLights = 3,
//% blockId="bosonAnalogWriteBuzzer" block="buzzer module(o5)"
BosonBuzzer = 4,
//% blockId="bosonAnalogWriteFan" block="fan module (o6)"
BosonFan = 5,
//% blockId="bosonAnalogWriteMotor" block="motor control module (o9)"
BosonMotor = 6,
//% blockId="bosonAnalogWriteServo" block="servo control module (o10)"
BosonServo = 7
}
export enum BosonSensorDigitalRead {
//% blockId="bosonDigitalReadPushButton" block="push button (i2b i2r i2y)"
BosonPushButton = 1,
//% blockId="bosonDigitalReadSelfLockingSwitch" block="self locking switch (i3)"
BosonSelfLockingSwitch = 2,
//% blockId="bosonDigitalReadTilt" block="tilt sensor (i5)"
BosonTilt = 3,
//% blockId="bosonDigitalReadTouch" block="touch sensor (i8)"
BosonTouch = 4,
//% blockId="bosonDigitalReadConductivity" block="conductivity sensor (i12)"
BosonConductivity = 5,
//% blockId="bosonDigitalReadMotion" block="motion sensor (i13)"
BosonMotion = 6
}
export enum BosonSensorDigitalWrite {
//% blockId="bosonDigitalWriteBrightLightLed" block="bright light LED (o1)"
BosonBrightLightLed = 1,
//% blockId="bosonDigitalWriteLed" block="LED module (o2r o2g o2b)"
BosonLed = 2,
//% blockId="bosonDigitalWriteRgbStripLights" block="RGB LED strip lights (o4)"
BosonRgbStripLights = 3,
//% blockId="bosonDigitalWriteBuzzer" block="buzzer module (o5)"
BosonBuzzer = 4,
//% blockId="bosonDigitalWriteFan" block="fan module (o6)"
BosonFan = 5,
//% blockId="bosonDigitalWriteVoiceRecorder" block="voice recorder (o7)"
BosonVoiceRecorder = 6,
//% blockId="bosonDigitalWriteServo" block="servo control module (o10)"
BosonServo = 7,
}
export enum Servers {
//% blockId=serversChina block="EasyIoT_CN"
China,
//% blockId=serversEnglish block="EasyIoT_EN"
English,
//% blockId=serversSiot block="SIOT"
Siot
}
// topics name
export enum TOPIC {
Topic0 = 0,
Topic1 = 1,
Topic2 = 2,
Topic3 = 3,
Topic4 = 4
}
// topics name
export enum YRAW {
//% block="0"
Y0 = 0,
//% block="1"
Y1 = 1,
//% block="2"
Y2 = 2,
//% block="3"
Y3 = 3
}
export class PacketaMqtt {
/**
* Obloq receives the message content.
*/
public message: string;
}
//debug12
const OBLOQ_DEBUG = false
const OBLOQ_MQTT_DEFAULT_SERVER = true
//DFRobot easy iot
const OBLOQ_MQTT_EASY_IOT_SERVER_CHINA = "iot.dfrobot.com.cn"
const OBLOQ_MQTT_EASY_IOT_SERVER_GLOBAL = "api.beebotte.com"
const OBLOQ_MQTT_EASY_IOT_SERVER_EN = "iot.dfrobot.com"
const OBLOQ_MQTT_EASY_IOT_SERVER_TK = "api.thingspeak.com"
const OBLOQ_MQTT_EASY_IOT_PORT = 1883
//other iot
const OBLOQ_MQTT_USER_IOT_SERVER = "---.-----.---"
const OBLOQ_MQTT_USER_IOT_PORT = 0
//topic max number
const OBLOQ_MQTT_TOPIC_NUM_MAX = 5
//wrong type
const OBLOQ_ERROR_TYPE_IS_SUCCE = 0
const OBLOQ_ERROR_TYPE_IS_ERR = 1
const OBLOQ_ERROR_TYPE_IS_WIFI_CONNECT_TIMEOUT = -1
const OBLOQ_ERROR_TYPE_IS_WIFI_CONNECT_FAILURE = -2
const OBLOQ_ERROR_TYPE_IS_MQTT_SUBTOPIC_TIMEOUT = -3
const OBLOQ_ERROR_TYPE_IS_MQTT_CONNECT_TIMEOUT = -4
const OBLOQ_ERROR_TYPE_IS_MQTT_CONNECT_FAILURE = -5
const OBLOQ_ERROR_TYPE_IS_MQTT_SUBTOPIC_FAILURE = -6
//data type
const OBLOQ_STR_TYPE_IS_NONE = ""
const OBLOQ_BOOL_TYPE_IS_TRUE = true
const OBLOQ_BOOL_TYPE_IS_FALSE = false
const OBLOQ_WEBHOOKS_URL = "maker.ifttt.com"
//serial
let obloqSerialInitFlag = OBLOQ_BOOL_TYPE_IS_FALSE
let obloqSerialTx = SerialPin.P2
let obloqSerialRx = SerialPin.P1
//wifi
let obloqWifiSsid = OBLOQ_STR_TYPE_IS_NONE
let obloqWifiPassword = OBLOQ_STR_TYPE_IS_NONE
let obloqWifiIp = "0.0.0.0"
//mqtt//*
let obloqMqttPort = 0
let obloqMqttServer = OBLOQ_STR_TYPE_IS_NONE
let obloqMqttPwd = OBLOQ_STR_TYPE_IS_NONE
let obloqMqttId = OBLOQ_STR_TYPE_IS_NONE
let obloqMqttTopic = [["x", "false"], ["x", "false"], ["x", "false"], ["x", "false"], ["x", "false"]]
//http
let obloqHttpIp = OBLOQ_STR_TYPE_IS_NONE
let obloqHttpPort = 8080
let obloqHttpBusy = OBLOQ_BOOL_TYPE_IS_FALSE
//state
let obloqWifiConnected = OBLOQ_BOOL_TYPE_IS_FALSE
let obloqWifiConnectFirst = OBLOQ_BOOL_TYPE_IS_TRUE
let obloqMqttInit = OBLOQ_BOOL_TYPE_IS_FALSE
let obloqHttpInit = OBLOQ_BOOL_TYPE_IS_FALSE
//callback
let obloqMqttCallback: Action[] = [null, null, null, null, null]
//commands
let obloqAnswerCmd = OBLOQ_STR_TYPE_IS_NONE
let obloqAnswerContent = OBLOQ_STR_TYPE_IS_NONE
let obloqWrongType = OBLOQ_STR_TYPE_IS_NONE
//animation
let obloqWifiIcon = 1
let obloqMqttIcon = 1
//event
let obloqMqttEvent = OBLOQ_BOOL_TYPE_IS_FALSE
//mode
let obloqWorkingModeIsMqtt = OBLOQ_BOOL_TYPE_IS_FALSE
let obloqWorkingModeIsHttp = OBLOQ_BOOL_TYPE_IS_FALSE
let obloqWorkingModeIsStop = OBLOQ_BOOL_TYPE_IS_TRUE
let obloqWebhooksKey = ""
let obloqWebhooksEvent = ""
let microIoTWebhooksKey = ""
let microIoTWebhooksEvent = ""
let microIoTThingspeakKey = ""
let obloqMqttEasyIotSiot = ""
let microIoTBeebotteToken = ""
let gcity = 0;
let beattime1 = 0;
let beattime2 = 0;
let beattime3 = 0;
let averagetime = 0;
let _brightness = 255;
let rgb_pin = -1;
let neopixel_buf: Buffer;
let ledsum = -1;
// OLED
const IIC_MAX_TRANSFER_SIZE = 32;
const SSD1306_CHARGEPUMP = 0x8D
const SSD1306_COLUMNADDR = 0x21
const SSD1306_COMSCANDEC = 0xC8
const SSD1306_COMSCANINC = 0xC0
const SSD1306_DISPLAYALLON = 0xA5
const SSD1306_DISPLAYALLON_RESUME = 0xA4
const SSD1306_DISPLAYOFF = 0xAE
const SSD1306_DISPLAYON = 0xAF
const SSD1306_EXTERNALVCC = 0x01
const SSD1306_INVERTDISPLAY = 0xA7
const SSD1306_MEMORYMODE = 0x20
const SSD1306_NORMALDISPLAY = 0xA6
const SSD1306_PAGEADDR = 0x22
const SSD1306_SEGREMAP = 0xA0
const SSD1306_SETCOMPINS = 0xDA
const SSD1306_SETCONTRAST = 0x81
const SSD1306_SETDISPLAYCLOCKDIV = 0xD5
const SSD1306_SETDISPLAYOFFSET = 0xD3
const SSD1306_SETHIGHCOLUMN = 0x10
const SSD1306_SETLOWCOLUMN = 0x00
const SSD1306_SETMULTIPLEX = 0xA8
const SSD1306_SETPRECHARGE = 0xD9
const SSD1306_SETSEGMENTREMAP = 0xA1
const SSD1306_SETSTARTLINE = 0x40
const SSD1306_SETVCOMDETECT = 0xDB
const SSD1306_SWITCHCAPVCC = 0x02
const SSD1306_WRITEDATA = 0x40
const SSD1306_WRITECMD = 0x80
let frameBuffer: number[] = [];
let cursorX = 0;
let cursorY = 0;
let oledArdress = 0x3C;
let brushColor = 1;
let cursorLine = 1;
const basicFont: string[] = [
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"/*" "*/,
"\x00\x00\x18\x3c\x3c\x3c\x18\x18\x18\x00\x18\x18\x00\x00\x00\x00"/*"!"*/,
"\x00\x63\x63\x63\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"/*"\"*/,
"\x00\x00\x00\x36\x36\x7f\x36\x36\x36\x7f\x36\x36\x00\x00\x00\x00"/*"#"*/,
"\x0c\x0c\x3e\x63\x61\x60\x3e\x03\x03\x43\x63\x3e\x0c\x0c\x00\x00"/*"$"*/,
"\x00\x00\x00\x00\x00\x61\x63\x06\x0c\x18\x33\x63\x00\x00\x00\x00"/*"%"*/,
"\x00\x00\x00\x1c\x36\x36\x1c\x3b\x6e\x66\x66\x3b\x00\x00\x00\x00"/*"&"*/,
"\x00\x30\x30\x30\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"/*"'"*/,
"\x00\x00\x0c\x18\x18\x30\x30\x30\x30\x18\x18\x0c\x00\x00\x00\x00"/*"("*/,
"\x00\x00\x18\x0c\x0c\x06\x06\x06\x06\x0c\x0c\x18\x00\x00\x00\x00"/*")"*/, //10
"\x00\x00\x00\x00\x42\x66\x3c\xff\x3c\x66\x42\x00\x00\x00\x00\x00"/*"*"*/,
"\x00\x00\x00\x00\x18\x18\x18\xff\x18\x18\x18\x00\x00\x00\x00\x00"/*"+"*/,
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x18\x18\x30\x00\x00"/*","*/,
"\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00"/*"-"*/,
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x18\x00\x00\x00\x00"/*"."*/,
"\x00\x00\x01\x03\x07\x0e\x1c\x38\x70\xe0\xc0\x80\x00\x00\x00\x00"/*"/"*/,
"\x00\x00\x3e\x63\x63\x63\x6b\x6b\x63\x63\x63\x3e\x00\x00\x00\x00"/*"0"*/,
"\x00\x00\x0c\x1c\x3c\x0c\x0c\x0c\x0c\x0c\x0c\x3f\x00\x00\x00\x00"/*"1"*/,
"\x00\x00\x3e\x63\x03\x06\x0c\x18\x30\x61\x63\x7f\x00\x00\x00\x00"/*"2"*/,
"\x00\x00\x3e\x63\x03\x03\x1e\x03\x03\x03\x63\x3e\x00\x00\x00\x00"/*"3"*/, //20
"\x00\x00\x06\x0e\x1e\x36\x66\x66\x7f\x06\x06\x0f\x00\x00\x00\x00"/*"4"*/,
"\x00\x00\x7f\x60\x60\x60\x7e\x03\x03\x63\x73\x3e\x00\x00\x00\x00"/*"5"*/,
"\x00\x00\x1c\x30\x60\x60\x7e\x63\x63\x63\x63\x3e\x00\x00\x00\x00"/*"6"*/,
"\x00\x00\x7f\x63\x03\x06\x06\x0c\x0c\x18\x18\x18\x00\x00\x00\x00"/*"7"*/,
"\x00\x00\x3e\x63\x63\x63\x3e\x63\x63\x63\x63\x3e\x00\x00\x00\x00"/*"8"*/,
"\x00\x00\x3e\x63\x63\x63\x63\x3f\x03\x03\x06\x3c\x00\x00\x00\x00"/*"9"*/,
"\x00\x00\x00\x00\x00\x18\x18\x00\x00\x00\x18\x18\x00\x00\x00\x00"/*":"*/,
"\x00\x00\x00\x00\x00\x18\x18\x00\x00\x00\x18\x18\x18\x30\x00\x00"/*";"*/,
"\x00\x00\x00\x06\x0c\x18\x30\x60\x30\x18\x0c\x06\x00\x00\x00\x00"/*"<"*/,
"\x00\x00\x00\x00\x00\x00\x7e\x00\x00\x7e\x00\x00\x00\x00\x00\x00"/*"="*/, //30
"\x00\x00\x00\x60\x30\x18\x0c\x06\x0c\x18\x30\x60\x00\x00\x00\x00"/*">"*/,
"\x00\x00\x3e\x63\x63\x06\x0c\x0c\x0c\x00\x0c\x0c\x00\x00\x00\x00"/*"?"*/,
"\x00\x00\x3e\x63\x63\x6f\x6b\x6b\x6e\x60\x60\x3e\x00\x00\x00\x00"/*"@"*/,
"\x00\x00\x08\x1c\x36\x63\x63\x63\x7f\x63\x63\x63\x00\x00\x00\x00"/*"A"*/,
"\x00\x00\x7e\x33\x33\x33\x3e\x33\x33\x33\x33\x7e\x00\x00\x00\x00"/*"B"*/,
"\x00\x00\x1e\x33\x61\x60\x60\x60\x60\x61\x33\x1e\x00\x00\x00\x00"/*"C"*/,
"\x00\x00\x7c\x36\x33\x33\x33\x33\x33\x33\x36\x7c\x00\x00\x00\x00"/*"D"*/,
"\x00\x00\x7f\x33\x31\x34\x3c\x34\x30\x31\x33\x7f\x00\x00\x00\x00"/*"E"*/,
"\x00\x00\x7f\x33\x31\x34\x3c\x34\x30\x30\x30\x78\x00\x00\x00\x00"/*"F"*/,
"\x00\x00\x1e\x33\x61\x60\x60\x6f\x63\x63\x37\x1d\x00\x00\x00\x00"/*"G"*/, //40
"\x00\x00\x63\x63\x63\x63\x7f\x63\x63\x63\x63\x63\x00\x00\x00\x00"/*"H"*/,
"\x00\x00\x3c\x18\x18\x18\x18\x18\x18\x18\x18\x3c\x00\x00\x00\x00"/*"I"*/,
"\x00\x00\x0f\x06\x06\x06\x06\x06\x06\x66\x66\x3c\x00\x00\x00\x00"/*"J"*/,
"\x00\x00\x73\x33\x36\x36\x3c\x36\x36\x33\x33\x73\x00\x00\x00\x00"/*"K"*/,
"\x00\x00\x78\x30\x30\x30\x30\x30\x30\x31\x33\x7f\x00\x00\x00\x00"/*"L"*/,
"\x00\x00\x63\x77\x7f\x6b\x63\x63\x63\x63\x63\x63\x00\x00\x00\x00"/*"M"*/,
"\x00\x00\x63\x63\x73\x7b\x7f\x6f\x67\x63\x63\x63\x00\x00\x00\x00"/*"N"*/,
"\x00\x00\x1c\x36\x63\x63\x63\x63\x63\x63\x36\x1c\x00\x00\x00\x00"/*"O"*/,
"\x00\x00\x7e\x33\x33\x33\x3e\x30\x30\x30\x30\x78\x00\x00\x00\x00"/*"P"*/,
"\x00\x00\x3e\x63\x63\x63\x63\x63\x63\x6b\x6f\x3e\x06\x07\x00\x00"/*"Q"*/, //50
"\x00\x00\x7e\x33\x33\x33\x3e\x36\x36\x33\x33\x73\x00\x00\x00\x00"/*"R"*/,
"\x00\x00\x3e\x63\x63\x30\x1c\x06\x03\x63\x63\x3e\x00\x00\x00\x00"/*"S"*/,
"\x00\x00\xff\xdb\x99\x18\x18\x18\x18\x18\x18\x3c\x00\x00\x00\x00"/*"T"*/,
"\x00\x00\x63\x63\x63\x63\x63\x63\x63\x63\x63\x3e\x00\x00\x00\x00"/*"U"*/,
"\x00\x00\x63\x63\x63\x63\x63\x63\x63\x36\x1c\x08\x00\x00\x00\x00"/*"V"*/,
"\x00\x00\x63\x63\x63\x63\x63\x6b\x6b\x7f\x36\x36\x00\x00\x00\x00"/*"W"*/,
"\x00\x00\xc3\xc3\x66\x3c\x18\x18\x3c\x66\xc3\xc3\x00\x00\x00\x00"/*"X"*/,
"\x00\x00\xc3\xc3\xc3\x66\x3c\x18\x18\x18\x18\x3c\x00\x00\x00\x00"/*"Y"*/,
"\x00\x00\x7f\x63\x43\x06\x0c\x18\x30\x61\x63\x7f\x00\x00\x00\x00"/*"Z"*/,
"\x00\x00\x3c\x30\x30\x30\x30\x30\x30\x30\x30\x3c\x00\x00\x00\x00"/*"["*/, //60
"\x00\x00\x80\xc0\xe0\x70\x38\x1c\x0e\x07\x03\x01\x00\x00\x00\x00"/*"\\"*/,
"\x00\x00\x3c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x3c\x00\x00\x00\x00"/*"}"*/,
"\x08\x1c\x36\x63\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"/*"^"*/,
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00"/*"_"*/,
"\x18\x18\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"/*"'"*/,
"\x00\x00\x00\x00\x00\x3c\x46\x06\x3e\x66\x66\x3b\x00\x00\x00\x00"/*"a"*/,
"\x00\x00\x70\x30\x30\x3c\x36\x33\x33\x33\x33\x6e\x00\x00\x00\x00"/*"b"*/,
"\x00\x00\x00\x00\x00\x3e\x63\x60\x60\x60\x63\x3e\x00\x00\x00\x00"/*"c"*/,
"\x00\x00\x0e\x06\x06\x1e\x36\x66\x66\x66\x66\x3b\x00\x00\x00\x00"/*"d"*/,
"\x00\x00\x00\x00\x00\x3e\x63\x63\x7e\x60\x63\x3e\x00\x00\x00\x00"/*"e"*/, //70
"\x00\x00\x1c\x36\x32\x30\x7c\x30\x30\x30\x30\x78\x00\x00\x00\x00"/*"f"*/,
"\x00\x00\x00\x00\x00\x3b\x66\x66\x66\x66\x3e\x06\x66\x3c\x00\x00"/*"g"*/,
"\x00\x00\x70\x30\x30\x36\x3b\x33\x33\x33\x33\x73\x00\x00\x00\x00"/*"h"*/,
"\x00\x00\x0c\x0c\x00\x1c\x0c\x0c\x0c\x0c\x0c\x1e\x00\x00\x00\x00"/*"i"*/,
"\x00\x00\x06\x06\x00\x0e\x06\x06\x06\x06\x06\x66\x66\x3c\x00\x00"/*"j"*/,
"\x00\x00\x70\x30\x30\x33\x33\x36\x3c\x36\x33\x73\x00\x00\x00\x00"/*"k"*/,
"\x00\x00\x1c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x1e\x00\x00\x00\x00"/*"l"*/,
"\x00\x00\x00\x00\x00\x6e\x7f\x6b\x6b\x6b\x6b\x6b\x00\x00\x00\x00"/*"m"*/,
"\x00\x00\x00\x00\x00\x6e\x33\x33\x33\x33\x33\x33\x00\x00\x00\x00"/*"n"*/,
"\x00\x00\x00\x00\x00\x3e\x63\x63\x63\x63\x63\x3e\x00\x00\x00\x00"/*"o"*/,
"\x00\x00\x00\x00\x00\x6e\x33\x33\x33\x33\x3e\x30\x30\x78\x00\x00"/*"p"*/,
"\x00\x00\x00\x00\x00\x3b\x66\x66\x66\x66\x3e\x06\x06\x0f\x00\x00"/*"q"*/,
"\x00\x00\x00\x00\x00\x6e\x3b\x33\x30\x30\x30\x78\x00\x00\x00\x00"/*"r"*/,
"\x00\x00\x00\x00\x00\x3e\x63\x38\x0e\x03\x63\x3e\x00\x00\x00\x00"/*"s"*/,
"\x00\x00\x08\x18\x18\x7e\x18\x18\x18\x18\x1b\x0e\x00\x00\x00\x00"/*"t"*/,
"\x00\x00\x00\x00\x00\x66\x66\x66\x66\x66\x66\x3b\x00\x00\x00\x00"/*"u"*/,
"\x00\x00\x00\x00\x00\x63\x63\x36\x36\x1c\x1c\x08\x00\x00\x00\x00"/*"v"*/,
"\x00\x00\x00\x00\x00\x63\x63\x63\x6b\x6b\x7f\x36\x00\x00\x00\x00"/*"w"*/,
"\x00\x00\x00\x00\x00\x63\x36\x1c\x1c\x1c\x36\x63\x00\x00\x00\x00"/*"x"*/,
"\x00\x00\x00\x00\x00\x63\x63\x63\x63\x63\x3f\x03\x06\x3c\x00\x00"/*"y"*/,
"\x00\x00\x00\x00\x00\x7f\x66\x0c\x18\x30\x63\x7f\x00\x00\x00\x00"/*"z"*/,
"\x00\x00\x0e\x18\x18\x18\x70\x18\x18\x18\x18\x0e\x00\x00\x00\x00"/*"{"*/,
"\x00\x00\x18\x18\x18\x18\x18\x00\x18\x18\x18\x18\x18\x00\x00\x00"/*"|"*/,
"\x00\x00\x70\x18\x18\x18\x0e\x18\x18\x18\x18\x70\x00\x00\x00\x00"/*"}"*/,
"\x00\x00\x3b\x6e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"/*"~"*/,
]
/**
* Read value from BOSON analog sensor
* @param pin to pin ,eg: "pin"
* @param type to type ,eg: "BosonSensorAnalogRead.BosonTemperature"
*/
//% block="analog read pin %pin %type"
//% group="Sensor"
//% weight=100
export function bosonAnalogRead(pin: AnalogPin, type: BosonSensorAnalogRead): number {
let value: number = 0;
switch (type) {
case BosonSensorAnalogRead.BosonTemperature: value = temperatureSensor(pin); break;
case BosonSensorAnalogRead.BosonHumidity: value = humiditySensor(pin); break;
case BosonSensorAnalogRead.BosonWaterproofTemperature: value = waterproofTemperatureSensor(pin); break;
case BosonSensorAnalogRead.BosonUltrasonicDistance: value = ultrasonicDistanceSensor(pin); break;
case BosonSensorAnalogRead.BosonSHT30Humidity: value = humiditySht30(pin); break;
case BosonSensorAnalogRead.BosonV2Ph: value = V2pHSensor(pin); break;
default: value = pins.analogReadPin(pin); break;
}
return value;
}
/**
* Write analog value(0-1023) to BOSON analog sensor
* @param pin to pin ,eg: "pin"
* @param value to value, eg: "0~1023"
* @param type to type ,eg: "BosonSensorAnalogWrite.BosonMotor"
*/
//% block="analog write pin %pin to %value %type"
//% group="Sensor"
//% value.min=0 value.max=1023
//% weight=90
export function bosonAnalogWrite(pin: AnalogPin, value: number, type: BosonSensorAnalogWrite): void {
switch (type) {
case BosonSensorAnalogWrite.BosonMotor: if (value > 1000) { value = 1000; } pins.analogWritePin(pin, value); break;
default: pins.analogWritePin(pin, value); break;
}
}
/**
* Read value from BOSON digital sensor
* @param pin to pin ,eg: "pin"
* @param type to type ,eg: "BosonSensorDigitalRead.BosonConductivity"
*/
//% block="digital read pin %pin %type"
//% group="Sensor"
//% weight=80
export function bosonDigitalRead(pin: DigitalPin, type: BosonSensorDigitalRead): number {
let value: number = 0;
switch (type) {
case BosonSensorDigitalRead.BosonConductivity: value = pins.digitalReadPin(pin); break;
default: value = pins.digitalReadPin(pin); break;
}
return value;
}
/**
* Write digital value(0/1) to BOSON digital sensor
* @param pin to pin ,eg: "pin"
* @param value to value, eg: "0~1"
* @param type to type ,eg: "BosonSensorDigitalWrite.BosonBrightLightLed"
*/
//% block="digital write pin %pin to %value %type"
//% group="Sensor"
//% value.min=0 value.max=1
//% weight=70
export function bosonDigitalWrite(pin: DigitalPin, value: number, type: BosonSensorDigitalWrite): void {
switch (type) {
case BosonSensorDigitalWrite.BosonBrightLightLed: pins.digitalWritePin(pin, value); break;
default: pins.digitalWritePin(pin, value); break;
}
}
/**
* Initialize heart rate sensor
* @param pin to pin ,eg: "pin"
*/
//% block="init pin %pin heart rate sensor (i20)"
//% group="Sensor"
//% weight=60
//% advanced=true
export function heartrateInit(pin: DigitalPin): void {
pins.setEvents(pin, PinEventType.Touch);
switch (pin) {
case DigitalPin.P0: control.onEvent(EventBusSource.MICROBIT_ID_IO_P0, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P1: control.onEvent(EventBusSource.MICROBIT_ID_IO_P1, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P2: control.onEvent(EventBusSource.MICROBIT_ID_IO_P2, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P3: control.onEvent(EventBusSource.MICROBIT_ID_IO_P3, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P4: control.onEvent(EventBusSource.MICROBIT_ID_IO_P4, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P5: control.onEvent(EventBusSource.MICROBIT_ID_IO_P5, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P6: control.onEvent(EventBusSource.MICROBIT_ID_IO_P6, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P7: control.onEvent(EventBusSource.MICROBIT_ID_IO_P7, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P8: control.onEvent(EventBusSource.MICROBIT_ID_IO_P8, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P9: control.onEvent(EventBusSource.MICROBIT_ID_IO_P9, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P10: control.onEvent(EventBusSource.MICROBIT_ID_IO_P10, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P11: control.onEvent(EventBusSource.MICROBIT_ID_IO_P11, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P12: control.onEvent(EventBusSource.MICROBIT_ID_IO_P12, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P13: control.onEvent(EventBusSource.MICROBIT_ID_IO_P13, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P14: control.onEvent(EventBusSource.MICROBIT_ID_IO_P14, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P15: control.onEvent(EventBusSource.MICROBIT_ID_IO_P15, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
case DigitalPin.P16: control.onEvent(EventBusSource.MICROBIT_ID_IO_P16, EventBusValue.MICROBIT_BUTTON_EVT_CLICK, pinCallback); break;
default: break;
}
beattime1 = 0;
beattime2 = 0;
}
/**
* Get heart rate(bpm)
*/
//% block="read heart rate (bpm) (i20)"
//% group="Sensor"
//% weight=50
//% advanced=true
export function heartrateRead(): number {
if (averagetime == 0) {
return 0;
}
let value: number = Math.round(29000 / averagetime);
return value;
}
/**
* Initialize a given number of LEDs on the RGB LED strip at a specific pin
* @param pin to pin ,eg: "pin"
* @param num to num ,eg: "1~7"
*/
//% block="initialize RGB strip at pin %pin with %num leds"
//% group="Actuator"
//% num.min=1 num.max=7 num.defl=3
//% weight=100
export function m01100184Init(pin: DigitalPin, num: number): void {
rgb_pin = pin;
neopixel_buf = pins.createBuffer(3 * num);
for (let i = 0; i < 3 * num; i++) {
neopixel_buf[i] = 0;
}
ledsum = num;
}
/**
* Set the brightness of RGB lights
* @param brightness to brightness ,eg: "0~255"
*/
//% block="set brightness %brightness"
//% group="Actuator"
//% brightness.min=0 brightness.max=255 brightness.defl=255
//% weight=90
//% advanced=true
export function m01100184Brightness(brightness: number): void {
_brightness = brightness;
}
/**
* The LED positions where you wish to begin and end
* @param from to start ,eg: "1~7"
* @param to to end ,eg: "1~7"
*/
//% block="leds from %from to %to"
//% group="Actuator"
//% from.min=1 from.max=7 from.defl=1
//% to.min=1 to.max=7 to.defl=2
//% weight=80
export function m01100184LedRange(from: number, to: number): number {
return ((from - 1) << 16) + (2 << 8) + (to);
}
/**
* The designated LED shows a given color
* @param index to index ,eg: "1~7"
* @param color to color ,eg: "color"
*/
//% block="led %index show color %color"
//% group="Actuator"
//% index.min=1 index.max=7 index.defl=1
//% color.shadow="colorNumberPicker"
//% weight=70
export function m01100184SetIndexColor(index: number, color: number): void {
let f = index - 1;
let t = index - 1;
let r = (color >> 16) * (_brightness / 255);
let g = ((color >> 8) & 0xFF) * (_brightness / 255);
let b = ((color) & 0xFF) * (_brightness / 255);
if ((index - 1) > 15) {
if ((((index - 1) >> 8) & 0xFF) == 0x02) {
f = (index - 1) >> 16;
t = (index - 1) & 0xff;
} else {
f = 0;
t = -1;
}
}
for (let i = f; i <= t; i++) {
neopixel_buf[i * 3 + 0] = Math.round(g)
neopixel_buf[i * 3 + 1] = Math.round(r)
neopixel_buf[i * 3 + 2] = Math.round(b)
}
ws2812b.sendBuffer(neopixel_buf, rgb_pin);
}
/**
* All LEDs show a given color
* @param rgb to rgb ,eg: "rgb"
*/
//% block="show color %rgb"
//% group="Actuator"
//% weight=60
//% rgb.shadow="colorNumberPicker"
export function m01100184ShowColor(rgb: number) {
let r = (rgb >> 16) * (_brightness / 255);
let g = ((rgb >> 8) & 0xFF) * (_brightness / 255);
let b = ((rgb) & 0xFF) * (_brightness / 255);
for (let i = 0; i < 3 * ledsum; i++) {
if ((i % 3) == 0)
neopixel_buf[i] = Math.round(g)
if ((i % 3) == 1)
neopixel_buf[i] = Math.round(r)
if ((i % 3) == 2)
neopixel_buf[i] = Math.round(b)
}
ws2812b.sendBuffer(neopixel_buf, rgb_pin)
}
/**
* Shift LEDs forward and clear with zeros
* @param offset to offset ,eg: "offset"
*/
//% block="shift pixels by %offset"
//% group="Actuator"
//% weight=52
//% advanced=true
export function m01100184Shift(offset: number): void {
let steps = ledsum
if (offset > steps) {
for (let i = 0; i < 16 * steps; i++) {
neopixel_buf[i] = 0;
}
}
if (ledsum > 1 && offset != 0) {
if (offset > 0) {
for (let i = steps - 1; i >= offset; i--) {
neopixel_buf[i * 3] = neopixel_buf[(i - offset) * 3]
neopixel_buf[i * 3 + 1] = neopixel_buf[(i - offset) * 3 + 1]
neopixel_buf[i * 3 + 2] = neopixel_buf[(i - offset) * 3 + 2]
}
for (let i = 0; i < offset; i++) {
neopixel_buf[i * 3] = 0
neopixel_buf[i * 3 + 1] = 0
neopixel_buf[i * 3 + 2] = 0
}
}
else {
for (let i = 0; i <= steps - Math.abs(offset); i++) {
neopixel_buf[i * 3] = neopixel_buf[(i + Math.abs(offset)) * 3]
neopixel_buf[i * 3 + 1] = neopixel_buf[(i + Math.abs(offset)) * 3 + 1]
neopixel_buf[i * 3 + 2] = neopixel_buf[(i + Math.abs(offset)) * 3 + 2]
}
for (let i = steps - Math.abs(offset); i < steps; i++) {
neopixel_buf[i * 3] = 0
neopixel_buf[i * 3 + 1] = 0
neopixel_buf[i * 3 + 2] = 0
}
}
ws2812b.sendBuffer(neopixel_buf, rgb_pin)
}
}
/**
* Rotate LEDs forward
* @param offset to offset ,eg: "offset"
*/
//% block="rotate pixels by %offset"
//% group="Actuator"
//% weight=51
//% advanced=true
export function m01100184Rotate(offset: number): void {
let steps = ledsum
if (offset > 0) {
offset = offset % steps;
} else {
offset = Math.abs(offset) % steps;
offset = -offset;
}
if (ledsum > 1 && offset != 0) {
if (offset > 0) {
let offdata = pins.createBuffer(3 * offset);
for (let i = 0; i < offset; i++) {
offdata[i * 3] = neopixel_buf[(steps - offset + i) * 3]
offdata[i * 3 + 1] = neopixel_buf[(steps - offset + i) * 3 + 1]
offdata[i * 3 + 2] = neopixel_buf[(steps - offset + i) * 3 + 2]
}
for (let i = steps - 1; i >= offset; i--) {
neopixel_buf[i * 3] = neopixel_buf[(i - offset) * 3]
neopixel_buf[i * 3 + 1] = neopixel_buf[(i - offset) * 3 + 1]
neopixel_buf[i * 3 + 2] = neopixel_buf[(i - offset) * 3 + 2]
}
for (let i = 0; i < offset; i++) {
neopixel_buf[i * 3] = offdata[i * 3]
neopixel_buf[i * 3 + 1] = offdata[i * 3 + 1]
neopixel_buf[i * 3 + 2] = offdata[i * 3 + 2]
}
ws2812b.sendBuffer(neopixel_buf, rgb_pin)
}
else {
let offdata = pins.createBuffer(3 * Math.abs(offset));
for (let i = 0; i < Math.abs(offset); i++) {
offdata[i * 3] = neopixel_buf[i * 3]
offdata[i * 3 + 1] = neopixel_buf[i * 3 + 1]
offdata[i * 3 + 2] = neopixel_buf[i * 3 + 2]
}
for (let i = 0; i <= steps - Math.abs(offset); i++) {
neopixel_buf[i * 3] = neopixel_buf[(i + Math.abs(offset)) * 3]
neopixel_buf[i * 3 + 1] = neopixel_buf[(i + Math.abs(offset)) * 3 + 1]
neopixel_buf[i * 3 + 2] = neopixel_buf[(i + Math.abs(offset)) * 3 + 2]
}
for (let i = steps - Math.abs(offset); i < steps; i++) {
neopixel_buf[i * 3] = offdata[(i - steps + Math.abs(offset)) * 3]
neopixel_buf[i * 3 + 1] = offdata[(i - steps + Math.abs(offset)) * 3 + 1]
neopixel_buf[i * 3 + 2] = offdata[(i - steps + Math.abs(offset)) * 3 + 2]
}
ws2812b.sendBuffer(neopixel_buf, rgb_pin)
}
}
}
/**
* Turn off all LEDs
*/
//% block="clear all"
//% group="Actuator"
//% weight=50
export function m01100184Off(): void {
m01100184ShowColor(0);
}
/**
* Convert red, green and blue channels into a RGB color
* @param red to red ,eg: "0~255"
* @param green to green ,eg: "0~255"
* @param blue to blue ,eg: "0~255"
*/
//% block="red %red green %green blue %blue"
//% group="Actuator"
//% red.min=0 red.max=255 red.defl=0
//% green.min=0 green.max=255 green.defl=0
//% blue.min=0 blue.max=255 blue.defl=0
//% weight=40
//% advanced=true
export function m01100184Rgb(red: number, green: number, blue: number): number {
return (red << 16) + (green << 8) + (blue);
}
/**
* LED strip shows gradient color
* @param start to start ,eg: "1~7"
* @param end to end ,eg: "1~7"
* @param startHue to startHue ,eg: "0~360"
* @param endHue to endHue ,eg: "0~360"
*/
//% weight=50
//% group="Actuator"
//% startHue.defl=1
//% endHue.defl=360
//% startHue.min=0 startHue.max=360
//% endHue.min=0 endHue.max=360
//% start.min=1 start.max=7 start.defl=1
//% end.min=1 end.max=7 end.defl=5
//% block="RGB LED %start to %end show gradient color from %startHue to %endHue"
//% inlineInputMode=inline
//% advanced=true
export function m01100184LedRainbow(start: number, end: number, startHue: number, endHue: number) {
start = start - 1
end = end - 1
if ((end < start)) {
let num = end;
end = start;
start = num;
}
start = Math.max(start, 0);
start = Math.min(start, ledsum);
end = Math.max(end, 0);
end = Math.min(end, ledsum);
let steps = end - start + 1;
// startHue = startHue >> 0;
// endHue = endHue >> 0;
const saturation = 100;
const luminance = 50;
// let steps = ledsum + 1;
// const direction = HueInterpolationDirection.Clockwise;
//hue
const h1 = startHue;
const h2 = endHue;
const hDistCW = ((h2 + 360) - h1) % 360;
const hStepCW = Math.idiv((hDistCW * 100), steps);
// const hDistCCW = ((h1 + 360) - h2) % 360;
// const hStepCCW = Math.idiv(-(hDistCCW * 100), steps);
let hStep: number = hStepCW;
// if (direction === HueInterpolationDirection.Clockwise) {
// hStep = hStepCW;
// } else if (direction === HueInterpolationDirection.CounterClockwise) {
// hStep = hStepCCW;
// } else {
// hStep = hDistCW < hDistCCW ? hStepCW : hStepCCW;
// }
const h1_100 = h1 * 100; //we multiply by 100 so we keep more accurate results while doing interpolation
//sat
const s1 = saturation;
const s2 = saturation;
const sDist = s2 - s1;
const sStep = Math.idiv(sDist, steps);
const s1_100 = s1 * 100;
//lum
const l1 = luminance;
const l2 = luminance;
const lDist = l2 - l1;
const lStep = Math.idiv(lDist, steps);
const l1_100 = l1 * 100
//interpolate
if (steps === 1) {
writeBuff(start, hsl(h1 + hStep, s1 + sStep, l1 + lStep))
} else {
writeBuff(start, hsl(startHue, saturation, luminance));
for (let i = start + 1; i < start + steps - 1; i++) {
const h = Math.idiv((h1_100 + i * hStep), 100) + 360;
const s = Math.idiv((s1_100 + i * sStep), 100);
const l = Math.idiv((l1_100 + i * lStep), 100);
writeBuff(0 + i, hsl(h, s, l));
}
writeBuff(start + steps - 1, hsl(endHue, saturation, luminance));
}
ws2812b.sendBuffer(neopixel_buf, rgb_pin)
}
/**
* Servo rotates to a specific angle
* @param pin to pin ,eg: "pin"
* @param angle to angle ,eg: "0~180"
*/
//% block="9g servo module pin %pin angle %angle"
//% group="Actuator"
//% angle.min=0 angle.max=180
//% weight=36
export function setServoAngle(pin: AnalogPin, angle: number): void {
pins.servoWritePin(pin, angle);
}
/**
* Used to set the I2C address and initialization configuration of the OLED display
* @param address to address ,eg: 0x3C
*/
//% block="OLED 128*64 init address $address"
//% group="Display"
//% weight=34
//% advanced=true
export function oledInit(address: number) {
oledArdress = address;
oledBegin();
}
/**
* Display numbers in the specified line
* @param row to row ,eg: 1
* @param num to num ,eg: 20
*/
//% block="OLED 128*64 Row $row display $num"
//% group="Display"
//% row.min=1 row.max=4
//% weight=33
//% advanced=true
export function oledInLineNumber(row: number, num: number) {
setCursorLine(row);
writeCharLine(convertToText(num));
}
/**
* Display letters, numbers, symbols, and other text information on the specified line
* @param row to row ,eg: 1
* @param str to str ,eg: "hello"
*/
//% block="OLED 128*64 Row $row display $str"
//% group="Display"
//% row.min=1 row.max=4
//% weight=32
//% advanced=true
export function oledInLine(row: number, str: string) {
setCursorLine(row);
writeCharLine(str);
}
/**
* Display numbers at specified coordinates
* @param num to num ,eg: 20
* @param x to x ,eg: "42"
* @param y to y ,eg: bosonKit.YRAW.Y1
*/
//% block="OLED 128*64 display $num at position X: $x Y: 16*$y"
//% group="Display"
//% weight=31
//% advanced=true
export function oledInXYNumber(num: number, x: number, y: YRAW) {
oledInXY(convertToText(num), x, y);
}
/**
* Display letters, numbers, symbols, and other text information at specified coordinates
* @param str to str ,eg: "hello"
* @param x to x ,eg: "42"
* @param y to y ,eg: bosonKit.YRAW.Y1
*/
//% block="OLED 128*64 display $str at position X: $x Y: 16*$y"
//% group="Display"
//% weight=30
//% advanced=true
export function oledInXY(str: string, x: number, y: YRAW) {
setCursor(x, y * 16);
for (let c of str) {
writeChar(c);
}
}
/**
* Clear all content from the display screen
*/
//% block="OLED 128*64 clear"
//% group="Display"
//% weight=28
//% advanced=true
export function oledClear() {
fillScreen(0);
}
/**
* WIFI initialization
* @param receive to receive ,eg: SerialPin.P1
* @param send to send ,eg: SerialPin.P2
* @param ssid to ssid ,eg: "yourSSID"
* @param password to password ,eg: "yourPASSWORD"
*/
//% block="Wi-Fi configure|Pin Rx:%receive|Pin Tx:%send|Wi-Fi name:%ssid|Wi-Fi password:%password|start connection"
//% group="Obloq"
//% receive.fieldEditor="gridpicker" receive.fieldOptions.columns=3
//% send.fieldEditor="gridpicker" send.fieldOptions.columns=3
//% weight=26
export function wifiInit(receive: SerialPin, send: SerialPin, ssid: string, password: string): void {
obloqWifiSsid = ssid;
obloqWifiPassword = password;
obloqSerialTx = send;
obloqSerialRx = receive;
obloqSerialInit();
for (let i = 0; i < 3; i++) {
obloqWriteString("|1|1|\r");
basic.pause(100);
}
obloqWriteString("|1|4|\r");
basic.pause(2000);
obloqStartConnectHttp();
}
/**
* MQTT initialization
* @param user to user ,eg: "yourApiKey"
* @param pwd to pwd ,eg: "yourSecretKey"
* @param topic to topic ,eg: "yourIotTopic"
* @param server to receive ,eg: Servers.China
*/
//% block="MQTT configure|IoT_ID(user):%user|IoT_PWD(password):%pwd|Topic(default Topic0):%topic|server:%server||IP(SIOT):%ip"
//% group="Obloq"
//% server.fieldEditor="gridpicker" server.fieldOptions.columns=2
//% weight=24
export function mqttInit(user: string, pwd: string, topic: string, server: Servers, ip?: string):
void {
//obloqWifiSsid = SSID
// obloqWifiPassword = PASSWORD
obloqMqttPwd = pwd
obloqMqttId = user
obloqMqttTopic[0][0] = topic
obloqMqttEasyIotSiot = ip
//obloqSerialTx = send
//obloqSerialRx = receive
obloqStartConnectMqtt(server, "connect mqtt")
}
/**
* MQTT sends a message.
* @param mess set mess, eg: "message"
* @param top set top, eg: TOPIC.Topic0
*/
//% block="send message %mess |to %top"
//% group="Obloq"
//% top.fieldEditor="gridpicker" top.fieldOptions.columns=2
//% weight=22
export function mqttSendMessageMore(mess: string, top: TOPIC): void {
while (obloqWorkingModeIsStop) { basic.pause(20) }
if (!obloqMqttInit) {
return
}
if (!obloqSerialInitFlag) {
obloqSerialInit()
}
switch (top) {
case TOPIC.Topic0: obloqWriteString("|4|1|3|" + obloqMqttTopic[0][0] + "|" + mess + "|\r"); break;