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