kopia lustrzana https://github.com/backface/turtlestitch
1 wiersz
41 KiB
XML
1 wiersz
41 KiB
XML
<blocks app="Snap! 5.1, http://snap.berkeley.edu" version="1"><block-definition s="Hummingbird %'sensor' %'port'" type="reporter" category="sensing"><header></header><code></code><translations></translations><inputs><input type="%txt" readonly="true">Light<options>Distance (cm)
Dial
Light
Sound
Other (V)</options></input><input type="%n" readonly="true">1<options>1
2
3</options></input></inputs><script><block s="doDeclareVariables"><list><l>value</l></list></block><block s="doIf"><block s="reportEquals"><block var="sensor"/><l>Other (V)</l></block><script><block s="doSetVar"><l>sensor</l><l>Other</l></block></script></block><block s="doIf"><block s="reportEquals"><block var="sensor"/><l>Distance (cm)</l></block><script><block s="doSetVar"><l>sensor</l><l>Distance</l></block></script></block><block s="doSetVar"><l>value</l><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/in/</l><block var="sensor"/><l>/</l><block var="port"/></list></block></block></block><block s="doIfElse"><block s="reportNot"><block s="reportEquals"><block var="value"/><l>Not Connected</l></block></block><script><block s="doIf"><block s="reportEquals"><block var="sensor"/><l>Distance</l></block><script><block s="doReport"><block s="reportRound"><block s="reportProduct"><l>1.17</l><block var="value"/></block></block><comment w="90" collapsed="false">117/100 Scaling factor</comment></block></script></block><block s="doIf"><block s="reportEquals"><block var="sensor"/><l>Other</l></block><script><block s="doReport"><block s="reportQuotient"><block s="reportRound"><block s="reportProduct"><block s="reportProduct"><l>0.01294</l><block var="value"/></block><l>100</l></block></block><l>100</l></block><comment w="102" collapsed="false">3.3/255 scale factor</comment></block></script></block><block s="doIf"><block s="reportEquals"><block var="sensor"/><l>Sound</l><comment w="155" collapsed="true">If connected, adjust sound level</comment></block><script><block s="doReport"><block s="reportRound"><block s="reportProduct"><l>0.784</l><block var="value"/><comment w="140" collapsed="false">200/255 Scaling factor</comment></block></block></block></script></block><block s="doIf"><block s="reportEquals"><block var="sensor"/><l>Light</l></block><script><block s="doReport"><block s="reportRound"><block s="reportProduct"><l>0.392</l><block var="value"/><comment w="140" collapsed="false">100/255 Scaling factor</comment></block></block></block></script></block><block s="doIf"><block s="reportEquals"><block var="sensor"/><l>Dial</l></block><script><block s="doReport"><block s="reportRound"><block s="reportProduct"><l>0.435</l><block var="value"/><comment w="140" collapsed="false">100/230 Scaling factor</comment></block></block></block></script></block></script><script><block s="doReport"><l>Not Connected</l></block></script></block></script></block-definition><block-definition s="Hummingbird Play Note %'note' for %'beats' beats" type="command" category="sound"><header></header><code></code><translations>ko:Hummingbird _ 번 음을 _ 박자로 연주하기
de:Hummingbird Spiele Note _ für _ Schläge
pt:Hummingbird Toque Notas _ por _ Batidas
fr:Hummingbird Jouer la note _ pour _ battement(s)
nl:Hummingbird Speel Noot _ voor _ Beats
zh_CN:Hummingbird 演奏 音阶 _ 于 _ 拍
zh_TW:Hummingbird 演奏 音階 _ 於 _ 拍
ar:Hummingbird تشغيل الموسيقى _ _
dk:Hummingbird Spil tone _ i _ slag
he:Hummingbird נגן תו _ במשך _ פעימות
es:Hummingbird Emitir un sonido _ por _ pulsos
ca:Hummingbird Toca nota _ durant _ temps
fi:Hummingbird Soita sävel _ _ iskun ajan
sv:Hummingbird Spela not _ _
</translations><inputs><input type="%n">60</input><input type="%n">0.5</input></inputs><script><block s="doIf"><block s="reportGreaterThan"><block var="note"/><l>135</l></block><script><block s="doSetVar"><l>note</l><l>135</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><l>32</l><block var="note"/></block><script><block s="doSetVar"><l>note</l><l>32</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><block var="beats"/><l>16</l></block><script><block s="doSetVar"><l>beats</l><l>16</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><l>0</l><block var="beats"/></block><script><block s="doSetVar"><l>beats</l><l>0</l></block></script></block><block s="doSetVar"><l>beats</l><block s="reportRound"><block s="reportProduct"><block s="reportQuotient"><l>60000</l><block s="getTempo"></block></block><block var="beats"/></block><comment w="242" collapsed="false">BPM = tempo
60 * 1000/BPM = BPMS beats per millisecond
beats = Duration in ms = BPMS * number of beats</comment></block></block><block s="doRun"><block s="reifyReporter"><autolambda><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/out/playnote/</l><block var="note"/><l>/</l><block var="beats"/></list></block></block></autolambda><list></list></block><list></list></block><block s="doWait"><block s="reportQuotient"><block var="beats"/><l>1000</l></block><comment w="205" collapsed="false">block for number of seconds</comment></block></script></block-definition><block-definition s="micro:bit %'device' %'dim'" type="reporter" category="sensing"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true">Accelerometer (m/s²)<options>Accelerometer (m/s²)
Magnetometer (µT)</options></input><input type="%txt" readonly="true">X<options>X
Y
Z</options></input></inputs><script><block s="doIf"><block s="reportEquals"><block var="device"/><l>Accelerometer (m/s²)</l></block><script><block s="doSetVar"><l>device</l><l>Accelerometer</l></block></script></block><block s="doIf"><block s="reportEquals"><block var="device"/><l>Magnetometer (µT)</l></block><script><block s="doSetVar"><l>device</l><l>Magnetometer</l></block></script></block><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/in/</l><block var="device"/><l>/</l><block var="dim"/></list></block></block></block></script></block-definition><block-definition s="micro:bit Button %'button'" type="predicate" category="sensing"><header></header><code></code><translations>ko:micro:bit 버튼 _
de:micro:bit Knopf _
pt:micro:bit Tecla _
fr:micro:bit Bouton _
nl:micro:bit Knop _
zh_CN:micro:bit 按钮 _
zh_TW:micro:bit 按鈕 _
ar:micro:bit زر _
dk:micro:bit Knap _
he:micro:bit לחצן _
es:micro:bit Pulsador _
ca:micro:bit Botó _
fi:micro:bit Painike _
sv:micro:bit Knapp _
</translations><inputs><input type="%txt" readonly="true">A<options>A
B</options></input></inputs><script><block s="doIfElse"><block s="reportEquals"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/in/button/</l><block var="button"/></list></block></block><l>true</l></block><script><block s="doReport"><block s="reportBoolean"><l><bool>true</bool></l></block></block></script><script><block s="doReport"><block s="reportBoolean"><l><bool>false</bool></l></block></block></script></block></script></block-definition><block-definition s="micro:bit Compass" type="reporter" category="sensing"><header></header><code></code><translations>ko:micro:bit 나침반 센서
de:micro:bit Kompass
pt:micro:bit Bússola
fr:micro:bit Compas
nl:micro:bit Kompas
zh_CN:micro:bit 指南针
zh_TW:micro:bit 指南針
ar:micro:bit بوصلة
dk:micro:bit Kompas
he:micro:bit מצפן
es:micro:bit Brujula
ca:micro:bit Brúixola
fi:micro:bit Kompassi
sv:micro:bit Kompass
</translations><inputs></inputs><script><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/in/</l><l>Compass</l></list></block></block></block></script></block-definition><block-definition s="micro:bit %'dim'" type="predicate" category="sensing"><header></header><code></code><translations></translations><inputs><input type="%txt" readonly="true">Screen Up<options>Screen Up
Screen Down
Tilt Left
Tilt Right
Logo Up
Logo Down
Shake</options></input></inputs><script><block s="doIfElse"><block s="reportEquals"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/in/orientation/</l><block var="dim"/></list></block></block><l>true</l></block><script><block s="doReport"><block s="reportBoolean"><l><bool>true</bool></l></block></block></script><script><block s="doReport"><block s="reportBoolean"><l><bool>false</bool></l></block></block></script></block></script></block-definition><block-definition s="stop all" type="command" category="control"><header></header><code></code><translations>ko:모두 멈추기
de:stoppe alles
pt:pare todos
fr:stop tout
nl:stop alle
zh_CN:停止 全部
zh_TW:停止 全部
ar:توقف الكل
dk:stop alle
he:להפסיק הכל
es:detener todo
ca:atura tot
fi:pysäytä kaikki
sv:stop allt
</translations><inputs></inputs><script><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/out/stopall</l></list></block></block></block></script></block-definition><block-definition s="Hummingbird Position Servo %'port' %'position' °" type="command" category="motion"><header></header><code></code><translations>ko:Hummingbird 위치 제어 서보 _ _ °
de:Hummingbird Position Servo _ _ °
pt:Hummingbird Posição do Servo _ _ °
fr:Hummingbird Position Servo _ _ °
nl:Hummingbird Positie-Servo _ _ °
zh_CN:Hummingbird 位置伺服 _ _ °
zh_TW:Hummingbird 位置伺服 _ _ °
ar:Hummingbird موقف محرك سيرفو المؤازر _ _
dk:Hummingbird Positionsservo _ _ °
he:Hummingbird סרוו כיוון _ _
es:Hummingbird Servo de posicion _ _ °
ca:Hummingbird Servo posicional _ _ °
fi:Hummingbird Asentoservo _ _ °
sv:Hummingbird Positionsservo _ _ °
</translations><inputs><input type="%n" readonly="true">1<options>1
2
3
4</options></input><input type="%n">90</input></inputs><script><block s="doIf"><block s="reportLessThan"><block var="position"/><l>0</l></block><script><block s="doSetVar"><l>position</l><l>0</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><block var="position"/><l>180</l></block><script><block s="doSetVar"><l>position</l><l>180</l></block></script></block><block s="doSetVar"><l>position</l><block s="reportRound"><block s="reportProduct"><block var="position"/><l>1.41</l></block></block><comment w="228" collapsed="false">254/180 Scaling Factor</comment></block><block s="doRun"><block s="reportJSFunction"><list><l>portnum</l><l>position</l></list><l>var realPort = portnum-1;
////////////////////////////////////////////////////////////////////////////////
// In order to avoid sending more messages than the app can handle, whenever we
// send a message we also save it in a persistent global variable. When the
// message is processed in the app, the callback checks if the global variable
// still matches what it was changed to. If it was, it deletes the global
// variable. Otherwise the message is resent with new data.
//
// When this block is called it checks if the global value has been set. If it
// has, it sends a message. Otherwise it just updates the value and lets the
// callback handle it.


