Skip to content

Commit 7807aaf

Browse files
authored
Merge pull request #2995 from entrylabs/develop
[4.50.0] master <= develop
2 parents 6af4856 + 48cde62 commit 7807aaf

File tree

6 files changed

+4286
-79
lines changed

6 files changed

+4286
-79
lines changed

images/hardware/Lline.png

35.6 KB
Loading

src/playground/blocks/hardware/block_ITPLE_board.js

Lines changed: 284 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ Entry.ITPLE.setLanguage = function () {
8888
template: {
8989
ITPLE_get_analog_value: '아날로그 %1 번 값',
9090
ITPLE_get_digital_value: '디지털 %1 번 값',
91+
ITPLE_is_key_pressed: '%1 키가 눌러져 있는가?',
92+
ITPLE_value_lighting: '조도 센서 값이 %1 보다 큰가?',
93+
ITPLE_value_sound: '소리 센서 값이 %1 보다 큰가?',
9194
ITPLE_value_mapping: '%1 의 범위를 %2 ~ %3 에서 %4 ~ %5 로 바꾼 값',
9295
ITPLE_get_ultrasonic_value: '초음파센서 Trig %1 Echo %2 값',
9396
ITPLE_toggle_led: '디지털 %1 번 핀 %2 %3',
97+
ITPLE_turn_led: '%1 LED %2 %3',
9498
ITPLE_digital_pwm: '디지털 %1 번 핀을 %2 (으)로 정하기 %3',
95-
ITPLE_set_tone: '디지털 %1 번 핀의 버저를 %2 %3 음으로 %4 초 연주하기 %5',
99+
ITPLE_set_tone: '버저를 %2 %3 음으로 %4 초 연주하기 %5',
96100
ITPLE_get_digital: '디지털 %1 번 센서값',
97101
ITPLE_set_motor_direction: '%1 모터 %2 방향으로 정하기 %3',
98102
ITPLE_set_motor_speed_old: '(V1)%1 모터 %2 속도로 정하기 %3',
@@ -107,11 +111,15 @@ Entry.ITPLE.setLanguage = function () {
107111
template: {
108112
ITPLE_get_analog_value: 'Analog %1 value',
109113
ITPLE_get_digital_value: 'Digital %1 value',
114+
ITPLE_is_key_pressed: '%1 key pressed',
115+
ITPLE_value_lighting: 'Is light sensor value greater than %1',
116+
ITPLE_value_sound: 'Is sound sensor value greater than %1',
110117
ITPLE_value_mapping: 'Map Value %1 %2 ~ %3 to %4 ~ %5',
111118
ITPLE_get_ultrasonic_value: 'Read ultrasonic sensor trig pin %1 echo pin %2',
112119
ITPLE_toggle_led: 'Digital %1 Pin %2 %3',
120+
ITPLE_turn_led: '%1 LED %2 %3',
113121
ITPLE_digital_pwm: 'Digital %1 Pin %2 %3',
114-
ITPLE_set_tone: 'Play tone pin %1 on note %2 octave %3 beat %4 %5',
122+
ITPLE_set_tone: 'Play tone on note %2 octave %3 beat %4 %5',
115123
ITPLE_get_digital: 'Digital %1 Sensor value',
116124
ITPLE_set_motor_direction: '%1 motor %2 direction %3',
117125
ITPLE_set_motor_speed_old: '(old) %1 motor %2 speed %3',
@@ -128,10 +136,14 @@ Entry.ITPLE.setLanguage = function () {
128136
Entry.ITPLE.blockMenuBlocks = [
129137
'ITPLE_get_analog_value',
130138
'ITPLE_get_digital_value',
139+
'ITPLE_is_key_pressed',
140+
'ITPLE_value_lighting',
141+
'ITPLE_value_sound',
131142
'ITPLE_value_mapping',
132143
'ITPLE_get_ultrasonic_value',
133144
'ITPLE_get_digital',
134145
'ITPLE_toggle_led',
146+
'ITPLE_turn_led',
135147
'ITPLE_digital_pwm',
136148
'ITPLE_set_tone',
137149
'ITPLE_set_motor_direction',
@@ -324,6 +336,179 @@ Entry.ITPLE.getBlocks = function () {
324336
],
325337
},
326338
},
339+
ITPLE_is_key_pressed: {
340+
color: EntryStatic.colorSet.block.default.HARDWARE,
341+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
342+
fontColor: '#fff',
343+
344+
skeleton: 'basic_boolean_field',
345+
346+
params: [
347+
{
348+
type: 'Dropdown',
349+
options: [
350+
['위', 'UP'],
351+
['아래', 'DOWN'],
352+
['오른쪽', 'RIGHT'],
353+
['왼쪽', 'LEFT'],
354+
],
355+
value: 'UP',
356+
fontSize: 11,
357+
bgColor: EntryStatic.colorSet.block.darken.HARDWARE,
358+
arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE,
359+
},
360+
],
361+
362+
events: {},
363+
364+
def: {
365+
params: [null],
366+
type: 'ITPLE_is_key_pressed',
367+
},
368+
369+
paramsKeyMap: {
370+
KEY: 0,
371+
},
372+
isNotFor: ['ITPLE'],
373+
func(sprite, script) {
374+
const seletedKey = script.getField('KEY');
375+
376+
const analogPortData = Entry.hw.portData.ANALOG;
377+
const digitalPortData = Entry.hw.portData.DIGITAL;
378+
379+
switch (seletedKey) {
380+
case 'UP': {
381+
const value = analogPortData ? analogPortData[0] : 0;
382+
return value === 0;
383+
}
384+
case 'DOWN': {
385+
const value = analogPortData ? analogPortData[1] : 0;
386+
return value === 0;
387+
}
388+
case 'RIGHT': {
389+
const value = digitalPortData ? digitalPortData[8] : 1;
390+
return value === 0;
391+
}
392+
case 'LEFT': {
393+
const value = digitalPortData ? digitalPortData[7] : 1;
394+
return value === 0;
395+
}
396+
default:
397+
return false;
398+
}
399+
},
400+
401+
syntax: {
402+
js: [],
403+
py: [
404+
{
405+
syntax: '위:Arduino.analogRead(0)==0, 아래:Arduino.analogRead(1)==0, 오른쪽:Arduino.digitalRead(8)==0, 왼쪽:Arduino.digitalRead(7)==0',
406+
},
407+
],
408+
},
409+
},
410+
ITPLE_value_lighting: {
411+
// 저학년을 위한 조도센서 블록 생성
412+
color: EntryStatic.colorSet.block.default.HARDWARE,
413+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
414+
fontColor: '#fff',
415+
416+
skeleton: 'basic_boolean_field',
417+
418+
params: [
419+
{
420+
type: 'Block',
421+
accept: 'number',
422+
},
423+
],
424+
425+
events: {},
426+
427+
def: {
428+
params: [null],
429+
type: 'ITPLE_value_lighting',
430+
},
431+
432+
paramsKeyMap: {
433+
VALUE: 0,
434+
},
435+
isNotFor: ['ITPLE'],
436+
func(sprite, script) {
437+
const value = script.getValue('VALUE');
438+
439+
const analogPortData = Entry.hw.portData.ANALOG;
440+
441+
if (analogPortData) {
442+
return analogPortData[2] > value;
443+
}
444+
return false;
445+
},
446+
447+
syntax: {
448+
js: [],
449+
py: [
450+
{
451+
syntax: 'Arduino.analogRead(2) > %1',
452+
blockType: 'param',
453+
textParams: [
454+
{
455+
type: 'Block',
456+
accept: 'string',
457+
},
458+
],
459+
},
460+
],
461+
},
462+
},
463+
ITPLE_value_sound: {
464+
// 저학년을 위한 사운드센서 블록 생성
465+
color: EntryStatic.colorSet.block.default.HARDWARE,
466+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
467+
fontColor: '#fff',
468+
469+
skeleton: 'basic_boolean_field',
470+
471+
params: [
472+
{
473+
type: 'Block',
474+
accept: 'number',
475+
},
476+
],
477+
events: {},
478+
def: {
479+
params: [null],
480+
type: 'ITPLE_value_sound',
481+
},
482+
paramsKeyMap: {
483+
VALUE: 0,
484+
},
485+
isNotFor: ['ITPLE'],
486+
func(sprite, script) {
487+
const value = script.getValue('VALUE');
488+
489+
const analogPortData = Entry.hw.portData.ANALOG;
490+
491+
if (analogPortData) {
492+
return analogPortData[3] > value;
493+
}
494+
return false;
495+
},
496+
syntax: {
497+
js: [],
498+
py: [
499+
{
500+
syntax: 'Arduino.analogRead(3) > %1',
501+
blockType: 'param',
502+
textParams: [
503+
{
504+
type: 'Block',
505+
accept: 'string',
506+
},
507+
],
508+
},
509+
],
510+
},
511+
},
327512
ITPLE_value_mapping: {
328513
color: EntryStatic.colorSet.block.default.HARDWARE,
329514
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
@@ -742,6 +927,100 @@ Entry.ITPLE.getBlocks = function () {
742927
],
743928
},
744929
},
930+
ITPLE_turn_led: {
931+
// 저학년 학생을 위한, 핀 번호 없는 LED 켜기 블록
932+
color: EntryStatic.colorSet.block.default.HARDWARE,
933+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
934+
fontColor: '#fff',
935+
936+
skeleton: 'basic',
937+
938+
params: [
939+
{
940+
type: 'Dropdown',
941+
options: [
942+
['빨강', 10],
943+
['파랑', 11],
944+
],
945+
value: 10,
946+
fontSize: 11,
947+
bgColor: EntryStatic.colorSet.block.darken.HARDWARE,
948+
arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE,
949+
},
950+
{
951+
type: 'Dropdown',
952+
options: [
953+
['켜기', 'on'],
954+
['끄기', 'off'],
955+
],
956+
value: 'on',
957+
fontSize: 11,
958+
bgColor: EntryStatic.colorSet.block.darken.HARDWARE,
959+
arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE,
960+
},
961+
{
962+
type: 'Indicator',
963+
img: 'block_icon/hardware_icon.svg',
964+
size: 12,
965+
},
966+
],
967+
968+
events: {},
969+
970+
def: {
971+
params: [null],
972+
type: 'ITPLE_turn_led',
973+
},
974+
975+
paramsKeyMap: {
976+
PORT: 0,
977+
VALUE: 1,
978+
},
979+
class: 'ITPLE',
980+
isNotFor: ['ITPLE'],
981+
func(sprite, script) {
982+
const port = script.getNumberValue('PORT');
983+
let value = script.getValue('VALUE');
984+
985+
if (typeof value === 'string') {
986+
value = value.toLowerCase();
987+
}
988+
if (Entry.ITPLE.highList.indexOf(value) > -1) {
989+
value = 255;
990+
} else if (Entry.ITPLE.lowList.indexOf(value) > -1) {
991+
value = 0;
992+
} else {
993+
throw new Error();
994+
}
995+
if (!Entry.hw.sendQueue.SET) {
996+
Entry.hw.sendQueue.SET = {};
997+
}
998+
Entry.hw.sendQueue.SET[port] = {
999+
type: Entry.ITPLE.sensorTypes.DIGITAL,
1000+
data: value,
1001+
time: new Date().getTime(),
1002+
};
1003+
return script.callReturn();
1004+
},
1005+
syntax: {
1006+
js: [],
1007+
py: [
1008+
{
1009+
syntax: 'Arduino.digitalWrite(%1, %2)',
1010+
textParams: [
1011+
{
1012+
type: 'Block',
1013+
accept: 'string',
1014+
},
1015+
{
1016+
type: 'Block',
1017+
accept: 'string',
1018+
},
1019+
],
1020+
},
1021+
],
1022+
},
1023+
},
7451024
ITPLE_digital_pwm: {
7461025
color: EntryStatic.colorSet.block.default.HARDWARE,
7471026
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
@@ -975,6 +1254,7 @@ Entry.ITPLE.getBlocks = function () {
9751254
},
9761255
},
9771256
ITPLE_set_tone: {
1257+
// 버저 핀번호 가림 업데이트
9781258
color: EntryStatic.colorSet.block.default.HARDWARE,
9791259
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
9801260
skeleton: 'basic',
@@ -1036,7 +1316,7 @@ Entry.ITPLE.getBlocks = function () {
10361316
isNotFor: ['ITPLE'],
10371317
func(sprite, script) {
10381318
const sq = Entry.hw.sendQueue;
1039-
const port = script.getNumberValue('PORT', script);
1319+
const port = 3;
10401320

10411321
if (!script.isStart) {
10421322
let note = script.getValue('NOTE', script);
@@ -1117,7 +1397,7 @@ Entry.ITPLE.getBlocks = function () {
11171397
js: [],
11181398
py: [
11191399
{
1120-
syntax: 'Arduino.tone(%1, %2, %3, %4)',
1400+
syntax: 'Arduino.tone(3, %2, %3, %4)',
11211401
textParams: [
11221402
{
11231403
type: 'Block',

0 commit comments

Comments
 (0)