-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathio.js
More file actions
326 lines (310 loc) · 10.5 KB
/
Copy pathio.js
File metadata and controls
326 lines (310 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* @fileoverview Blocks for Arduino Digital and Analogue input and output
* functions. The Arduino function syntax can be found at
* http://arduino.cc/en/Reference/HomePage
*
* TODO: maybe change this to a "PIN" BlocklyType
*/
'use strict';
goog.provide('Blockly.Blocks.io');
goog.require('Blockly.Blocks');
goog.require('Blockly.Types');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.io.HUE = 250;
function dynamicDigPins() {
var options = [];
var pins = Blockly.Arduino.Boards.selected.digitalPins;
// now we add variables of type DIGPIN
// how to obtain the workspace here ?? Hack it for now...
var workspace = Blockly.getMainWorkspace();
var typedvar = Blockly.StaticTypingArduino.typedVariables(workspace, Blockly.Types.DIGPIN);
for (var ind in typedvar) {
options.push([typedvar[ind], typedvar[ind]]);
}
return options.concat(pins);
}
Blockly.Blocks['io_digitalwrite'] = {
/**
* Block for creating a 'set pin' to a state.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('STATE')
.appendField(Blockly.Msg.ARD_DIGITALWRITE)
.appendField(new Blockly.FieldDropdown(dynamicDigPins), 'PIN')
.appendField(Blockly.Msg.ARD_WRITE_TO)
.setCheck(Blockly.Types.BOOLEAN.checkList);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.ARD_DIGITALWRITE_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'PIN', 'digitalPins');
}
};
Blockly.Blocks['io_digitalread'] = {
/**
* Block for creating a 'read pin'.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalRead');
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_DIGITALREAD)
.appendField(new Blockly.FieldDropdown(dynamicDigPins), 'PIN');
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.setTooltip(Blockly.Msg.ARD_DIGITALREAD_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
getBlockType: function() {
return Blockly.Types.BOOLEAN;
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'PIN', 'digitalPins');
}
};
Blockly.Blocks['io_builtin_led'] = {
/**
* Block for setting built-in LED to a state.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('STATE')
.appendField(Blockly.Msg.ARD_BUILTIN_LED)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.builtinLed), 'BUILT_IN_LED')
.appendField('to')
.setCheck(Blockly.Types.BOOLEAN.checkList);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.ARD_BUILTIN_LED_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'BUILT_IN_LED', 'builtinLed');
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function() {
return Blockly.Types.BOOLEAN;
},
};
Blockly.Blocks['io_analogwrite'] = {
/**
* Block for creating a 'set pin' to an analogue value.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogWrite');
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('NUM')
.appendField(Blockly.Msg.ARD_ANALOGWRITE)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.pwmPins), 'PIN')
.appendField(Blockly.Msg.ARD_WRITE_TO)
.setCheck(Blockly.Types.NUMBER.output);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.ARD_ANALOGWRITE_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, 'PIN', 'pwmPins');
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function() {
return Blockly.Types.NUMBER;
},
};
Blockly.Blocks['io_analogread'] = {
/**
* Block for reading an analogue input.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogRead');
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_ANALOGREAD)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.analogPins), 'PIN');
this.setOutput(true, Blockly.Types.NUMBER.output);
this.setTooltip(Blockly.Msg.ARD_ANALOGREAD_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
getBlockType: function() {
return Blockly.Types.NUMBER;
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, 'PIN', 'analogPins');
}
};
Blockly.Blocks['io_highlow'] = {
/**
* Block for creating a pin state.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Constants');
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField(
new Blockly.FieldDropdown([[Blockly.Msg.ARD_HIGH, 'HIGH'], [Blockly.Msg.ARD_LOW, 'LOW']]),
'STATE');
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.setTooltip(Blockly.Msg.ARD_HIGHLOW_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
getBlockType: function() {
return Blockly.Types.BOOLEAN;
}
};
Blockly.Blocks['io_pulsein'] = {
init: function() {
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PULSEREAD);
this.appendValueInput("PULSETYPE")
.setCheck(Blockly.Types.BOOLEAN.check);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PULSEON)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.digitalPins), "PULSEPIN");
this.setOutput(true);
this.setInputsInline(true);
this.setColour(Blockly.Blocks.io.HUE);
this.setTooltip(Blockly.Msg.ARD_PULSE_TIP);
this.setHelpUrl('https://www.arduino.cc/en/Reference/PulseIn');
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function() {
return Blockly.Types.NUMBER;
}
};
Blockly.Blocks['io_pulsetimeout'] = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PULSEREAD);
this.appendValueInput("PULSETYPE")
.setCheck(Blockly.Types.BOOLEAN.check);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PULSEON)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.digitalPins), "PULSEPIN");
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PULSETIMEOUT);
this.appendValueInput('TIMEOUT')
.setCheck(Blockly.Types.NUMBER.output);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PULSETIMEOUT_MS);
this.setOutput(true);
this.setInputsInline(true);
this.setColour(Blockly.Blocks.io.HUE);
this.setTooltip(Blockly.Msg.ARD_PULSETIMEOUT_TIP);
this.setHelpUrl('https://www.arduino.cc/en/Reference/PulseIn');
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function() {
return Blockly.Types.NUMBER;
}
};
Blockly.Blocks['io_pin_dig'] = {
init: function() {
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PIN_DIG)
.appendField(new Blockly.FieldDropdown(Blockly.Arduino.Boards.selected.digitalPins), "PIN");
this.setOutput(true);
this.setColour(Blockly.Blocks.io.HUE);
this.setTooltip(Blockly.Msg.ARD_PIN_DIG_TIP);
this.setHelpUrl('https://www.arduino.cc/en/Reference/Board');
},
/** @return {!string} The type of return value for the block, a digital pin. */
getBlockType: function() {
return Blockly.Types.DIGPIN;
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'PIN', 'digitalPins');
}
};
Blockly.Blocks['io_pin_an'] = {
init: function() {
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PIN_AN)
.appendField(new Blockly.FieldDropdown(Blockly.Arduino.Boards.selected.analogPins), "PIN");
this.setOutput(true);
this.setColour(Blockly.Blocks.io.HUE);
this.setTooltip(Blockly.Msg.ARD_PIN_AN_TIP);
this.setHelpUrl('https://www.arduino.cc/en/Reference/Board');
},
/** @return {!string} The type of return value for the block, an analog pin */
getBlockType: function() {
return Blockly.Types.ANAPIN;
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'PIN', 'analogPins');
}
};
Blockly.Blocks['io_pin_pwm'] = {
init: function() {
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_PIN_PWM)
.appendField(new Blockly.FieldDropdown(Blockly.Arduino.Boards.selected.pwmPins), "PIN");
this.setOutput(true);
this.setColour(Blockly.Blocks.io.HUE);
this.setTooltip(Blockly.Msg.ARD_PIN_PWM_TIP);
this.setHelpUrl('https://www.arduino.cc/en/Reference/Board');
},
/** @return {!string} The type of return value for the block, a PWM pin. */
getBlockType: function() {
return Blockly.Types.PWMPIN;
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'PIN', 'pwmPins');
}
};