// We can't run code beforehand to define values so we must check each block
// call if they are set.
if (window.birdbrain === undefined || window.birdbrain.servos === undefined) {
 window.birdbrain = window.birdbrain || {};
 window.birdbrain.servos = {
 // By attaching this function to a global variable, it is only
 // defined once instead of every time this block is called, improving
 // performance significantly.
 setServoAngle: function (port, angle) {
 function callback() {
 if (window.birdbrain.servos[port] === angle) {
 delete window.birdbrain.servos[port];
 }
 else {
 window.birdbrain.servos.setServoAngle(port, window.birdbrain.servos[port]);
 }
 }

 //Create a new XMLHttpRequest object
 var xhr = new XMLHttpRequest();
 var actualPort = port+1; 
 var thisURL = "http://127.0.0.1:30061/hummingbird/out/servo/" + actualPort + "/" + angle;
 //console.log("thisURL: " + thisURL);
 xhr.open("GET", thisURL, true);
 xhr.onload = function (e) {
 if (xhr.readyState === 4) {
 if (xhr.status === 200) {
 callback();
 } else {
 console.error(xhr.statusText);
 }
 }
 };
 xhr.onerror = function (e) {
 console.error(xhr.statusText);
 };
 xhr.send(null); 
 
 }
 };
}

