source: EcnlProtoTool/trunk/webapp/webmrbc/Arduino/KernelBlock.cs@ 287

Last change on this file since 287 was 287, checked in by coas-nagasima, 7 years ago

ファイルヘッダーコメントを追加

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