Skip to content

Commit 23e2223

Browse files
committed
Entry Js PUBLISH by v3.20250526.216
1 parent 86233a3 commit 23e2223

File tree

8 files changed

+5228
-1521
lines changed

8 files changed

+5228
-1521
lines changed

dist/entry.js

Lines changed: 2383 additions & 572 deletions
Large diffs are not rendered by default.

dist/entry.min.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/playground/blocks/hardware/block_robotis.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ Entry.Robotis_carCont = {
5151
this.update();
5252
return script.callReturn();
5353
}
54-
// clear portData only if not RB-100 practical kit
54+
// clear portData only if not RB-100
5555
if (Entry.hw.hwModule.id != "7.A,7.B" &&
56-
Entry.hw.hwModule.id != "7.C" ) {
56+
Entry.hw.hwModule.id != "7.C" &&
57+
Entry.hw.hwModule.id != "7.5,7.6" &&
58+
Entry.hw.hwModule.id != "7.7,7.8" &&
59+
Entry.hw.hwModule.id != "7.9") {
5760
Entry.hw.portData = {};
5861
}
5962
setTimeout(function() {

src/playground/blocks/hardware/block_robotisRBPracticalAssembly.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,8 @@ Entry.Robotis_rb_P_Assembly.setLanguage = function () {
824824
robotis_ai_camera_center_arrow_target_x: "끝점 X좌표",
825825
robotis_ai_camera_center_arrow_target_y: "끝점 Y좌표",
826826

827-
robotis_plant_ripe: "빨간색으로 잘 익은",
828-
robotis_plant_unripe: "초록색으로 덜 익은",
827+
robotis_plant_ripe: "빨간색",
828+
robotis_plant_unripe: "초록색",
829829
robotis_harvest: "수확하고",
830830
robotis_not_harvest: "수확하지 않고",
831831
},

src/playground/blocks/hardware/block_smartCodingHouse.js

Lines changed: 89 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ Entry.smartCodingHouse = {
3131

3232
// 핀 매핑 (참고용)
3333
analogPin: {
34-
ULTRASONIC_TRIG: 0,
35-
ULTRASONIC_ECHO: 1,
36-
TEMP_HUM: 2,
37-
IR_SENSOR: 3,
38-
LIGHT_SENSOR: 4,
39-
RAIN_SENSOR: 5,
34+
ULTRASONIC_TRIG: 0, // 초음파센서 trig
35+
ULTRASONIC_ECHO: 1, // 초음파센서 echo
36+
TEMP_HUM: 2, // 온습도센서
37+
IR_SENSOR: 3, // 적외선센서
38+
LIGHT_SENSOR: 4, // 조도센서
39+
RAIN_SENSOR: 5, // 레인센서서
4040
},
4141
digitalPin: {
42-
SERVO_MOTOR: 2, // 서보모터 제어 (D2)
43-
DC_MOTOR: 3, // DC모터 (D3) – 방향과 속도를 하나의 값으로 결합
42+
SERVO_MOTOR: 2, // 서보모터
43+
DC_MOTOR: 3, // DC모터 – 방향과 속도를 하나의 값으로 결합
4444
OUTDOOR1_LED_RED: 5, // 1층 실외 빨강 LED
4545
OUTDOOR1_LED_GREEN: 6, // 1층 실외 초록 LED
4646
OUTDOOR1_LED_BLUE: 7, // 1층 실외 파란 LED
@@ -122,91 +122,93 @@ function hexToRgb(hex) {
122122
let num = parseInt(hex, 16);
123123
return { r: (num >> 16) & 255, g: (num >> 8) & 255, b: num & 255 };
124124
}
125+
125126
// RGB를 HSV로 변환하는 함수
126127
function rgbToHsv(r, g, b) {
127128
// 0~255 범위의 값을 0~1 범위로 정규화
128129
r /= 255;
129130
g /= 255;
130131
b /= 255;
131-
132+
132133
// 최대값과 최소값 찾기
133134
let max = Math.max(r, g, b);
134135
let min = Math.min(r, g, b);
135136
let h,
136-
s,
137-
v = max;
137+
s,
138+
v = max;
138139
let d = max - min;
139-
140+
140141
// 채도(saturation) 계산: 최대값이 0이면 0, 아니면 (최대-최소)/최대
141142
s = max === 0 ? 0 : d / max;
142-
143+
143144
// 색조(hue) 계산
144145
if (max === min) {
145-
// 무채색인 경우(hue는 정의할 수 없음; 0으로 지정)
146-
h = 0;
146+
// 무채색인 경우(hue는 정의할 수 없음; 0으로 지정)
147+
h = 0;
147148
} else {
148-
if (max === r) {
149-
h = (g - b) / d + (g < b ? 6 : 0);
150-
} else if (max === g) {
151-
h = (b - r) / d + 2;
152-
} else {
153-
h = (r - g) / d + 4;
154-
}
155-
h /= 6; // 0~1 사이의 값으로 정규화
149+
if (max === r) {
150+
h = (g - b) / d + (g < b ? 6 : 0);
151+
} else if (max === g) {
152+
h = (b - r) / d + 2;
153+
} else {
154+
h = (r - g) / d + 4;
155+
}
156+
h /= 6; // 0~1 사이의 값으로 정규화
156157
}
157-
158+
158159
// 결과 객체 반환: h는 0~1, s는 0~1, v는 0~1
159160
return { h: h, s: s, v: v };
160-
}
161-
162-
// HSV 값을 RGB로 변환하는 함수
163-
function hsvToRgb(h, s, v) {
161+
}
162+
163+
// HSV 값을 RGB로 변환하는 함수
164+
function hsvToRgb(h, s, v) {
164165
let r, g, b;
165166
const i = Math.floor(h * 6);
166167
const f = h * 6 - i;
167168
const p = v * (1 - s);
168169
const q = v * (1 - f * s);
169170
const t = v * (1 - (1 - f) * s);
170171
switch (i % 6) {
171-
case 0:
172-
(r = v), (g = t), (b = p);
173-
break;
174-
case 1:
175-
(r = q), (g = v), (b = p);
176-
break;
177-
case 2:
178-
(r = p), (g = v), (b = t);
179-
break;
180-
case 3:
181-
(r = p), (g = q), (b = v);
182-
break;
183-
case 4:
184-
(r = t), (g = p), (b = v);
185-
break;
186-
case 5:
187-
(r = v), (g = p), (b = q);
188-
break;
172+
case 0:
173+
(r = v), (g = t), (b = p);
174+
break;
175+
case 1:
176+
(r = q), (g = v), (b = p);
177+
break;
178+
case 2:
179+
(r = p), (g = v), (b = t);
180+
break;
181+
case 3:
182+
(r = p), (g = q), (b = v);
183+
break;
184+
case 4:
185+
(r = t), (g = p), (b = v);
186+
break;
187+
case 5:
188+
(r = v), (g = p), (b = q);
189+
break;
189190
}
190191
return {
191-
r: Math.round(r * 255),
192-
g: Math.round(g * 255),
193-
b: Math.round(b * 255),
192+
r: Math.round(r * 255),
193+
g: Math.round(g * 255),
194+
b: Math.round(b * 255),
194195
};
195-
}
196+
}
196197

197198
// 블록이 아니라, 일반 함수로 선언
198-
Entry.smartCodingHouse.modeDoor = function () {
199+
Entry.smartCodingHouse.modeDoor = function() {
199200
let port = Entry.smartCodingHouse.digitalPin.SERVO_MOTOR;
200201
// 서보모터를 90도로 설정
201202
Entry.hw.sendQueue[port] = 4;
202203
Entry.hw.update && Entry.hw.update();
203-
204+
204205
setTimeout(() => {
205206
Entry.hw.sendQueue[port] = 0;
206207
Entry.hw.update && Entry.hw.update();
207208
}, 26);
208209
};
209210

211+
210212
Entry.smartCodingHouse.getBlocks = function () {
211213
return {
212214
set_ultrasonic_input: {
@@ -234,22 +236,27 @@ Entry.smartCodingHouse.getBlocks = function () {
234236
paramsKeyMap: { EXPECTED: 0, THRESHOLD: 1 },
235237
def: {
236238
type: 'set_ultrasonic_input',
237-
params: [null, { type: 'number', params: ['3'] }],
239+
params: [null, { type: 'number', params: ['20'] }],
238240
},
239241
class: 'SmartCodingHouseSensor',
240242
isNotFor: ['smartCodingHouse'],
241243
func: function (sprite, script) {
242244
var expected = script.getField('EXPECTED', script); // "near" 또는 "far"
243-
var threshold = script.getNumberValue('THRESHOLD', script); // 임계값 (기본 3)
245+
var threshold = script.getNumberValue('THRESHOLD', script); // 임계값 (기본 20cm)
244246
var distance = Number(Entry.hw.portData.ultrasonic);
245-
if (isNaN(distance)) return false;
247+
248+
if (isNaN(distance)) {
249+
// 만약 ultrasonic이 NaN이면, a1 값을 대신 사용
250+
distance = Number(Entry.hw.portData.a1);
251+
}
252+
// console.log('[DEBUG] Ultrasonic sensor reading: ' + distance + ' cm');
253+
246254
// 센서 값이 임계값보다 작으면 "near", 이상이면 "far"
247255
var actual = distance < threshold ? 'near' : 'far';
248256
return actual === expected;
249257
},
250258
},
251259

252-
// ── 온습도 센서 블록 ─────────────────────────────
253260
set_temp_hum_input: {
254261
color: EntryStatic.colorSet.block.default.HARDWARE,
255262
outerLine: EntryStatic.colorSet.block.default.HARDWARE,
@@ -286,24 +293,36 @@ Entry.smartCodingHouse.getBlocks = function () {
286293
func: function (sprite, script) {
287294
var sensorType = script.getField('TYPE', script); // "temperature" 또는 "humidity"
288295
var expected = script.getField('EXPECTED', script);
296+
// a2 채널에서 수신한 결합된 값을 가져옴
297+
var combined = Number(Entry.hw.portData.a2);
298+
// Arduino에서 보낸 값은 (온도×100 + 습도)를 5로 나눈 값이므로,
299+
// 원래 값을 복원하려면 5를 곱해줌
300+
var value = combined * 5;
301+
// 온도는 몫, 습도는 나머지로 분리 (예: 25°C, 50% → 25×100+50 = 2550)
302+
var temp = Math.floor(value / 100);
303+
var humi = value % 100;
304+
305+
console.log('[DEBUG] combined: ' + combined);
306+
console.log('[DEBUG] temp: ' + temp);
307+
console.log('[DEBUG] humi: ' + humi);
308+
309+
if (isNaN(combined)) {
310+
combined = Number(Entry.hw.portData.a2);
311+
}
312+
289313
if (sensorType === 'temperature') {
290-
var temp = Number(Entry.hw.portData.temperature);
291-
if (isNaN(temp)) return false;
292-
// 25℃를 기준으로 온도가 높으면 "hot", 낮으면 "cold"
293314
var actual = temp > 25 ? 'hot' : 'cold';
294-
// 예상 결과가 온도 관련 옵션이 아니면 false 반환
295315
if (expected !== 'hot' && expected !== 'cold') return false;
296316
return actual === expected;
297317
} else {
298-
var humi = Number(Entry.hw.portData.humidity);
299-
if (isNaN(humi)) return false;
300-
// 50%를 기준으로 습도가 높으면 "wet", 낮으면 "dry"
301318
var actual = humi > 50 ? 'wet' : 'dry';
302319
if (expected !== 'wet' && expected !== 'dry') return false;
303320
return actual === expected;
304321
}
322+
305323
},
306324
},
325+
307326

308327
set_light_input: {
309328
color: EntryStatic.colorSet.block.default.HARDWARE,
@@ -543,6 +562,7 @@ Entry.smartCodingHouse.getBlocks = function () {
543562
Entry.smartCodingHouse.modeDoor();
544563
break;
545564
default:
565+
console.log('Unknown mode: ' + mode);
546566
}
547567
return script.callReturn();
548568
},
@@ -692,14 +712,10 @@ Entry.smartCodingHouse.getBlocks = function () {
692712
let location = script.getField('LOCATION', script);
693713
let color = script.getStringField('COLOR', script);
694714
if (!location) {
715+
console.error('Error: LOCATION 값이 undefined!');
695716
return script.callReturn();
696717
}
697718
let rgb = hexToRgb(color);
698-
let hsv = rgbToHsv(rgb.r, rgb.g, rgb.b); // RGB → HSV
699-
hsv.s = 1.0; // 채도 100%
700-
hsv.v = 1.0; // 밝기 100%
701-
rgb = hsvToRgb(hsv.h, hsv.s, hsv.v); // HSV → RGB
702-
703719
let pinR, pinG, pinB;
704720
if (location === 'OUTDOOR1') {
705721
pinR = Entry.smartCodingHouse.digitalPin.OUTDOOR1_LED_RED;
@@ -714,6 +730,10 @@ Entry.smartCodingHouse.getBlocks = function () {
714730
pinG = Entry.smartCodingHouse.digitalPin.TERRACE2_LED_GREEN;
715731
pinB = Entry.smartCodingHouse.digitalPin.TERRACE2_LED_BLUE;
716732
}
733+
// 콘솔 로그로 선택된 포트 번호 확인
734+
// console.log('LED OFF - Location:', location);
735+
// console.log('Port Red:', pinR, 'Port Green:', pinG, 'Port Blue:', pinB);
736+
717737
// LED 출력: 하드웨어 업데이트 전에 값 할당
718738
Entry.hw.sendQueue[pinR] = rgb.r;
719739
Entry.hw.sendQueue[pinG] = rgb.g;
@@ -734,7 +754,7 @@ Entry.smartCodingHouse.getBlocks = function () {
734754
{
735755
type: 'Dropdown',
736756
options: [
737-
['1층 실내', 'INDOOR'],
757+
['실내', 'INDOOR'],
738758
['1층 실외', 'OUTDOOR1'],
739759
['2층 테라스', 'TERRACE2'],
740760
],

0 commit comments

Comments
 (0)