//var realAngle = Math.floor(ang*1.25);

//realAngle = Math.max(Math.min(realAngle,225.0),0.0);

if (window.birdbrain.servos[realPort] === undefined) {
 window.birdbrain.servos.setServoAngle(realPort, position);
}

window.birdbrain.servos[realPort] = position;</l></block><list><block var="port"/><block var="position"/></list></block><block s="doWait"><l>0</l></block></script><scripts><script x="187.14285714285717" y="82.28571428571428"><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/out/servo/</l><l></l><l>/</l><l></l></list></block></block></block></script></scripts></block-definition><block-definition s="Hummingbird Rotation Servo %'port' %'speed' %" type="command" category="motion"><header></header><code></code><translations>ko:Hummingbird 회전속도 제어 서보 _ _ %
de:Hummingbird Drehung Servo _ _ %
pt:Hummingbird Rotação do Servo _ _ %
fr:Hummingbird Rotation Servo _ _ %
nl:Hummingbird Draai-Servo _ _ %
zh_CN:Hummingbird 旋转伺服 _ _ %
zh_TW:Hummingbird 旋轉伺服 _ _ %
ar:Hummingbird فتحة دوران المحرك المؤازر _ _
dk:Hummingbird Rotationsservo _ _ %
he:Hummingbird סרוו סיבובים _ _ %
es:Hummingbird Servo de rotacion _ _ %
ca:Hummingbird Servo rotacional _ _ %
fi:Hummingbird Kiertoservo _ _ %
sv:Hummingbird Rotationsservo _ _ %
</translations><inputs><input type="%n" readonly="true">1<options>1
2
3
4</options></input><input type="%n">0</input></inputs><script><block s="doIf"><block s="reportLessThan"><block var="speed"/><l>-100</l></block><script><block s="doSetVar"><l>speed</l><l>-100</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><block var="speed"/><l>100</l></block><script><block s="doSetVar"><l>speed</l><l>100</l></block></script></block><block s="doIfElse"><block s="reportAnd"><block s="reportGreaterThan"><block var="speed"/><l>-10</l></block><block s="reportLessThan"><block var="speed"/><l>10</l></block></block><script><block s="doSetVar"><l>speed</l><l>255</l></block></script><script><block s="doSetVar"><l>speed</l><block s="reportRound"><block s="reportSum"><block s="reportQuotient"><block s="reportProduct"><block var="speed"/><l>23</l></block><l>100</l></block><l>122</l></block></block></block></script></block><block s="doRun"><block s="reportJSFunction"><list><l>portnum</l><l>speed</l></list><l>var realPort = portnum-1;
////////////////////////////////////////////////////////////////////////////////
// In order to avoid sending more messages than the app can handle, whenever we
// send a message we also save it in a persistent global variable. When the
// message is processed in the app, the callback checks if the global variable
// still matches what it was changed to. If it was, it deletes the global
// variable. Otherwise the message is resent with new data.
//
// When this block is called it checks if the global value has been set. If it
// has, it sends a message. Otherwise it just updates the value and lets the
// callback handle it.


