Add delay block type, add home button
authorNick Downing <nick@ndcode.org>
Fri, 23 Nov 2018 00:00:00 +0000 (11:00 +1100)
committerNick Downing <nick@ndcode.org>
Fri, 23 Nov 2018 00:00:00 +0000 (11:00 +1100)
index.html.jst

index 7c7f965..d01b8fa 100644 (file)
@@ -42,6 +42,15 @@ return async env => {
             }
           }
         }
+        block(type="delay") {
+          value(name="millisec") {
+            shadow(type="math_number") {
+              field(name="NUM") {
+                '1000'
+              }
+            }
+          }
+        }
         block(type="math_arithmetic") {
           value(name="A") {
             shadow(type="math_number") {
@@ -101,12 +110,12 @@ return async env => {
     async _out => {
       div.container-fluid {
         div.row(style="margin-top: 10px; margin-bottom: 0px;") {
-          div.col-md-4 {
-            h1(style="margin-top: 0px;") {
+          div.col-md-3 {
+            h2(style="margin-top: 0px;") {
               'MiRobot Demonstration'
             }
           }
-          div.col-md-6(style="text-align: right;") {
+          div.col-md-5(style="text-align: right;") {
             div.form-group.form-inline {
               label(style="margin-right: 6px;") {
                 'Connected device:'
@@ -121,6 +130,11 @@ return async env => {
               }
             }
           }
+          div.col-md-2(style="text-align: right;") {
+            button.btn#home(type="button" style="width: 50%;") {
+              'Home'
+            }
+          }
           div.col-md-2(style="text-align: right;") {
             button.btn#run(type="button" style="width: 50%;") {
               'Run'
@@ -209,7 +223,19 @@ return async env => {
             "previousStatement": null,
             "nextStatement": null,
             "colour": "%{BKY_LOGIC_HUE}" 
+          },
+          {
+            "type": "delay",
+            "message0": "delay %1",
+            "args0": [
+               {"type": "input_value", "name": "millisecs", "check": "Number"},
+            ],
+            "inputsInline": true,
+            "previousStatement": null,
+            "nextStatement": null,
+            "colour": "%{BKY_LOGIC_HUE}" 
           }
    
         ]);
 
@@ -229,6 +255,12 @@ return async env => {
           return 'await deviceGripper(' + d + ');\n'
         };
 
+        Blockly.JavaScript['delay'] = function(block) {
+          var millisecs = Blockly.JavaScript.valueToCode(block, 'millisecs',
+              Blockly.JavaScript.ORDER_COMMA) || '0';
+          return 'await delay(' + millisecs + ');\n'
+        };
+
         var deviceA = 90;
         var deviceB = 90;
         var deviceC = 90;
@@ -532,6 +564,35 @@ return async env => {
           }
         );
 
+        document.getElementById('home').addEventListener(
+          'click',
+          async () => {
+            if (device && !deviceBusy) {
+              deviceBusy = true;
+
+              deviceA = 90;
+              deviceB = 105;
+              deviceC = 70;
+              deviceD = 80;
+              deviceE = 90;
+              deviceF = 90;
+              setToolboxTimeout();
+   
+              A.value = 90
+              B.value = 105
+              C.value = 70
+              D.value = 80
+              E.value = 90
+              F.value = 90
+
+              await deviceSend("A090010\nB105010\nC070010\nD080010\nE090010\nF090010\n");
+              await delay(90 * 50);
+
+              deviceBusy = false;
+            }
+          }
+        );
         document.getElementById('run').addEventListener(
           'click',
           async () => {