[270] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 |
|
---|
| 5 | namespace WebMrbc
|
---|
| 6 | {
|
---|
| 7 | public class I2cNewBlock : Block
|
---|
| 8 | {
|
---|
| 9 | public const string type_name = "i2c_new";
|
---|
| 10 |
|
---|
| 11 | public I2cNewBlock()
|
---|
| 12 | : base(type_name)
|
---|
| 13 | {
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | public void init()
|
---|
| 17 | {
|
---|
| 18 | this.appendDummyInput()
|
---|
| 19 | .appendField("I2Cの初期化")
|
---|
| 20 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 21 | this.setInputsInline(true);
|
---|
| 22 | this.setPreviousStatement(true, null);
|
---|
| 23 | this.setNextStatement(true, null);
|
---|
| 24 | this.setColour(160);
|
---|
| 25 | this.setTooltip("");
|
---|
| 26 | this.setHelpUrl("http://www.example.com/");
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public class I2cWriteBlock : Block
|
---|
| 31 | {
|
---|
| 32 | public const string type_name = "i2c_write";
|
---|
| 33 |
|
---|
| 34 | public I2cWriteBlock()
|
---|
| 35 | : base(type_name)
|
---|
| 36 | {
|
---|
| 37 | }
|
---|
| 38 | public void init()
|
---|
| 39 | {
|
---|
| 40 | this.appendDummyInput()
|
---|
| 41 | .appendField("I2Cへの書き込み")
|
---|
| 42 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 43 | this.appendValueInput("DEVICEID")
|
---|
| 44 | .setCheck("Number")
|
---|
| 45 | .appendField("デバイスID");
|
---|
| 46 | this.appendValueInput("ADDRESS")
|
---|
| 47 | .setCheck("Number")
|
---|
| 48 | .appendField("アドレス");
|
---|
| 49 | this.appendValueInput("DATA")
|
---|
| 50 | .setCheck("Number")
|
---|
| 51 | .appendField("データ");
|
---|
| 52 | this.setInputsInline(true);
|
---|
| 53 | this.setPreviousStatement(true, null);
|
---|
| 54 | this.setNextStatement(true, null);
|
---|
| 55 | this.setColour(160);
|
---|
| 56 | this.setTooltip("");
|
---|
| 57 | this.setHelpUrl("http://www.example.com/");
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public class I2cReadBlock : Block
|
---|
| 62 | {
|
---|
| 63 | public const string type_name = "i2c_read";
|
---|
| 64 |
|
---|
| 65 | public I2cReadBlock()
|
---|
| 66 | : base(type_name)
|
---|
| 67 | {
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public void init()
|
---|
| 71 | {
|
---|
| 72 | this.appendDummyInput()
|
---|
| 73 | .appendField("I2Cからの読み込み")
|
---|
| 74 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 75 | this.appendValueInput("DEVICEID")
|
---|
| 76 | .setCheck("Number")
|
---|
| 77 | .appendField("デバイスID");
|
---|
| 78 | this.appendValueInput("ADDRESS_L")
|
---|
| 79 | .setCheck("Number")
|
---|
| 80 | .appendField("下位アドレス");
|
---|
| 81 | this.appendValueInput("ADDRESS_H")
|
---|
| 82 | .setCheck("Number")
|
---|
| 83 | .appendField("上位アドレス");
|
---|
| 84 | this.setInputsInline(true);
|
---|
| 85 | this.setOutput(true, "Number");
|
---|
| 86 | this.setColour(160);
|
---|
| 87 | this.setTooltip("");
|
---|
| 88 | this.setHelpUrl("http://www.example.com/");
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public class I2cBeginBlock : Block
|
---|
| 93 | {
|
---|
| 94 | public const string type_name = "i2c_begin";
|
---|
| 95 |
|
---|
| 96 | public I2cBeginBlock()
|
---|
| 97 | : base(type_name)
|
---|
| 98 | {
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | public void init()
|
---|
| 102 | {
|
---|
| 103 | this.appendDummyInput()
|
---|
| 104 | .appendField("I2Cの送信開始準備")
|
---|
| 105 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 106 | this.appendValueInput("DEVICEID")
|
---|
| 107 | .setCheck("Number")
|
---|
| 108 | .appendField("デバイスID");
|
---|
| 109 | this.setInputsInline(true);
|
---|
| 110 | this.setPreviousStatement(true, null);
|
---|
| 111 | this.setNextStatement(true, null);
|
---|
| 112 | this.setColour(160);
|
---|
| 113 | this.setTooltip("");
|
---|
| 114 | this.setHelpUrl("http://www.example.com/");
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | public class I2cLwriteBlock : Block
|
---|
| 119 | {
|
---|
| 120 | public const string type_name = "i2c_lwrite";
|
---|
| 121 |
|
---|
| 122 | public I2cLwriteBlock()
|
---|
| 123 | : base(type_name)
|
---|
| 124 | {
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | public void init()
|
---|
| 128 | {
|
---|
| 129 | this.appendDummyInput()
|
---|
| 130 | .appendField("I2Cの送信バッファの末尾に数値を追加する")
|
---|
| 131 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 132 | this.appendValueInput("DATA")
|
---|
| 133 | .setCheck("Number")
|
---|
| 134 | .appendField("データ");
|
---|
| 135 | this.setInputsInline(true);
|
---|
| 136 | this.setOutput(true, "Number");
|
---|
| 137 | this.setColour(160);
|
---|
| 138 | this.setTooltip("");
|
---|
| 139 | this.setHelpUrl("http://www.example.com/");
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | public class I2cEndBlock : Block
|
---|
| 144 | {
|
---|
| 145 | public const string type_name = "i2c_end";
|
---|
| 146 |
|
---|
| 147 | public I2cEndBlock()
|
---|
| 148 | : base(type_name)
|
---|
| 149 | {
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | public void init()
|
---|
| 153 | {
|
---|
| 154 | this.appendDummyInput()
|
---|
| 155 | .appendField("I2Cの送信シーケンスを発行する")
|
---|
| 156 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 157 | this.appendDummyInput()
|
---|
| 158 | .appendField("ストップコンディション発生")
|
---|
| 159 | .appendField(new FieldCheckbox("TRUE"), "STOP");
|
---|
| 160 | this.setInputsInline(true);
|
---|
| 161 | this.setOutput(true, "Number");
|
---|
| 162 | this.setColour(160);
|
---|
| 163 | this.setTooltip("");
|
---|
| 164 | this.setHelpUrl("http://www.example.com/");
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | public class I2cRequestBlock : Block
|
---|
| 169 | {
|
---|
| 170 | public const string type_name = "i2c_request";
|
---|
| 171 |
|
---|
| 172 | public I2cRequestBlock()
|
---|
| 173 | : base(type_name)
|
---|
| 174 | {
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | public void init()
|
---|
| 178 | {
|
---|
| 179 | this.appendDummyInput()
|
---|
| 180 | .appendField("I2Cへ受信シーケンスを発行する")
|
---|
| 181 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 182 | this.appendValueInput("ADDRESS")
|
---|
| 183 | .setCheck("Number")
|
---|
| 184 | .appendField("開始アドレス");
|
---|
| 185 | this.appendValueInput("COUNT")
|
---|
| 186 | .setCheck("Number")
|
---|
| 187 | .appendField("データ数");
|
---|
| 188 | this.setInputsInline(true);
|
---|
| 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 I2cLreadBlock : Block
|
---|
| 197 | {
|
---|
| 198 | public const string type_name = "i2c_lread";
|
---|
| 199 |
|
---|
| 200 | public I2cLreadBlock()
|
---|
| 201 | : base(type_name)
|
---|
| 202 | {
|
---|
| 203 | }
|
---|
| 204 | public void init()
|
---|
| 205 | {
|
---|
| 206 | this.appendDummyInput()
|
---|
| 207 | .appendField("I2Cへ受信シーケンスを発行しデータを読み出す")
|
---|
| 208 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 209 | this.setInputsInline(true);
|
---|
| 210 | this.setOutput(true, "Number");
|
---|
| 211 | this.setColour(160);
|
---|
| 212 | this.setTooltip("");
|
---|
| 213 | this.setHelpUrl("http://www.example.com/");
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | public class I2cAvailableBlock : Block
|
---|
| 218 | {
|
---|
| 219 | public const string type_name = "i2c_available";
|
---|
| 220 |
|
---|
| 221 | public I2cAvailableBlock()
|
---|
| 222 | : base(type_name)
|
---|
| 223 | {
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | public void init()
|
---|
| 227 | {
|
---|
| 228 | this.appendDummyInput()
|
---|
| 229 | .appendField("I2Cの受信バッファ内にあるデータ数を調べる")
|
---|
| 230 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 231 | this.setInputsInline(true);
|
---|
| 232 | this.setOutput(true, "Number");
|
---|
| 233 | this.setColour(160);
|
---|
| 234 | this.setTooltip("");
|
---|
| 235 | this.setHelpUrl("http://www.example.com/");
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | public class I2cFrequencyBlock : Block
|
---|
| 240 | {
|
---|
| 241 | public const string type_name = "i2c_frequency";
|
---|
| 242 |
|
---|
| 243 | public I2cFrequencyBlock()
|
---|
| 244 | : base(type_name)
|
---|
| 245 | {
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | public void init()
|
---|
| 249 | {
|
---|
| 250 | this.appendDummyInput()
|
---|
| 251 | .appendField("I2Cの周波数を変更する")
|
---|
| 252 | .appendField(GrPeach.I2CPorts(), "I2C_PORT_NO");
|
---|
| 253 | this.appendValueInput("FREQUENCY")
|
---|
| 254 | .setCheck("Number")
|
---|
| 255 | .appendField("周波数");
|
---|
| 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 | partial class Ruby
|
---|
| 266 | {
|
---|
| 267 | public node i2c_new(I2cNewBlock block)
|
---|
| 268 | {
|
---|
| 269 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 270 | // $i2c0 = I2c.new(0)
|
---|
| 271 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 272 | var c = new const_node(this, intern("I2c"));
|
---|
| 273 | var p = new node[] {
|
---|
| 274 | new int_node(this, GrPeach.I2CPortNameToNum(dropdown_i2c_port_no))
|
---|
| 275 | };
|
---|
| 276 | return new asgn_node(this, a, new call_node(this, c, intern("new"), p, null));
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | public node i2c_write(I2cWriteBlock block)
|
---|
| 280 | {
|
---|
| 281 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 282 | var value_deviceid = valueToCode(block, "DEVICEID");
|
---|
| 283 | var value_address = valueToCode(block, "ADDRESS");
|
---|
| 284 | var value_data = valueToCode(block, "DATA");
|
---|
| 285 | // $i2c0.write(0, 0x00, 0x00)
|
---|
| 286 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 287 | var p = new node[] {
|
---|
| 288 | value_deviceid,
|
---|
| 289 | value_address,
|
---|
| 290 | value_data
|
---|
| 291 | };
|
---|
| 292 | return new call_node(this, a, intern("write"), p, null);
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | public node i2c_read(I2cReadBlock block)
|
---|
| 296 | {
|
---|
| 297 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 298 | var value_deviceid = valueToCode(block, "DEVICEID");
|
---|
| 299 | var value_address_l = valueToCode(block, "ADDRESS_L");
|
---|
| 300 | var value_address_h = valueToCode(block, "ADDRESS_H");
|
---|
| 301 | // $i2c0.read(0, 0x00, 0x00)
|
---|
| 302 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 303 | var p = new node[] {
|
---|
| 304 | value_deviceid,
|
---|
| 305 | value_address_l
|
---|
| 306 | };
|
---|
| 307 | if (value_address_h != null) {
|
---|
| 308 | p.Push(value_address_h);
|
---|
| 309 | }
|
---|
| 310 | return new call_node(this, a, intern("write"), p, null);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | public node i2c_begin(I2cBeginBlock block)
|
---|
| 314 | {
|
---|
| 315 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 316 | var value_deviceid = valueToCode(block, "DEVICEID");
|
---|
| 317 | // $i2c0.begin(0)
|
---|
| 318 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 319 | var p = new node[] {
|
---|
| 320 | value_deviceid,
|
---|
| 321 | };
|
---|
| 322 | return new call_node(this, a, intern("begin"), p, null);
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | public node i2c_lwrite(I2cLwriteBlock block)
|
---|
| 326 | {
|
---|
| 327 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 328 | var value_data = valueToCode(block, "DATA");
|
---|
| 329 | // $i2c0.lwrite(0x00)
|
---|
| 330 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 331 | var p = new node[0];
|
---|
| 332 | if (value_data != null)
|
---|
| 333 | p.Push(value_data);
|
---|
| 334 | return new call_node(this, a, intern("lwrite"), p, null);
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | public node i2c_end(I2cEndBlock block)
|
---|
| 338 | {
|
---|
| 339 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 340 | var checkbox_stop = block.getFieldValue("STOP");
|
---|
| 341 | // $i2c0.lwrite(0x00)
|
---|
| 342 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 343 | var p = new node[0];
|
---|
| 344 | if (checkbox_stop != null)
|
---|
| 345 | p.Push(checkbox_stop == "TRUE" ? (node)new true_node(this) : (node)new false_node(this));
|
---|
| 346 | return new call_node(this, a, intern("end"), p, null);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | public node i2c_request(I2cRequestBlock block)
|
---|
| 350 | {
|
---|
| 351 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 352 | var value_address = valueToCode(block, "ADDRESS");
|
---|
| 353 | var value_count = valueToCode(block, "COUNT");
|
---|
| 354 | // $i2c0.request(0x00, 1)
|
---|
| 355 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 356 | var p = new node[] {
|
---|
| 357 | value_address,
|
---|
| 358 | value_count
|
---|
| 359 | };
|
---|
| 360 | return new call_node(this, a, intern("request"), p, null);
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | public node i2c_lread(I2cLreadBlock block)
|
---|
| 364 | {
|
---|
| 365 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 366 | // $i2c0.lread()
|
---|
| 367 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 368 | var p = new node[0];
|
---|
| 369 | return new call_node(this, a, intern("lread"), p, null);
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | public node i2c_available(I2cAvailableBlock block)
|
---|
| 373 | {
|
---|
| 374 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 375 | // $i2c0.available()
|
---|
| 376 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 377 | var p = new node[0];
|
---|
| 378 | return new call_node(this, a, intern("available"), p, null);
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | public node i2c_frequency(I2cFrequencyBlock block)
|
---|
| 382 | {
|
---|
| 383 | var dropdown_i2c_port_no = block.getFieldValue("I2C_PORT_NO");
|
---|
| 384 | var value_frequency = valueToCode(block, "FREQUENCY");
|
---|
| 385 | // $i2c0.frequency(0)
|
---|
| 386 | var a = new gvar_node(this, intern(GrPeach.I2CPortNameToVariable(dropdown_i2c_port_no)));
|
---|
| 387 | var p = new node[] {
|
---|
| 388 | value_frequency
|
---|
| 389 | };
|
---|
| 390 | return new call_node(this, a, intern("frequency"), p, null);
|
---|
| 391 | }
|
---|
| 392 | }
|
---|
| 393 | }
|
---|