// We can't run code beforehand to define values so we must check each block
// call if they are set.
if (window.birdbrain === undefined || window.birdbrain.rotationServos === undefined) {
 window.birdbrain = window.birdbrain || {};
 window.birdbrain.rotationServos = {
 // By attaching this function to a global variable, it is only
 // defined once instead of every time this block is called, improving
 // performance significantly.
 setServoSpeed: function (port, speed) {
 function callback() {
 if (window.birdbrain.rotationServos[port] === speed) {
 delete window.birdbrain.rotationServos[port];
 }
 else {
 window.birdbrain.rotationServos.setServoSpeed(port, window.birdbrain.rotationServos[port]);
 }
 }

 //Create a new XMLHttpRequest object
 var xhr = new XMLHttpRequest();
 var actualPort = port+1; 
 var thisURL = "http://127.0.0.1:30061/hummingbird/out/rotation/" + actualPort + "/" + speed;
 //console.log("thisURL: " + thisURL);
 xhr.open("GET", thisURL, true);
 xhr.onload = function (e) {
 if (xhr.readyState === 4) {
 if (xhr.status === 200) {
 callback();
 } else {
 console.error(xhr.statusText);
 }
 }
 };
 xhr.onerror = function (e) {
 console.error(xhr.statusText);
 };
 xhr.send(null); 
 
 }
 };
}

if (window.birdbrain.rotationServos[realPort] === undefined) {
 window.birdbrain.rotationServos.setServoSpeed(realPort, speed);
}

window.birdbrain.rotationServos[realPort] = speed;</l></block><list><block var="port"/><block var="speed"/></list></block></script></block-definition><block-definition s="Hummingbird LED %'port' %'intensity' %" type="command" category="looks"><header></header><code></code><translations>ko:Hummingbird LED _ _ %
de:Hummingbird LED _ _ %
pt:Hummingbird LED _ _ %
fr:Hummingbird LED _ _ %
nl:Hummingbird LED _ _ %
zh_CN:Hummingbird LED _ _ %
zh_TW:Hummingbird LED _ _ %
ar:Hummingbird ضوء _ _
dk:Hummingbird LED _ _ %
he:Hummingbird לד % _ _
es:Hummingbird LED _ _ %
ca:Hummingbird LED _ _ %
fi:Hummingbird LED _ _ %
sv:Hummingbird LED _ _ %
</translations><inputs><input type="%n" readonly="true">1<options>1
2
3</options></input><input type="%n">0</input></inputs><script><block s="doIf"><block s="reportLessThan"><block var="intensity"/><l>0</l></block><script><block s="doSetVar"><l>intensity</l><l>0</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><block var="intensity"/><l>100</l></block><script><block s="doSetVar"><l>intensity</l><l>100</l></block></script></block><block s="doRun"><block s="reportJSFunction"><list><l>portnum,intensitynum</l></list><l>//var hummingbirdAppID = "lfloofocohhfeeoohpokmljiinfmpenj";
var realPort = portnum-1;
////////////////////////////////////////////////////////////////////////////////
// In order to avoid sending more messages than the app can handle, whenever we
// send a message we also save it in a persistent global variable. When the
// message is processed in the app, the callback checks if the global variable
// still matches what it was changed to. If it was, it deletes the global
// variable. Otherwise the message is resent with new data.
//
// When this block is called it checks if the global value has been set. If it
// has, it sends a message. Otherwise it just updates the value and lets the
// callback handle it.


