Skip to content

Commit 47d1d93

Browse files
authored
Merge pull request #2475 from pyocoding/develop-hw
표쌤코딩 기능추가
2 parents c7835d0 + 3e88a95 commit 47d1d93

File tree

1 file changed

+294
-1
lines changed

1 file changed

+294
-1
lines changed

src/playground/blocks/hardware/block_0uboard.js

Lines changed: 294 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Entry.pyocoding = {
3737
OLED: 241,
3838
COM: 242,
3939
NEOPIXELCOLOR: 243,
40-
40+
DOTMATRIX: 245,
4141
},
4242
duration: {
4343
TIME_1ms: 1,
@@ -103,6 +103,10 @@ Entry.pyocoding.setLanguage = function() {
103103
pyocoding_neopixel_all_led: '네오픽셀 %1 번에 LED R: %2 , G: %3 , B: %4 색을 밝기 %5 으로 켜기',
104104
pyocoding_digital_pwm: '디지털 %1 번 핀을 %2 (으)로 정하기 %3',
105105
pyocoding_set_tone: '디지털 %1 번 핀을 %2 음으로 %3 옥타브로 %4 만큼 연주하기 %5',
106+
pyocoding_change_4095to255_value: '%1 값 %2을 %3로 변환하기',
107+
pyocoding_change_analog_to_temperature_tc_value: '아날로그 온도 변환 %1',
108+
pyocoding_get_touch_value : '터치 %1 센서값',
109+
pyocoding_dotmatrix : '도트매트릭스 %1 번 배열에 %2 을 그리기',
106110
},
107111
},
108112
en: {
@@ -137,6 +141,10 @@ Entry.pyocoding.setLanguage = function() {
137141
pyocoding_neopixel_all_led: '디지털 %1 번 핀에 연결된 %2 번째 네오픽셀 LED R: %3 , G: %4 , B: %5 색으로 켜기',
138142
pyocoding_digital_pwm: 'Digital %1 Pin %2 %3',
139143
pyocoding_set_tone: 'Play tone pin %1 on note %2 octave %3 beat %4 %5',
144+
pyocoding_change_4095to255_value: 'Analog 4095to255 %1',
145+
pyocoding_change_analog_to_temperature_tc_value: 'Analog to Tc %1',
146+
pyocoding_get_touch_value : 'touch %1 value',
147+
pyocoding_dotmatrix : '도트매트릭스 %1 번 배열에 %2 을 그리기',
140148
},
141149
},
142150
};
@@ -158,6 +166,10 @@ Entry.pyocoding.blockMenuBlocks = [
158166
'pyocoding_neopixel_set',
159167
'pyocoding_neopixel_led',
160168
'pyocoding_neopixel_all_led',
169+
'pyocoding_change_4095to255_value',
170+
'pyocoding_change_analog_to_temperature_tc_value',
171+
'pyocoding_get_touch_value',
172+
'pyocoding_dotmatrix',
161173

162174
];
163175

