1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using Bridge;
|
---|
5 |
|
---|
6 | namespace WebMrbc
|
---|
7 | {
|
---|
8 | public class ServoAttachBlock : Block
|
---|
9 | {
|
---|
10 | public const string type_name = "servo_attach";
|
---|
11 |
|
---|
12 | public ServoAttachBlock()
|
---|
13 | : base(type_name)
|
---|
14 | {
|
---|
15 | }
|
---|
16 | public void init()
|
---|
17 | {
|
---|
18 | this.appendDummyInput()
|
---|
19 | .appendField("サーボ出力を任意のピンに割り当てます")
|
---|
20 | .appendField(new FieldNumber("0", 0, 11, 1), "CH");
|
---|
21 | this.appendDummyInput()
|
---|
22 | .appendField("割り当てるピン番号")
|
---|
23 | .appendField(GrPeach.PwmPins(), "PIN_NO")
|
---|
24 | .appendField("Min")
|
---|
25 | .appendField(new FieldTextInput("default"), "MIN")
|
---|
26 | .appendField("Max")
|
---|
27 | .appendField(new FieldTextInput("default"), "MAX");
|
---|
28 | this.setPreviousStatement(true, null);
|
---|
29 | this.setNextStatement(true, null);
|
---|
30 | this.setColour(160);
|
---|
31 | this.setTooltip("");
|
---|
32 | this.setHelpUrl("http://www.example.com/");
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public class ServoAngleBlock : Block
|
---|
37 | {
|
---|
38 | public const string type_name = "servo_angle";
|
---|
39 |
|
---|
40 | public ServoAngleBlock()
|
---|
41 | : base(type_name)
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | public void init()
|
---|
46 | {
|
---|
47 | this.appendDummyInput()
|
---|
48 | .appendField(new FieldAngle("180", validator), "VALUE");
|
---|
49 | this.setInputsInline(true);
|
---|
50 | this.setOutput(true, "Number");
|
---|
51 | this.setColour(160);
|
---|
52 | this.setTooltip("");
|
---|
53 | this.setHelpUrl("http://www.example.com/");
|
---|
54 | }
|
---|
55 |
|
---|
56 | public string validator(string text)
|
---|
57 | {
|
---|
58 | if (text == null) return null;
|
---|
59 | var a = Script.ParseFloat(text);
|
---|
60 | if (Script.IsNaN(a)) return null;
|
---|
61 | a %= 180;
|
---|
62 | if (a < 0) a += 180;
|
---|
63 | return a.ToString();
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | public class ServoWriteBlock : Block
|
---|
69 | {
|
---|
70 | public const string type_name = "servo_write";
|
---|
71 |
|
---|
72 | public ServoWriteBlock()
|
---|
73 | : base(type_name)
|
---|
74 | {
|
---|
75 | }
|
---|
76 | public void init()
|
---|
77 | {
|
---|
78 | this.appendDummyInput()
|
---|
79 | .appendField("サーボの角度をセットします")
|
---|
80 | .appendField(new FieldNumber("0", 0, 11, 1), "CH");
|
---|
81 | this.appendValueInput("ANGLE")
|
---|
82 | .setCheck("Number")
|
---|
83 | .appendField("角度");
|
---|
84 | this.setInputsInline(true);
|
---|
85 | this.setPreviousStatement(true, null);
|
---|
86 | this.setNextStatement(true, null);
|
---|
87 | this.setColour(160);
|
---|
88 | this.setTooltip("");
|
---|
89 | this.setHelpUrl("http://www.example.com/");
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | public class ServoUsValueBlock : Block
|
---|
94 | {
|
---|
95 | public const string type_name = "servo_us_value";
|
---|
96 |
|
---|
97 | public ServoUsValueBlock()
|
---|
98 | : base(type_name)
|
---|
99 | {
|
---|
100 | }
|
---|
101 |
|
---|
102 | public void init()
|
---|
103 | {
|
---|
104 | this.appendDummyInput()
|
---|
105 | .appendField(new FieldNumber("0", 0, 19999, 1), "VALUE");
|
---|
106 | this.setOutput(true, "Number");
|
---|
107 | this.setColour(160);
|
---|
108 | this.setTooltip("パルスの幅 1~19999, 0で出力 OFF");
|
---|
109 | this.setHelpUrl("http://www.example.com/");
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | public class ServoUsBlock : Block
|
---|
115 | {
|
---|
116 | public const string type_name = "servo_us";
|
---|
117 |
|
---|
118 | public ServoUsBlock()
|
---|
119 | : base(type_name)
|
---|
120 | {
|
---|
121 | }
|
---|
122 |
|
---|
123 | public void init()
|
---|
124 | {
|
---|
125 | this.appendDummyInput()
|
---|
126 | .appendField("サーボモータにus単位で角度を指定する")
|
---|
127 | .appendField(new FieldNumber("0", 0, 11, 1), "CH");
|
---|
128 | this.appendValueInput("US")
|
---|
129 | .setCheck("Number")
|
---|
130 | .appendField("出力したいパルスの幅");
|
---|
131 | this.setPreviousStatement(true, null);
|
---|
132 | this.setNextStatement(true, null);
|
---|
133 | this.setColour(160);
|
---|
134 | this.setTooltip("");
|
---|
135 | this.setHelpUrl("http://www.example.com/");
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | public class ServoReadBlock : Block
|
---|
140 | {
|
---|
141 | public const string type_name = "servo_read";
|
---|
142 |
|
---|
143 | public ServoReadBlock()
|
---|
144 | : base(type_name)
|
---|
145 | {
|
---|
146 | }
|
---|
147 |
|
---|
148 | public void init()
|
---|
149 | {
|
---|
150 | this.appendDummyInput()
|
---|
151 | .appendField("最後に設定された角度を読み出す")
|
---|
152 | .appendField(new FieldNumber("0", 0, 11, 1), "CH");
|
---|
153 | this.setOutput(true, "Number");
|
---|
154 | this.setColour(160);
|
---|
155 | this.setTooltip("");
|
---|
156 | this.setHelpUrl("http://www.example.com/");
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | public class ServoAttachedBlock : Block
|
---|
161 | {
|
---|
162 | public const string type_name = "servo_attached";
|
---|
163 |
|
---|
164 | public ServoAttachedBlock()
|
---|
165 | : base(type_name)
|
---|
166 | {
|
---|
167 | }
|
---|
168 |
|
---|
169 | public void init()
|
---|
170 | {
|
---|
171 | this.appendDummyInput()
|
---|
172 | .appendField("ピンにサーボが割り当てられているかを確認する")
|
---|
173 | .appendField(new FieldNumber("0", 0, 11, 1), "CH");
|
---|
174 | this.setOutput(true, "Boolean");
|
---|
175 | this.setColour(160);
|
---|
176 | this.setTooltip("");
|
---|
177 | this.setHelpUrl("http://www.example.com/");
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | public class ServoDetachBlock : Block
|
---|
182 | {
|
---|
183 | public const string type_name = "servo_detach";
|
---|
184 |
|
---|
185 | public ServoDetachBlock()
|
---|
186 | : base(type_name)
|
---|
187 | {
|
---|
188 | }
|
---|
189 |
|
---|
190 | public void init()
|
---|
191 | {
|
---|
192 | this.appendDummyInput()
|
---|
193 | .appendField("サーボの動作を止め、割り込みを禁止する")
|
---|
194 | .appendField(new FieldNumber("0", 0, 11, 1), "CH");
|
---|
195 | this.setPreviousStatement(true, null);
|
---|
196 | this.setNextStatement(true, null);
|
---|
197 | this.setColour(160);
|
---|
198 | this.setTooltip("");
|
---|
199 | this.setHelpUrl("http://www.example.com/");
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | partial class Ruby
|
---|
204 | {
|
---|
205 | public node servo_angle(ServoAngleBlock block)
|
---|
206 | {
|
---|
207 | var value = block.getFieldValue("VALUE");
|
---|
208 | return new int_node(this, value == null ? 0 : Script.ParseInt(value, 10));
|
---|
209 | }
|
---|
210 |
|
---|
211 | public node servo_us_value(ServoUsValueBlock block)
|
---|
212 | {
|
---|
213 | var value = block.getFieldValue("VALUE");
|
---|
214 | return new int_node(this, value == null ? 0 : Script.ParseInt(value, 10));
|
---|
215 | }
|
---|
216 |
|
---|
217 | public node servo_attach(ServoAttachBlock block)
|
---|
218 | {
|
---|
219 | var number_ch = block.getFieldValue("CH");
|
---|
220 | var dropdown_pin_no = block.getFieldValue("PIN_NO");
|
---|
221 | var text_min = block.getFieldValue("MIN");
|
---|
222 | var text_max = block.getFieldValue("MAX");
|
---|
223 | var c = new const_node(this, intern("Servo"));
|
---|
224 | var p = new node[] {
|
---|
225 | new int_node(this, number_ch == null ? 0 : Script.ParseInt(number_ch, 10)),
|
---|
226 | new int_node(this, GrPeach.PinNameToNum(dropdown_pin_no)),
|
---|
227 | new int_node(this, text_min == null ? 0 : Script.ParseInt(text_min, 10)),
|
---|
228 | new int_node(this, text_max == null ? 0 : Script.ParseInt(text_max, 10)),
|
---|
229 | };
|
---|
230 | return new call_node(this, c, intern("attach"), p, null);
|
---|
231 | }
|
---|
232 |
|
---|
233 | public node servo_write(ServoWriteBlock block)
|
---|
234 | {
|
---|
235 | var number_ch = block.getFieldValue("CH");
|
---|
236 | var value_angle = valueToCode(block, "ANGLE");
|
---|
237 | var c = new const_node(this, intern("Servo"));
|
---|
238 | var p = new node[] {
|
---|
239 | new int_node(this, number_ch == null ? 0 : Script.ParseInt(number_ch, 10)),
|
---|
240 | value_angle,
|
---|
241 | };
|
---|
242 | return new call_node(this, c, intern("write"), p, null);
|
---|
243 | }
|
---|
244 |
|
---|
245 | public node servo_us(ServoUsBlock block)
|
---|
246 | {
|
---|
247 | var number_ch = block.getFieldValue("CH");
|
---|
248 | var value_us = valueToCode(block, "US");
|
---|
249 | var c = new const_node(this, intern("Servo"));
|
---|
250 | var p = new node[] {
|
---|
251 | new int_node(this, number_ch == null ? 0 : Script.ParseInt(number_ch, 10)),
|
---|
252 | value_us,
|
---|
253 | };
|
---|
254 | return new call_node(this, c, intern("us"), p, null);
|
---|
255 | }
|
---|
256 |
|
---|
257 | public node servo_read(ServoReadBlock block)
|
---|
258 | {
|
---|
259 | var number_ch = block.getFieldValue("CH");
|
---|
260 | var c = new const_node(this, intern("Servo"));
|
---|
261 | var p = new node[] {
|
---|
262 | new int_node(this, number_ch == null ? 0 : Script.ParseInt(number_ch, 10)),
|
---|
263 | };
|
---|
264 | return new call_node(this, c, intern("read"), p, null);
|
---|
265 | }
|
---|
266 |
|
---|
267 | public node servo_attached(ServoAttachedBlock block)
|
---|
268 | {
|
---|
269 | var number_ch = block.getFieldValue("CH");
|
---|
270 | var c = new const_node(this, intern("Servo"));
|
---|
271 | var p = new node[] {
|
---|
272 | new int_node(this, number_ch == null ? 0 : Script.ParseInt(number_ch, 10)),
|
---|
273 | };
|
---|
274 | return new call_node(this, c, intern("attached"), p, null);
|
---|
275 | }
|
---|
276 |
|
---|
277 | public node servo_detach(ServoDetachBlock block)
|
---|
278 | {
|
---|
279 | var number_ch = block.getFieldValue("CH");
|
---|
280 | var c = new const_node(this, intern("Servo"));
|
---|
281 | var p = new node[] {
|
---|
282 | new int_node(this, number_ch == null ? 0 : Script.ParseInt(number_ch, 10)),
|
---|
283 | };
|
---|
284 | return new call_node(this, c, intern("detach"), p, null);
|
---|
285 | }
|
---|
286 | }
|
---|
287 | }
|
---|