// We can't run code beforehand to define values so we must check each block
// call if they are set.
if (window.birdbrain === undefined || window.birdbrain.LEDs === undefined) {
 window.birdbrain = window.birdbrain || {};
 window.birdbrain.LEDs = {
 // By attaching this function to a global variable, it is only
 // defined once instead of every time this block is called, improving
 // performance significantly.
 setLEDIntensity: function(port, intensity) {
 function callback() {
 if (window.birdbrain.LEDs[port] === intensity) {
 delete window.birdbrain.LEDs[port];
 }
 else {
 window.birdbrain.LEDs.setLEDIntensity(port, window.birdbrain.LEDs[port]);
 }
 }
 /*
 var report = {
 message:"L".charCodeAt(0),
 port: port.toString().charCodeAt(0),
 intensity: intensity
 };
 chrome.runtime.sendMessage(hummingbirdAppID, report, callback);
 */

 //Create a new XMLHttpRequest object
 var xhr = new XMLHttpRequest();
 var actualPort = port+1;
 var ledURL = "http://127.0.0.1:30061/hummingbird/out/led/" + actualPort + "/" + intensity;
 xhr.open("GET", ledURL, true);
 xhr.onload = function (e) {
 if (xhr.readyState === 4) {
 if (xhr.status === 200) {
 callback();
 } else {
 console.error(xhr.statusText);
 }
 }
 };
 xhr.onerror = function (e) {
 console.error(xhr.statusText);
 };
 xhr.send(null);

 }
 }
}

var realIntensity = Math.floor(intensitynum*2.55);

realIntensity = Math.max(Math.min(realIntensity,255.0),0.0);

if (window.birdbrain.LEDs[realPort] === undefined) {
 window.birdbrain.LEDs.setLEDIntensity(realPort, realIntensity);
}

window.birdbrain.LEDs[realPort] = realIntensity;</l></block><list><block var="port"/><block var="intensity"/></list></block><block s="doWait"><l>0</l></block></script><scripts><script x="396.42857142857144" y="46.57142857142853"><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/out/led/</l><block var="port"/><l>/</l><block var="intensity"/></list></block></block></block></script><script x="396.42857142857144" y="100.28571428571436"><block s="doSetVar"><l>intensity</l><block s="reportRound"><block s="reportProduct"><block var="intensity"/><l>2.55</l><comment w="90" collapsed="false">Scale factor 255/100</comment></block></block></block></script></scripts></block-definition><block-definition s="Hummingbird Tri-LED %'port' R %'redLED' % G %'greenLED' % B %'blueLED' %" type="command" category="looks"><header></header><code></code><translations>ko:Hummingbird 삼색 LED _ 빨강 _ % 초록 _ % 파랑 _ %
de:Hummingbird Dreifarben-LED _ R _ % G _ % B _ %
pt:Hummingbird LED Tricolor _ R _ % G _ % B _ %
fr:Hummingbird Tri-LED _ R _ % G _ % B _ %
nl:Hummingbird Tri-LED _ R _ % G _ % B _ %
zh_CN:Hummingbird 三色LED _ 红 _ % 绿 _ % 蓝 _ %
zh_TW:Hummingbird 三色LED _ 紅 _ % 綠 _ % 藍 _ %
ar:Hummingbird ضوء الصمام الثلاثي _ _ _ _
dk:Hummingbird Tri-LED _ R _ % G _ % B _ %
he:Hummingbird לד שלושה צבעים % _ R _ % G _ % B _
es:Hummingbird Led tricolor _ R _ % G _ % B _ %
ca:Hummingbird Tri-LED _ vermell _ % verd _ % blau _ %
fi:Hummingbird Tri-LED _ R _ % G _ % B _ %
sv:Hummingbird Tri-LED _ R _ % G _ % B _ %
</translations><inputs><input type="%n" readonly="true">1<options>1
2</options></input><input type="%n">0</input><input type="%n">0</input><input type="%n">0</input></inputs><script><block s="doIf"><block s="reportLessThan"><block var="redLED"/><l>0</l></block><script><block s="doSetVar"><l>redLED</l><l>0</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><block var="redLED"/><l>100</l></block><script><block s="doSetVar"><l>redLED</l><l>100</l></block></script></block><block s="doIf"><block s="reportLessThan"><block var="greenLED"/><l>0</l></block><script><block s="doSetVar"><l>greenLED</l><l>0</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><block var="greenLED"/><l>100</l></block><script><block s="doSetVar"><l>greenLED</l><l>100</l></block></script></block><block s="doIf"><block s="reportLessThan"><block var="blueLED"/><l>0</l></block><script><block s="doSetVar"><l>blueLED</l><l>0</l></block></script></block><block s="doIf"><block s="reportGreaterThan"><block var="blueLED"/><l>100</l></block><script><block s="doSetVar"><l>blueLED</l><l>100</l></block></script></block><block s="doRun"><block s="reportJSFunction"><list><l>portnum</l><l>rednum</l><l>greennum</l><l>bluenum</l></list><l>var realPort = portnum-1;
////////////////////////////////////////////////////////////////////////////////
// In order to avoid sending more messages than the app can handle, whenever we
// send a message we also save it in a persistent global variable. When the
// message is processed in the app, the callback checks if the global variable
// still matches what it was changed to. If it was, it deletes the global
// variable. Otherwise the message is resent with new data.
//
// When this block is called it checks if the global value has been set. If it
// has, it sends a message. Otherwise it just updates the value and lets the
// callback handle it.


