1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using Bridge.Text.RegularExpressions;
|
---|
5 |
|
---|
6 | namespace WebMrbc
|
---|
7 | {
|
---|
8 | public class CallBlock : Block
|
---|
9 | {
|
---|
10 | public const string type_name = "call";
|
---|
11 |
|
---|
12 | public CallBlock()
|
---|
13 | : base(type_name)
|
---|
14 | {
|
---|
15 | }
|
---|
16 |
|
---|
17 | public void init()
|
---|
18 | {
|
---|
19 | this.appendValueInput("RET")
|
---|
20 | .setCheck(null)
|
---|
21 | .appendField("呼び出し");
|
---|
22 | this.setInputsInline(false);
|
---|
23 | this.setPreviousStatement(true, null);
|
---|
24 | this.setNextStatement(true, null);
|
---|
25 | this.setColour(160);
|
---|
26 | this.setTooltip("");
|
---|
27 | this.setHelpUrl("http://www.example.com/");
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | public class PinModeBlock : Block
|
---|
32 | {
|
---|
33 | public const string type_name = "pin_mode";
|
---|
34 |
|
---|
35 | public PinModeBlock()
|
---|
36 | : base(type_name)
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void init()
|
---|
41 | {
|
---|
42 | this.appendDummyInput()
|
---|
43 | .appendField("PINのモード設定")
|
---|
44 | .appendField(App.TargetBoard.Pins(), "PIN_NO");
|
---|
45 | this.appendDummyInput()
|
---|
46 | .appendField("モード")
|
---|
47 | .appendField(new FieldDropdown(new[] {
|
---|
48 | new[] { "INPUTモード", "INPUT" },
|
---|
49 | new[] { "OUTPUTモード", "OUTPUT" }
|
---|
50 | }), "PIN_MODE");
|
---|
51 | this.setInputsInline(true);
|
---|
52 | this.setPreviousStatement(true, null);
|
---|
53 | this.setNextStatement(true, null);
|
---|
54 | this.setColour(160);
|
---|
55 | this.setTooltip("");
|
---|
56 | this.setHelpUrl("http://www.example.com/");
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | public class DigitalWriteBlock : Block
|
---|
61 | {
|
---|
62 | public const string type_name = "digital_write";
|
---|
63 |
|
---|
64 | public DigitalWriteBlock()
|
---|
65 | : base(type_name)
|
---|
66 | {
|
---|
67 | }
|
---|
68 |
|
---|
69 | public void init()
|
---|
70 | {
|
---|
71 | this.appendDummyInput()
|
---|
72 | .appendField("デジタルライト")
|
---|
73 | .appendField(App.TargetBoard.Pins(), "PIN_NO");
|
---|
74 | this.appendDummyInput()
|
---|
75 | .appendField("値")
|
---|
76 | .appendField(new FieldDropdown(new[] {
|
---|
77 | new[] { "LOW", "LOW" },
|
---|
78 | new[] { "HIGH", "HIGH" }
|
---|
79 | }), "PIN_VALUE");
|
---|
80 | this.setInputsInline(true);
|
---|
81 | this.setPreviousStatement(true, null);
|
---|
82 | this.setNextStatement(true, null);
|
---|
83 | this.setColour(160);
|
---|
84 | this.setTooltip("");
|
---|
85 | this.setHelpUrl("http://www.example.com/");
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | public class DigitalReadBlock : Block
|
---|
90 | {
|
---|
91 | public const string type_name = "digital_read";
|
---|
92 |
|
---|
93 | public DigitalReadBlock()
|
---|
94 | : base(type_name)
|
---|
95 | {
|
---|
96 | }
|
---|
97 |
|
---|
98 | public void init()
|
---|
99 | {
|
---|
100 | this.appendDummyInput()
|
---|
101 | .appendField("デジタルリード")
|
---|
102 | .appendField(App.TargetBoard.Pins(), "PIN_NO");
|
---|
103 | this.setInputsInline(true);
|
---|
104 | this.setOutput(true, "Boolean");
|
---|
105 | this.setColour(160);
|
---|
106 | this.setTooltip("");
|
---|
107 | this.setHelpUrl("http://www.example.com/");
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | public class AnalogReadBlock : Block
|
---|
112 | {
|
---|
113 | public const string type_name = "analog_read";
|
---|
114 |
|
---|
115 | public AnalogReadBlock()
|
---|
116 | : base(type_name)
|
---|
117 | {
|
---|
118 | }
|
---|
119 |
|
---|
120 | public void init()
|
---|
121 | {
|
---|
122 | this.appendDummyInput()
|
---|
123 | .appendField("アナログリード")
|
---|
124 | .appendField(App.TargetBoard.AnalogPins(), "PIN_NO");
|
---|
125 | this.setInputsInline(true);
|
---|
126 | this.setOutput(true, "Number");
|
---|
127 | this.setColour(160);
|
---|
128 | this.setTooltip("");
|
---|
129 | this.setHelpUrl("http://www.example.com/");
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | public class PwmBlock : Block
|
---|
134 | {
|
---|
135 | public const string type_name = "pwm";
|
---|
136 |
|
---|
137 | public PwmBlock()
|
---|
138 | : base(type_name)
|
---|
139 | {
|
---|
140 | }
|
---|
141 |
|
---|
142 | public void init()
|
---|
143 | {
|
---|
144 | this.appendDummyInput()
|
---|
145 | .appendField("PWM出力")
|
---|
146 | .appendField(App.TargetBoard.PwmPins(), "PIN_NO");
|
---|
147 | this.appendValueInput("PWM_OUT")
|
---|
148 | .setCheck("Number")
|
---|
149 | .appendField("出力PWM比率");
|
---|
150 | this.setInputsInline(true);
|
---|
151 | this.setPreviousStatement(true, null);
|
---|
152 | this.setNextStatement(true, null);
|
---|
153 | this.setColour(160);
|
---|
154 | this.setTooltip("");
|
---|
155 | this.setHelpUrl("http://www.example.com/");
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | public class PwmValueBlock : Block
|
---|
160 | {
|
---|
161 | public const string type_name = "pwm_value";
|
---|
162 |
|
---|
163 | public PwmValueBlock()
|
---|
164 | : base(type_name)
|
---|
165 | {
|
---|
166 | }
|
---|
167 |
|
---|
168 | public void init()
|
---|
169 | {
|
---|
170 | this.appendDummyInput()
|
---|
171 | .appendField(new FieldNumber("0", 0, 255, 1), "PWM_VALUE");
|
---|
172 | this.setOutput(true, "Number");
|
---|
173 | this.setColour(160);
|
---|
174 | this.setTooltip("PWM 0~255");
|
---|
175 | this.setHelpUrl("http://www.example.com/");
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | public class AnalogReferenceBlock : Block
|
---|
180 | {
|
---|
181 | public const string type_name = "analog_reference";
|
---|
182 |
|
---|
183 | public AnalogReferenceBlock()
|
---|
184 | : base(type_name)
|
---|
185 | {
|
---|
186 | }
|
---|
187 |
|
---|
188 | public void init()
|
---|
189 | {
|
---|
190 | this.appendDummyInput()
|
---|
191 | .appendField("アナログ入力基準電圧")
|
---|
192 | .appendField(new FieldDropdown(new[] {
|
---|
193 | new[] { "5.0V Arduino互換", "DEFAULT" },
|
---|
194 | new[] { "1.1V 内蔵電圧", "INTERNAL" },
|
---|
195 | new[] { "AVREFピン供給電圧", "EXTERNAL" },
|
---|
196 | new[] { "3.3V 12ビットA/D変換を行う", "RAW12BIT" }
|
---|
197 | }), "ANALOG_REFERENCE_MODE");
|
---|
198 | this.setInputsInline(true);
|
---|
199 | this.setPreviousStatement(true, null);
|
---|
200 | this.setNextStatement(true, null);
|
---|
201 | this.setColour(160);
|
---|
202 | this.setTooltip("");
|
---|
203 | this.setHelpUrl("http://www.example.com/");
|
---|
204 | }
|
---|
205 | }
|
---|
206 |
|
---|
207 | public class InitDacBlock : Block
|
---|
208 | {
|
---|
209 | public const string type_name = "init_dac";
|
---|
210 |
|
---|
211 | public InitDacBlock()
|
---|
212 | : base(type_name)
|
---|
213 | {
|
---|
214 | }
|
---|
215 |
|
---|
216 | public void init()
|
---|
217 | {
|
---|
218 | this.appendDummyInput()
|
---|
219 | .appendField("アナログDACピン初期化");
|
---|
220 | this.setInputsInline(true);
|
---|
221 | this.setPreviousStatement(true, null);
|
---|
222 | this.setNextStatement(true, null);
|
---|
223 | this.setColour(160);
|
---|
224 | this.setTooltip("");
|
---|
225 | this.setHelpUrl("http://www.example.com/");
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | public class AnalogDacBlock : Block
|
---|
230 | {
|
---|
231 | public const string type_name = "analog_dac";
|
---|
232 |
|
---|
233 | public AnalogDacBlock()
|
---|
234 | : base(type_name)
|
---|
235 | {
|
---|
236 | }
|
---|
237 |
|
---|
238 | public void init()
|
---|
239 | {
|
---|
240 | this.appendDummyInput()
|
---|
241 | .appendField("アナログDAC出力");
|
---|
242 | this.appendValueInput("VALUE")
|
---|
243 | .setCheck("Number");
|
---|
244 | this.setInputsInline(true);
|
---|
245 | this.setPreviousStatement(true, null);
|
---|
246 | this.setNextStatement(true, null);
|
---|
247 | this.setColour(160);
|
---|
248 | this.setTooltip("");
|
---|
249 | this.setHelpUrl("http://www.example.com/");
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | public class DacValueBlock : Block
|
---|
254 | {
|
---|
255 | public const string type_name = "dac_value";
|
---|
256 |
|
---|
257 | public DacValueBlock()
|
---|
258 | : base(type_name)
|
---|
259 | {
|
---|
260 | }
|
---|
261 |
|
---|
262 | public void init()
|
---|
263 | {
|
---|
264 | this.appendDummyInput()
|
---|
265 | .appendField(new FieldNumber("0", 0, 4095, 1), "DAC_VALUE");
|
---|
266 | this.setOutput(true, "Number");
|
---|
267 | this.setColour(160);
|
---|
268 | this.setTooltip("DAC 0~4095");
|
---|
269 | this.setHelpUrl("http://www.example.com/");
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | public class DelayBlock : Block
|
---|
274 | {
|
---|
275 | public const string type_name = "delay";
|
---|
276 |
|
---|
277 | public DelayBlock()
|
---|
278 | : base(type_name)
|
---|
279 | {
|
---|
280 | }
|
---|
281 |
|
---|
282 | public void init()
|
---|
283 | {
|
---|
284 | this.appendDummyInput()
|
---|
285 | .appendField("ディレイ");
|
---|
286 | this.appendValueInput("VALUE")
|
---|
287 | .setCheck("Number");
|
---|
288 | this.setInputsInline(true);
|
---|
289 | this.setPreviousStatement(true, null);
|
---|
290 | this.setNextStatement(true, null);
|
---|
291 | this.setColour(160);
|
---|
292 | this.setTooltip("");
|
---|
293 | this.setHelpUrl("http://www.example.com/");
|
---|
294 | }
|
---|
295 | }
|
---|
296 |
|
---|
297 | public class MillisBlock : Block
|
---|
298 | {
|
---|
299 | public const string type_name = "millis";
|
---|
300 |
|
---|
301 | public MillisBlock()
|
---|
302 | : base(type_name)
|
---|
303 | {
|
---|
304 | }
|
---|
305 |
|
---|
306 | public void init()
|
---|
307 | {
|
---|
308 | this.appendDummyInput()
|
---|
309 | .appendField("起動してからのミリ秒数");
|
---|
310 | this.setInputsInline(true);
|
---|
311 | this.setOutput(true, "Number");
|
---|
312 | this.setColour(160);
|
---|
313 | this.setTooltip("");
|
---|
314 | this.setHelpUrl("http://www.example.com/");
|
---|
315 | }
|
---|
316 | }
|
---|
317 |
|
---|
318 | public class MicrosBlock : Block
|
---|
319 | {
|
---|
320 | public const string type_name = "micros";
|
---|
321 |
|
---|
322 | public MicrosBlock()
|
---|
323 | : base(type_name)
|
---|
324 | {
|
---|
325 | }
|
---|
326 |
|
---|
327 | public void init()
|
---|
328 | {
|
---|
329 | this.appendDummyInput()
|
---|
330 | .appendField("起動してからのマイクロ秒数");
|
---|
331 | this.setInputsInline(true);
|
---|
332 | this.setOutput(true, "Number");
|
---|
333 | this.setColour(160);
|
---|
334 | this.setTooltip("");
|
---|
335 | this.setHelpUrl("http://www.example.com/");
|
---|
336 | }
|
---|
337 | }
|
---|
338 |
|
---|
339 | public class LedBlock : Block
|
---|
340 | {
|
---|
341 | public const string type_name = "led";
|
---|
342 |
|
---|
343 | public LedBlock()
|
---|
344 | : base(type_name)
|
---|
345 | {
|
---|
346 | }
|
---|
347 |
|
---|
348 | public void init()
|
---|
349 | {
|
---|
350 | this.appendDummyInput()
|
---|
351 | .appendField("LED");
|
---|
352 | this.appendValueInput("SW")
|
---|
353 | .setCheck("Number");
|
---|
354 | this.setInputsInline(true);
|
---|
355 | this.setPreviousStatement(true, null);
|
---|
356 | this.setNextStatement(true, null);
|
---|
357 | this.setColour(160);
|
---|
358 | this.setTooltip("");
|
---|
359 | this.setHelpUrl("http://www.example.com/");
|
---|
360 | }
|
---|
361 | }
|
---|
362 |
|
---|
363 | public class BitBlock : Block
|
---|
364 | {
|
---|
365 | public const string type_name = "bit";
|
---|
366 |
|
---|
367 | public BitBlock()
|
---|
368 | : base(type_name)
|
---|
369 | {
|
---|
370 | }
|
---|
371 | public void init()
|
---|
372 | {
|
---|
373 | this.appendDummyInput()
|
---|
374 | .appendField("Bit 7")
|
---|
375 | .appendField(new FieldCheckbox("FALSE"), "BIT7")
|
---|
376 | .appendField(new FieldCheckbox("FALSE"), "BIT6")
|
---|
377 | .appendField(new FieldCheckbox("FALSE"), "BIT5")
|
---|
378 | .appendField(new FieldCheckbox("FALSE"), "BIT4")
|
---|
379 | .appendField(new FieldCheckbox("FALSE"), "BIT3")
|
---|
380 | .appendField(new FieldCheckbox("FALSE"), "BIT2")
|
---|
381 | .appendField(new FieldCheckbox("FALSE"), "BIT1")
|
---|
382 | .appendField(new FieldCheckbox("FALSE"), "BIT0")
|
---|
383 | .appendField("0");
|
---|
384 | this.setOutput(true, "Number");
|
---|
385 | this.setColour(160);
|
---|
386 | this.setTooltip("");
|
---|
387 | this.setHelpUrl("http://www.example.com/");
|
---|
388 | }
|
---|
389 | }
|
---|
390 |
|
---|
391 | public class HexadecimalBlock : Block
|
---|
392 | {
|
---|
393 | public const string type_name = "hexadecimal";
|
---|
394 |
|
---|
395 | public HexadecimalBlock()
|
---|
396 | : base(type_name)
|
---|
397 | {
|
---|
398 | }
|
---|
399 |
|
---|
400 | public void init()
|
---|
401 | {
|
---|
402 | var input = new FieldTextInput("00000000");
|
---|
403 | input.setValidator(validator);
|
---|
404 |
|
---|
405 | this.appendDummyInput()
|
---|
406 | .appendField("HEX")
|
---|
407 | .appendField(input, "VALUE");
|
---|
408 | this.setOutput(true, "Number");
|
---|
409 | this.setColour(160);
|
---|
410 | this.setTooltip("");
|
---|
411 | this.setHelpUrl("http://www.example.com/");
|
---|
412 |
|
---|
413 | }
|
---|
414 |
|
---|
415 | public string validator(string text)
|
---|
416 | {
|
---|
417 | text = text.Replace(new Regex("[^0-9a-fA-F]+", "g"), "");
|
---|
418 | return text;
|
---|
419 | }
|
---|
420 | }
|
---|
421 |
|
---|
422 | public class ToneBlock : Block
|
---|
423 | {
|
---|
424 | public const string type_name = "tone";
|
---|
425 |
|
---|
426 | public ToneBlock()
|
---|
427 | : base(type_name)
|
---|
428 | {
|
---|
429 | }
|
---|
430 | public void init()
|
---|
431 | {
|
---|
432 | this.appendDummyInput()
|
---|
433 | .appendField("トーン出力")
|
---|
434 | .appendField(App.TargetBoard.PwmPins(), "PIN_NO");
|
---|
435 | this.appendValueInput("FREQUENCY")
|
---|
436 | .setCheck("Number")
|
---|
437 | .appendField("周波数");
|
---|
438 | this.appendValueInput("DURATION")
|
---|
439 | .setCheck("Number")
|
---|
440 | .appendField("出力を維持する時間[ms]");
|
---|
441 | this.setInputsInline(true);
|
---|
442 | this.setPreviousStatement(true, null);
|
---|
443 | this.setNextStatement(true, null);
|
---|
444 | this.setColour(160);
|
---|
445 | this.setTooltip("");
|
---|
446 | this.setHelpUrl("http://www.example.com/");
|
---|
447 | }
|
---|
448 | }
|
---|
449 |
|
---|
450 | public class ToneValueBlock : Block
|
---|
451 | {
|
---|
452 | public const string type_name = "tone_value";
|
---|
453 |
|
---|
454 | public ToneValueBlock()
|
---|
455 | : base(type_name)
|
---|
456 | {
|
---|
457 | }
|
---|
458 |
|
---|
459 | public void init()
|
---|
460 | {
|
---|
461 | this.appendDummyInput()
|
---|
462 | .appendField(new FieldNumber("1000", 2, 62500, 1), "TONE_VALUE");
|
---|
463 | this.setOutput(true, "Number");
|
---|
464 | this.setColour(160);
|
---|
465 | this.setTooltip("Tone 2~62500");
|
---|
466 | this.setHelpUrl("http://www.example.com/");
|
---|
467 | }
|
---|
468 | }
|
---|
469 |
|
---|
470 | public class NoToneBlock : Block
|
---|
471 | {
|
---|
472 | public const string type_name = "no_tone";
|
---|
473 |
|
---|
474 | public NoToneBlock()
|
---|
475 | : base(type_name)
|
---|
476 | {
|
---|
477 | }
|
---|
478 |
|
---|
479 | public void init()
|
---|
480 | {
|
---|
481 | this.appendDummyInput()
|
---|
482 | .appendField("トーン出力停止")
|
---|
483 | .appendField(App.TargetBoard.PwmPins(), "PIN_NO");
|
---|
484 | this.setInputsInline(true);
|
---|
485 | this.setPreviousStatement(true, null);
|
---|
486 | this.setNextStatement(true, null);
|
---|
487 | this.setColour(160);
|
---|
488 | this.setTooltip("");
|
---|
489 | this.setHelpUrl("http://www.example.com/");
|
---|
490 | }
|
---|
491 | }
|
---|
492 |
|
---|
493 | public class RandomSeedBlock : Block
|
---|
494 | {
|
---|
495 | public const string type_name = "random_seed";
|
---|
496 |
|
---|
497 | public RandomSeedBlock()
|
---|
498 | : base(type_name)
|
---|
499 | {
|
---|
500 | }
|
---|
501 |
|
---|
502 | public void init()
|
---|
503 | {
|
---|
504 | this.appendDummyInput()
|
---|
505 | .appendField("乱数を得るための種を与えます");
|
---|
506 | this.appendValueInput("VALUE")
|
---|
507 | .setCheck("Number");
|
---|
508 | this.setInputsInline(true);
|
---|
509 | this.setPreviousStatement(true, null);
|
---|
510 | this.setNextStatement(true, null);
|
---|
511 | this.setColour(160);
|
---|
512 | this.setTooltip("");
|
---|
513 | this.setHelpUrl("http://www.example.com/");
|
---|
514 | }
|
---|
515 | }
|
---|
516 |
|
---|
517 | public class RandomBlock : Block
|
---|
518 | {
|
---|
519 | public const string type_name = "random";
|
---|
520 |
|
---|
521 | public RandomBlock()
|
---|
522 | : base(type_name)
|
---|
523 | {
|
---|
524 | }
|
---|
525 |
|
---|
526 | public void init()
|
---|
527 | {
|
---|
528 | this.appendDummyInput()
|
---|
529 | .appendField("乱数を取得");
|
---|
530 | this.appendValueInput("MIN")
|
---|
531 | .setCheck("Number")
|
---|
532 | .appendField("最小値");
|
---|
533 | this.appendValueInput("MAX")
|
---|
534 | .setCheck("Number")
|
---|
535 | .appendField("最大値");
|
---|
536 | this.setInputsInline(true);
|
---|
537 | this.setOutput(true, "Number");
|
---|
538 | this.setColour(160);
|
---|
539 | this.setTooltip("");
|
---|
540 | this.setHelpUrl("http://www.example.com/");
|
---|
541 | }
|
---|
542 | }
|
---|
543 |
|
---|
544 | partial class Ruby
|
---|
545 | {
|
---|
546 | public node call(CallBlock block)
|
---|
547 | {
|
---|
548 | var value_ret = valueToCode(block, "RET");
|
---|
549 | return value_ret;
|
---|
550 | }
|
---|
551 |
|
---|
552 | public node pin_mode(PinModeBlock block)
|
---|
553 | {
|
---|
554 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
555 | var dropdown_pin_mode = block.getFieldValue("PIN_MODE");
|
---|
556 | var p = new node[] {
|
---|
557 | new int_node(this, App.TargetBoard.PinNameToNum(dropdown_pin_no)),
|
---|
558 | new int_node(this, App.TargetBoard.PinModeNameToNum(dropdown_pin_mode))
|
---|
559 | };
|
---|
560 | return new fcall_node(this, intern("pinMode"), p, null);
|
---|
561 | }
|
---|
562 |
|
---|
563 | public node digital_write(DigitalWriteBlock block)
|
---|
564 | {
|
---|
565 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
566 | var dropdown_pin_value = block.getFieldValue("PIN_VALUE");
|
---|
567 | var p = new node[] {
|
---|
568 | new int_node(this, App.TargetBoard.PinNameToNum(dropdown_pin_no)),
|
---|
569 | new int_node(this, App.TargetBoard.PinValueNameToNum(dropdown_pin_value ))
|
---|
570 | };
|
---|
571 | return new fcall_node(this, intern("digitalWrite"), p, null);
|
---|
572 | }
|
---|
573 |
|
---|
574 | public node digital_read(DigitalReadBlock block)
|
---|
575 | {
|
---|
576 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
577 | var p = new node[] {
|
---|
578 | new int_node(this, App.TargetBoard.PinNameToNum(dropdown_pin_no)),
|
---|
579 | };
|
---|
580 | return new fcall_node(this, intern("digitalRead"), p, null);
|
---|
581 | }
|
---|
582 |
|
---|
583 | public node analog_read(AnalogReadBlock block)
|
---|
584 | {
|
---|
585 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
586 | var p = new node[] {
|
---|
587 | new int_node(this, App.TargetBoard.PinNameToNum(dropdown_pin_no)),
|
---|
588 | };
|
---|
589 | return new fcall_node(this, intern("analogRead"), p, null);
|
---|
590 | }
|
---|
591 |
|
---|
592 | public node pwm(PwmBlock block)
|
---|
593 | {
|
---|
594 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
595 | var value_pwm_out = valueToCode(block, "PWM_OUT");
|
---|
596 | var p = new node[] {
|
---|
597 | new int_node(this, App.TargetBoard.PinNameToNum(dropdown_pin_no)),
|
---|
598 | value_pwm_out
|
---|
599 | };
|
---|
600 | return new fcall_node(this, intern("pwm"), p, null);
|
---|
601 | }
|
---|
602 |
|
---|
603 | public node pwm_value(PwmValueBlock block)
|
---|
604 | {
|
---|
605 | var number_pwm_value = block.getFieldValue("PWM_VALUE");
|
---|
606 | return new int_node(this, number_pwm_value == null ? 0 : Bridge.Script.ParseInt(number_pwm_value, 10));
|
---|
607 | }
|
---|
608 |
|
---|
609 | public node analog_reference(AnalogReferenceBlock block)
|
---|
610 | {
|
---|
611 | var dropdown_analog_reference_mode = block.getFieldValue("ANALOG_REFERENCE_MODE");
|
---|
612 | var p = new node[] {
|
---|
613 | new int_node(this, App.TargetBoard.AnalogRefModeNameToNum(dropdown_analog_reference_mode))
|
---|
614 | };
|
---|
615 | return new fcall_node(this, intern("analogReference"), p, null);
|
---|
616 | }
|
---|
617 |
|
---|
618 | public node init_dac(InitDacBlock block)
|
---|
619 | {
|
---|
620 | var p = new node[0];
|
---|
621 | return new fcall_node(this, intern("initDac"), p, null);
|
---|
622 | }
|
---|
623 |
|
---|
624 | public node analog_dac(AnalogDacBlock block)
|
---|
625 | {
|
---|
626 | var value_value = valueToCode(block, "VALUE");
|
---|
627 | var p = new node[] {
|
---|
628 | value_value
|
---|
629 | };
|
---|
630 | return new fcall_node(this, intern("analogDac"), p, null);
|
---|
631 | }
|
---|
632 |
|
---|
633 | public node dac_value(DacValueBlock block)
|
---|
634 | {
|
---|
635 | var number_dac_value = block.getFieldValue("ADC_VALUE");
|
---|
636 | return new int_node(this, number_dac_value == null ? 0 : Bridge.Script.ParseInt(number_dac_value, 10));
|
---|
637 | }
|
---|
638 |
|
---|
639 | public node delay(DelayBlock block)
|
---|
640 | {
|
---|
641 | var value_value = valueToCode(block, "VALUE");
|
---|
642 | var p = new node[] {
|
---|
643 | value_value
|
---|
644 | };
|
---|
645 | return new fcall_node(this, intern("delay"), p, null);
|
---|
646 | }
|
---|
647 |
|
---|
648 | public node millis(MillisBlock block)
|
---|
649 | {
|
---|
650 | var p = new node[0];
|
---|
651 | return new fcall_node(this, intern("millis"), p, null);
|
---|
652 | }
|
---|
653 |
|
---|
654 | public node micros(MicrosBlock block)
|
---|
655 | {
|
---|
656 | var p = new node[0];
|
---|
657 | return new fcall_node(this, intern("micros"), p, null);
|
---|
658 | }
|
---|
659 |
|
---|
660 | public node led(LedBlock block)
|
---|
661 | {
|
---|
662 | var value_sw = valueToCode(block, "SW");
|
---|
663 | var p = new node[] {
|
---|
664 | value_sw
|
---|
665 | };
|
---|
666 | return new fcall_node(this, intern("led"), p, null);
|
---|
667 | }
|
---|
668 |
|
---|
669 | public node bit(BitBlock block)
|
---|
670 | {
|
---|
671 | var value = 0;
|
---|
672 | value += (block.getFieldValue("BIT7") == "TRUE") ? 0x80 : 0;
|
---|
673 | value += (block.getFieldValue("BIT6") == "TRUE") ? 0x40 : 0;
|
---|
674 | value += (block.getFieldValue("BIT5") == "TRUE") ? 0x20 : 0;
|
---|
675 | value += (block.getFieldValue("BIT4") == "TRUE") ? 0x10 : 0;
|
---|
676 | value += (block.getFieldValue("BIT3") == "TRUE") ? 0x08 : 0;
|
---|
677 | value += (block.getFieldValue("BIT2") == "TRUE") ? 0x04 : 0;
|
---|
678 | value += (block.getFieldValue("BIT1") == "TRUE") ? 0x02 : 0;
|
---|
679 | value += (block.getFieldValue("BIT0") == "TRUE") ? 0x01 : 0;
|
---|
680 | return new int_node(this, value);
|
---|
681 | }
|
---|
682 |
|
---|
683 | public node hexadecimal(HexadecimalBlock block)
|
---|
684 | {
|
---|
685 | var value = block.getFieldValue("VALUE");
|
---|
686 | return new int_node(this, value == null ? 0 : Bridge.Script.ParseInt(value, 16));
|
---|
687 | }
|
---|
688 |
|
---|
689 | public node tone(ToneBlock block)
|
---|
690 | {
|
---|
691 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
692 | var value_frequency = valueToCode(block, "FREQUENCY");
|
---|
693 | var value_duration = valueToCode(block, "DURATION");
|
---|
694 | var p = new node[] {
|
---|
695 | new int_node(this, App.TargetBoard.PinNameToNum(dropdown_pin_no)),
|
---|
696 | value_frequency,
|
---|
697 | value_duration
|
---|
698 | };
|
---|
699 | return new fcall_node(this, intern("tone"), p, null);
|
---|
700 | }
|
---|
701 |
|
---|
702 | public node tone_value(ToneValueBlock block)
|
---|
703 | {
|
---|
704 | var number_tone_value = block.getFieldValue("TONE_VALUE");
|
---|
705 | return new int_node(this, number_tone_value == null ? 0 : Bridge.Script.ParseInt(number_tone_value, 10));
|
---|
706 | }
|
---|
707 |
|
---|
708 | public node no_tone(NoToneBlock block)
|
---|
709 | {
|
---|
710 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
711 | var p = new node[] {
|
---|
712 | new int_node(this, App.TargetBoard.PinNameToNum(dropdown_pin_no)),
|
---|
713 | };
|
---|
714 | return new fcall_node(this, intern("noTone"), p, null);
|
---|
715 | }
|
---|
716 |
|
---|
717 | public node random_seed(RandomSeedBlock block)
|
---|
718 | {
|
---|
719 | var value_name = valueToCode(block, "VALUE");
|
---|
720 | var p = new node[] {
|
---|
721 | value_name,
|
---|
722 | };
|
---|
723 | return new fcall_node(this, intern("randomSeed"), p, null);
|
---|
724 | }
|
---|
725 |
|
---|
726 | public node random(RandomBlock block)
|
---|
727 | {
|
---|
728 | var value_min = valueToCode(block, "MIN");
|
---|
729 | var value_max = valueToCode(block, "MAX");
|
---|
730 | var p = new node[0];
|
---|
731 | if (value_min == null)
|
---|
732 | p.Push(value_max);
|
---|
733 | else {
|
---|
734 | p.Push(value_min);
|
---|
735 | p.Push(value_max);
|
---|
736 | }
|
---|
737 | return new fcall_node(this, intern("random"), p, null);
|
---|
738 | }
|
---|
739 | }
|
---|
740 | }
|
---|