@@ -295,11 +307,151 @@ Entry.pyocoding.getBlocks = function() {
295307
func: function (sprite, script) {
296308
var port = script.getValue("PORT", script);
297309
var ANALOG = Entry.hw.portData.ANALOG;
310+
//console.log(port,ANALOG)
298311
if (port[0] === "A")
299312
port = port.substring(1)
300313
return ANALOG ? ANALOG[port] || 0 : 0;
301314
},
302315
},
316+
pyocoding_get_touch_value: {
317+
color: EntryStatic.colorSet.block.default.HARDWARE,
318+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
319+
skeleton: 'basic_string_field',
320+
statements: [],
321+
events: {},
322+
params: [
323+
{
324+
"type": "Dropdown",
325+
"options": [
326+
[ "A3", "3" ],
327+
//[ "A5", "5" ],
328+
],
329+
"value": "3",
330+
"fontSize": 11,
331+
bgColor: EntryStatic.colorSet.block.darken.HARDWARE,
332+
arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE,
333+
},
334+
],
335+
def: {
336+
params: [ null ],
337+
"type": "pyocoding_get_touch_value"
338+
},
339+
isNotFor: [ '0uboard' ],
340+
class: "SENSOR",
341+
paramsKeyMap: {
342+
"PORT": 0,
343+
},
344+
func: function (sprite, script) {
345+
var port = script.getValue("PORT", script);
346+
var ANALOG = Entry.hw.portData.ANALOG;
347+
console.log(port,ANALOG)
348+
if (port[0] === "A")
349+
port = port.substring(1)
350+
return ANALOG ? ANALOG[5] || 0 : 0;
351+
},
352+
},
353+
pyocoding_change_4095to255_value: {
354+
color: EntryStatic.colorSet.block.default.HARDWARE,
355+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
356+
skeleton: 'basic_string_field',
357+
statements: [],
358+
events: {},
359+
params: [
360+
{
361+
"type": "Block",
362+
"accept": "string"
363+
},
364+
{
365+
"type": "Block",
366+
"accept": "string"
367+
},
368+
{
369+
"type": "Block",
370+
"accept": "string"
371+
},
372+
],
373+
def: {
374+
params: [
375+
{
376+
"type": "text",
377+
"params": [ "0" ]
378+
},
379+
{
380+
"type": "text",
381+
"params": [ "4095" ]
382+
},
383+
{
384+
"type": "text",
385+
"params": [ "255" ]
386+
},
387+
],
388+
"type": "pyocoding_change_4095to255_value"
389+
},
390+
isNotFor: [ '0uboard' ],
391+
class: "ext",
392+
paramsKeyMap: {
393+
"VALUE": 0,
394+
"VALUE2": 1,
395+
"VALUE3": 2,
396+
},
397+
func: function (sprite, script) {
398+
var value = script.getNumberValue("VALUE");
399+
var value2 = script.getNumberValue("VALUE2");
400+
var value3 = script.getNumberValue("VALUE3");
401+
console.log(value,value2,value3);
402+
var dividedValue = Math.floor(value / (value2 / value3));
403+
404+
return dividedValue;
405+
},
406+
},
407+
pyocoding_change_analog_to_temperature_tc_value: {
408+
color: EntryStatic.colorSet.block.default.HARDWARE,
409+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
410+
skeleton: 'basic_string_field',
411+
statements: [],
412+
events: {},
413+
params: [
414+
{
415+
"type": "Block",
416+
"accept": "string"
417+
},
418+
],
419+
def: {
420+
params: [
421+
{
422+
"type": "text",
423+
"params": [ "0" ]
424+
},
425+
null
426+
],
427+
"type": "pyocoding_change_analog_to_temperature_tc_value"
428+
},
429+
isNotFor: [ '0uboard' ],
430+
class: "ext",
431+
paramsKeyMap: {
432+
"VALUE": 0,
433+
},
434+
func: function (sprite, script) {
435+
436+
var R1 = 10000;
437+
var logR2, R2, T, Tc, Tf;
438+
var c1 = 1.106836861e-03, c2 = 2.384641754e-04, c3 = 0.6507394466e-07;
439+
440+
var Vo = script.getNumberValue("VALUE");
441+
442+
R2 = R1 * ((4095.0 / Vo) - 1.0);
443+
logR2 = Math.log(R2);
444+
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
445+
Tc = T - 273.15; //섭씨
446+
//Tf = (Tc * 9.0)/ 5.0 + 32.0; //화씨
447+
448+
// Print the result to the console
449+
//console.log("vo:",Vo,"Tc:",Tc);
450+
451+
// You can return the value in Fahrenheit as well
452+
return Tc;
453+
},
454+
},
303455
pyocoding_get_port_number: {
304456
color: EntryStatic.colorSet.block.default.HARDWARE,
305457
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
@@ -1388,6 +1540,147 @@ Entry.pyocoding.getBlocks = function() {
13881540
syntax: {
13891541
},
13901542
},
1543+
pyocoding_dotmatrix: {
1544+
color: EntryStatic.colorSet.block.default.HARDWARE,
1545+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
1546+
skeleton: 'basic',
1547+
statements: [],
1548+
params: [
1549+
{
1550+
"type": "Dropdown",
1551+
"options": [
1552+
["0","0"],
1553+
["1","1"],
1554+
["2","2"],
1555+
["3","3"],
1556+
["4","4"],
1557+
["5","5"],
1558+
["6","6"],
1559+
["7","7"],
1560+
],
1561+
"value":"0",
1562+
"fontSize":11,
1563+
bgColor: EntryStatic.colorSet.block.darken.HARDWARE,
1564+
arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE,
1565+
},
1566+
{
1567+
type: 'Block',
1568+
accept: 'string',
1569+
defaultType: 'number',
1570+
},
1571+
{
1572+
type: 'Block',
1573+
accept: 'string',
1574+
defaultType: 'number',
1575+
},
1576+
{
1577+
type: 'Block',
1578+
accept: 'string',
1579+
defaultType: 'number',
1580+
},
1581+
{
1582+
type: 'Block',
1583+
accept: 'string',
1584+
defaultType: 'number',
1585+
},
1586+
{
1587+
type: 'Indicator',
1588+
img: 'block_icon/hardware_icon.svg',
1589+
size: 12,
1590+
},
1591+
],
1592+
events: {},
1593+
def: {
1594+
params: [
1595+
null,
1596+
{
1597+
type: 'number',
1598+
params: ['00001111'],
1599+
},
1600+
{
1601+
type: 'number',
1602+
params: ['255'],
1603+
},
1604+
{
1605+
type: 'number',
1606+
params: ['255'],
1607+
},
1608+
{
1609+
type: 'number',
1610+
params: ['100'],
1611+
},
1612+
null,
1613+
],
1614+
type: 'pyocoding_dotmatrix',
1615+
},
1616+
paramsKeyMap: {
1617+
INDEX : 0,
1618+
RED: 1,
1619+
GREEN: 2,
1620+
BLUE: 3,
1621+
BRIG: 4,
1622+
},
1623+
class: 'neopixel',
1624+
isNotFor: ['0uboard'],
1625+
func(sprite, script) {
1626+
var port = script.getNumberValue("INDEX");
1627+
var red = script.getNumberValue("RED");
1628+
var green = script.getNumberValue("GREEN");
1629+
var blue = script.getNumberValue("BLUE");
1630+
var brig = script.getNumberValue("BRIG");
1631+
var mode = 3;
1632+
1633+
let str = parseInt(String(red), 2);
1634+
red = str;
1635+
1636+
if(red > 255) red=255;
1637+
console.log(red);
1638+
1639+
1640+
if (!script.isStart)
1641+
{
1642+
1643+
if(!Entry.hw.sendQueue['SET']) {
1644+
Entry.hw.sendQueue['SET'] = {};
1645+
}
1646+
var duration = Entry.Orange.duration.TIME_10ms;
1647+
script.isStart = true;
1648+
script.timeFlag = 1;
1649+
1650+
Entry.hw.sendQueue['SET'][port] = {
1651+
type: Entry.pyocoding.sensorTypes.DOTMATRIX,
1652+
data:
1653+
{
1654+
index : port,
1655+
mode: mode,
1656+
red: red,
1657+
green: green,
1658+
blue: blue,
1659+
brig: brig,
1660+
},
1661+
time: new Date().getTime()
1662+
};
1663+
setTimeout(function() {
1664+
script.timeFlag = 0;
1665+
}, duration );
1666+
return script;
1667+
}
1668+
else if (script.timeFlag == 1)
1669+
{
1670+
return script;
1671+
}
1672+
else
1673+
{
1674+
delete script.timeFlag;
1675+
delete script.isStart;
1676+
1677+
Entry.engine.isContinue = false;
1678+
return script.callReturn();
1679+
}
1680+
},
1681+
syntax: {
1682+
},
1683+
},
13911684
} //return
13921685
}; //function
13931686

0 commit comments

Comments
 (0)