// We can't run code beforehand to define values so we must check each block
// call if they are set.
if (window.birdbrain === undefined || window.birdbrain.triLEDs === undefined) {
 window.birdbrain = window.birdbrain || {};
 window.birdbrain.triLEDs = {
 // By attaching this function to a global variable, it is only
 // defined once instead of every time this block is called, improving
 // performance significantly.
 setLEDIntensities: function(port, intensities) {
 function callback() {
 if (JSON.stringify(window.birdbrain.triLEDs[port]) === JSON.stringify(intensities)) {
 delete window.birdbrain.triLEDs[port];
 }
 else {
 window.birdbrain.triLEDs.setLEDIntensities(port, window.birdbrain.triLEDs[port]);
 }
 }

 //Create a new XMLHttpRequest object
 var xhr = new XMLHttpRequest();
 var actualPort = port+1;
 /* Note RGB:
 red: intensities[0],
 green: intensities[1],
 blue: intensities[2] 
 */
 
 var thisURL = "http://127.0.0.1:30061/hummingbird/out/triled/" + actualPort + "/" + intensities[0] + "/" + intensities[1] + "/" + intensities[2];
 //console.log("thisURL: " + thisURL);
 xhr.open("GET", thisURL, true);
 xhr.onload = function (e) {
 if (xhr.readyState === 4) {
 if (xhr.status === 200) {
 callback();
 } else {
 console.error(xhr.statusText);
 }
 }
 };
 xhr.onerror = function (e) {
 console.error(xhr.statusText);
 };
 xhr.send(null);
 }
 }
}

var realIntensities = [rednum, greennum, bluenum].map(function(intensity) {
 return Math.floor(Math.max(Math.min(intensity*2.55, 255), 0));
});

if (window.birdbrain.triLEDs[realPort] === undefined) {
 window.birdbrain.triLEDs.setLEDIntensities(realPort, realIntensities);
}

window.birdbrain.triLEDs[realPort] = realIntensities;
</l></block><list><block var="port"/><block var="redLED"/><block var="greenLED"/><block var="blueLED"/></list></block><block s="doWait"><l>0</l></block></script><scripts><script x="251.42857142857144" y="108.85714285714293"><block s="doSetVar"><l>redLED</l><block s="reportRound"><block s="reportProduct"><block var="redLED"/><l>2.55</l><comment w="90" collapsed="false">Scale factor 255/100</comment></block></block></block><block s="doSetVar"><l>blueLED</l><block s="reportRound"><block s="reportProduct"><block var="blueLED"/><l>2.55</l><comment w="90" collapsed="false">Scale factor 255/100</comment></block></block></block><block s="doSetVar"><l>greenLED</l><block s="reportRound"><block s="reportProduct"><block var="greenLED"/><l>2.55</l><comment w="90" collapsed="false">Scale factor 255/100</comment></block></block></block><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/out/triled/</l><l></l><l>/</l><l></l><l>/</l><l></l><l>/</l><l></l></list></block></block></block></script></scripts></block-definition><block-definition s="micro:bit Print %'string'" type="command" category="looks"><header></header><code></code><translations>ko:micro:bit 출력 _
de:micro:bit Drucke _
pt:micro:bit Imprimir _
fr:micro:bit Imprimer _
nl:micro:bit Schrijf _
zh_CN:micro:bit 打印 _
zh_TW:micro:bit 打印 _
ar:micro:bit طباعة _
dk:micro:bit Vis _
he:micro:bit הדפס _
es:micro:bit Imprimir _
ca:micro:bit Escriu _
fi:micro:bit Näytä teksti _
sv:micro:bit Visa text _
</translations><inputs><input type="%txt">Hello</input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>string</l></list><l>////////////////////////////////////////////////////////////////////////////////
// In order to avoid sending more messages than the app can handle, whenever we
// send a message we also save it in a persistent global variable. When the
// message is processed in the app, the callback checks if the global variable
// still matches what it was changed to. If it was, it deletes the global
// variable. Otherwise the message is resent with new data.
//
// When this block is called it checks if the global value has been set. If it
// has, it sends a message. Otherwise it just updates the value and lets the
// callback handle it.

// Encode any special characters in the URL
string = encodeURIComponent(string);
|
|



// We can't run code beforehand to define values so we must check each block
// call if they are set.
if (window.birdbrain === undefined || window.birdbrain.printObj === undefined) {
 window.birdbrain = window.birdbrain || {};
 window.birdbrain.printObj = {
 // By attaching this function to a global variable, it is only
 // defined once instead of every time this block is called, improving
 // performance significantly.
 printString: function(string) {
 function callback() {
 if (window.birdbrain.printObj.stringToPrint === string) {
 delete window.birdbrain.printObj.stringToPrint;
 }
 else {
 window.birdbrain.printObj.printString(window.birdbrain.printObj.stringToPrint);
 }
 }
 /*
 var report = {
 message:"L".charCodeAt(0),
 port: port.toString().charCodeAt(0),
 intensity: intensity
 };
 chrome.runtime.sendMessage(hummingbirdAppID, report, callback);
 */

 //Create a new XMLHttpRequest object
 var xhr = new XMLHttpRequest();
 var printURL = "http://127.0.0.1:30061/hummingbird/out/print/" + string;
 xhr.open("GET", printURL, true);
 xhr.onload = function (e) {
 if (xhr.readyState === 4) {
 if (xhr.status === 200) {
 callback();
 } else {
 console.error(xhr.statusText);
 }
 }
 };
 xhr.onerror = function (e) {
 console.error(xhr.statusText);
 };
 xhr.send(null);

 }
 }
}

//TODO Turn '/' chars into % 

if (window.birdbrain.printObj.stringToPrint === undefined) {
 window.birdbrain.printObj.printString(string);
}

window.birdbrain.printObj.stringToPrint = string;</l></block><list><block var="string"/></list></block><block s="doWait"><l>0</l></block></script><scripts><script x="310.9999990000001" y="47"><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/out/print/</l><block var="string"/></list></block></block></block></script><script x="335" y="1024.8333343333334"><block var="intensity"/></script></scripts></block-definition><block-definition s="micro:bit Display $nl %'r1c1' %'r1c2' %'r1c3' %'r1c4' %'r1c5' $nl %'r2c1' %'r2c2' %'r2c3' %'r2c4' %'r2c5' $nl %'r3c1' %'r3c2' %'r3c3' %'r3c4' %'r3c5' $nl %'r4c1' %'r4c2' %'r4c3' %'r4c4' %'r4c5' $nl %'r5c1' %'r5c2' %'r5c3' %'r5c4' %'r5c5'" type="command" category="looks"><header></header><code></code><translations>ko:micro:bit 보이기 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
de:micro:bit LED Anzeige _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pt:micro:bit Visor _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fr:micro:bit Display _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
nl:micro:bit Scherm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
zh_CN:micro:bit 显示 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
zh_TW:micro:bit 顯示 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ar:micro:bit عرض _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dk:micro:bit Display _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
he:micro:bit מסך _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
es:micro:bit Monitor _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ca:micro:bit Pantalla _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fi:micro:bit Näytä _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
sv:micro:bit Skärm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
</translations><inputs><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input><input type="%b">false</input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>r1c1, r1c2, r1c3, r1c4, r1c5, r2c1, r2c2, r2c3, r2c4, r2c5, r3c1, r3c2, r3c3, r3c4, r3c5, r4c1, r4c2, r4c3, r4c4, r4c5, r5c1, r5c2, r5c3, r5c4, r5c5 </l></list><l>////////////////////////////////////////////////////////////////////////////////
|
|

// In order to avoid sending more messages than the app can handle, whenever we
|
|

// send a message we also save it in a persistent global variable. When the
|
|

// message is processed in the app, the callback checks if the global variable
|
|

// still matches what it was changed to. If it was, it deletes the global
|
|

// variable. Otherwise the message is resent with new data.
|
|

//
|
|

// When this block is called it checks if the global value has been set. If it
|
|

// has, it sends a message. Otherwise it just updates the value and lets the
|
|

// callback handle it.
|
|

|
|

// Create url representation from inputs
|
|

var symbolString = r1c1 + "\/"+ r1c2 + "\/"+ r1c3 + "\/"+ r1c4 + "\/"+ r1c5 + "\/" +
|
|

 r2c1 + "\/"+ r2c2 + "\/"+ r2c3 + "\/"+ r2c4 + "\/"+ r2c5 + "\/" +
|
|

 r3c1 + "\/"+ r3c2 + "\/"+ r3c3 + "\/"+ r3c4 + "\/"+ r3c5 + "\/" +
|
|

 r4c1 + "\/"+ r4c2 + "\/"+ r4c3 + "\/"+ r4c4 + "\/"+ r4c5 + "\/" +
|
|

 r5c1 + "\/"+ r5c2 + "\/"+ r5c3 + "\/"+ r5c4 + "\/"+ r5c5 ;
|
|

|
|

//r1c1, r1c2, r1c3, r1c4, r1c5, r2c1, r2c2, r2c3, r2c4, r2c5, r3c1, r3c2, r3c3, r3c4, r3c5, r4c1, r4c2, r4c3, r4c4, r4c5, r5c1, r5c2, r5c3, r5c4, r5c5
|
|

|
|

// We can't run code beforehand to define values so we must check each block
|
|

// call if they are set.
|
|

if (window.birdbrain === undefined || window.birdbrain.symbolObj === undefined) {
|
|

 window.birdbrain = window.birdbrain || {};
|
|

 window.birdbrain.symbolObj = {
|
|

 // By attaching this function to a global variable, it is only
|
|

 // defined once instead of every time this block is called, improving
|
|

 // performance significantly.
|
|

 printSymbol: function(symbol) {
|
|

 function callback() {
|
|

 if (window.birdbrain.symbolObj.symbolToPrint === symbol) { // Check if arrays are equal
|
|

 delete window.birdbrain.symbolObj.symbolToPrint;
|
|

 }
|
|

 else {
|
|

 window.birdbrain.symbolObj.printSymbol(window.birdbrain.symbolObj.symbolToPrint);
|
|

 }
|
|

 }
|
|

|
|

 //Create a new XMLHttpRequest object
|
|

 var xhr = new XMLHttpRequest();
|
|

 var symbolURL = "http://127.0.0.1:30061/hummingbird/out/symbol/A/" + symbol;
|
|

 xhr.open("GET", symbolURL, true);
|
|

 xhr.onload = function (e) {
|
|

 if (xhr.readyState === 4) {
|
|

 if (xhr.status === 200) {
|
|

 callback();
|
|

 } else {
|
|

 console.error(xhr.statusText);
|
|

 }
|
|

 }
|
|

 };
|
|

 xhr.onerror = function (e) {
|
|

 console.error(xhr.statusText);
|
|

 };
|
|

 xhr.send(null);
|
|

|
|

 }
|
|

 }
|
|

}
|
|

|
|

if (window.birdbrain.symbolObj.symbolToPrint === undefined) {
|
|

 window.birdbrain.symbolObj.printSymbol(symbolString);
|
|

}
|
|

|
|

window.birdbrain.symbolObj.symbolToPrint = symbolString;
|
|

|
|

|
|

</l></block><list><block var="r1c1"/><block var="r1c2"/><block var="r1c3"/><block var="r1c4"/><block var="r1c5"/><block var="r2c1"/><block var="r2c2"/><block var="r2c3"/><block var="r2c4"/><block var="r2c5"/><block var="r3c1"/><block var="r3c2"/><block var="r3c3"/><block var="r3c4"/><block var="r3c5"/><block var="r4c1"/><block var="r4c2"/><block var="r4c3"/><block var="r4c4"/><block var="r4c5"/><block var="r5c1"/><block var="r5c2"/><block var="r5c3"/><block var="r5c4"/><block var="r5c5"/></list></block><block s="doWait"><l></l></block></script><scripts><script x="731" y="16"><block s="doReport"><block s="reportURL"><block s="reportJoinWords"><list><l>http://127.0.0.1:30061/hummingbird/out/symbol/A/</l><block var="11"/><l>/</l><block var="12"/><l>/</l><block var="r1c3"/><l>/</l><block var="r1c4"/><l>/</l><block var="r1c5"/><l>/</l><block var="r2c1"/><l>/</l><block var="r2c2"/><l>/</l><block var="r2c3"/><l>/</l><block var="r2c4"/><l>/</l><block var="25"/><l>/</l><block var="31"/><l>/</l><block var="r3c2"/><l>/</l><block var="33"/><l>/</l><block var="34"/><l>/</l><block var="35"/><l>/</l><block var="41"/><l>/</l><block var="42"/><l>/</l><block var="43"/><l>/</l><block var="44"/><l>/</l><block var="45"/><l>/</l><block var="51"/><l>/</l><block var="52"/><l>/</l><block var="53"/><l>/</l><block var="54"/><l>/</l><block var="55"/></list></block></block></block></script></scripts></block-definition></blocks> |