1414window . onload = function ( ) {
1515 Blockly . inject ( document . body , { path : '' , toolbox : document . getElementById ( 'toolbox' ) } ) ;
1616 Blockly . Xml . domToWorkspace ( Blockly . mainWorkspace , document . getElementById ( 'blocklyInitial' ) ) ;
17- window . parent . blocklyLoaded ( Blockly ) ; // see core/editorBlockly.js
17+ window . parent . blocklyLoaded ( Blockly , window ) ; // see core/editorBlockly.js
1818} ;
1919// ---------------------------------
2020
@@ -32,16 +32,16 @@ for (var p in PORTS)
3232 PINS . push ( [ pinname , pinname ] ) ;
3333 }
3434
35- Blockly . Language . espruino_timeout = {
35+ Blockly . Blocks . espruino_timeout = {
3636 category : 'Espruino' ,
3737 init : function ( ) {
3838 this . appendValueInput ( 'SECONDS' )
3939 . setCheck ( 'Number' )
40- . appendTitle ( 'wait' ) ;
40+ . appendField ( 'wait' ) ;
4141 this . appendDummyInput ( )
42- . appendTitle ( "seconds" ) ;
42+ . appendField ( "seconds" ) ;
4343 this . appendStatementInput ( 'DO' )
44- . appendTitle ( 'do' ) ;
44+ . appendField ( 'do' ) ;
4545
4646 this . setPreviousStatement ( true ) ;
4747 this . setNextStatement ( true ) ;
@@ -50,16 +50,16 @@ Blockly.Language.espruino_timeout = {
5050 this . setTooltip ( 'Waits for a certain period before running code' ) ;
5151 }
5252} ;
53- Blockly . Language . espruino_interval = {
53+ Blockly . Blocks . espruino_interval = {
5454 category : 'Espruino' ,
5555 init : function ( ) {
5656 this . appendValueInput ( 'SECONDS' )
5757 . setCheck ( 'Number' )
58- . appendTitle ( 'every' ) ;
58+ . appendField ( 'every' ) ;
5959 this . appendDummyInput ( )
60- . appendTitle ( "seconds" ) ;
60+ . appendField ( "seconds" ) ;
6161 this . appendStatementInput ( 'DO' )
62- . appendTitle ( 'do' ) ;
62+ . appendField ( 'do' ) ;
6363
6464 this . setPreviousStatement ( true ) ;
6565 this . setNextStatement ( true ) ;
@@ -68,29 +68,56 @@ Blockly.Language.espruino_interval = {
6868 this . setTooltip ( 'Runs code repeatedly, every so many seconds' ) ;
6969 }
7070} ;
71- Blockly . Language . espruino_pin = {
71+
72+ Blockly . Blocks . espruino_pin = {
7273// category: 'Espruino',
7374 init : function ( ) {
75+
76+ var start = 0 ;
77+ var incrementStep = 10 ;
78+ var originalPin = undefined ;
79+ var listGen = function ( ) {
80+ originalPin = this . value_ ;
81+ var list = PINS . slice ( start , start + incrementStep ) ;
82+ if ( start > 0 ) list . unshift ( [ 'Back...' , 'Back' ] ) ;
83+ if ( start + incrementStep < PINS . length ) list . push ( [ 'More...' , 'More' ] ) ;
84+ return list ;
85+ } ;
86+
87+ var pinSelector = new Blockly . FieldDropdown ( listGen , function ( selection ) {
88+ var ret = undefined ;
89+
90+ if ( selection == "More" || selection == "Back" ) {
91+ if ( selection == "More" )
92+ start += incrementStep ;
93+ else
94+ start -= incrementStep ;
95+
96+ var t = this ;
97+ setTimeout ( function ( ) { t . showEditor_ ( ) ; } , 1 ) ;
98+
99+ return originalPin ;
100+ }
101+ } ) ;
102+
74103 this . setColour ( ESPRUINO_COL ) ;
75104 this . setOutput ( true , 'Pin' ) ;
76- this . appendDummyInput ( )
77- . appendTitle ( new Blockly . FieldDropdown ( this . PINS ) , 'PIN' ) ;
105+ this . appendDummyInput ( ) . appendField ( pinSelector , 'PIN' ) ;
78106 this . setTooltip ( 'The Name of a Pin' ) ;
79107 } ,
80- PINS : PINS ,
81108} ;
82-
83109
84- Blockly . Language . espruino_watch = {
110+
111+ Blockly . Blocks . espruino_watch = {
85112 category : 'Espruino' ,
86113 init : function ( ) {
87114 this . appendValueInput ( 'PIN' )
88115 . setCheck ( 'Pin' )
89- . appendTitle ( 'watch' ) ;
116+ . appendField ( 'watch' ) ;
90117 this . appendDummyInput ( )
91- . appendTitle ( new Blockly . FieldDropdown ( this . EDGES ) , 'EDGE' ) . appendTitle ( 'edge' ) ; ;
118+ . appendField ( new Blockly . FieldDropdown ( this . EDGES ) , 'EDGE' ) . appendField ( 'edge' ) ; ;
92119 this . appendStatementInput ( 'DO' )
93- . appendTitle ( 'do' ) ;
120+ . appendField ( 'do' ) ;
94121
95122 this . setPreviousStatement ( true ) ;
96123 this . setNextStatement ( true ) ;
@@ -105,10 +132,10 @@ EDGES: [
105132} ;
106133
107134
108- Blockly . Language . espruino_getTime = {
135+ Blockly . Blocks . espruino_getTime = {
109136 category : 'Espruino' ,
110137 init : function ( ) {
111- this . appendDummyInput ( ) . appendTitle ( 'Time' ) ;
138+ this . appendDummyInput ( ) . appendField ( 'Time' ) ;
112139 this . setOutput ( true , 'Number' ) ;
113140 this . setColour ( 230 /*Number*/ ) ;
114141 this . setInputsInline ( true ) ;
@@ -117,15 +144,15 @@ Blockly.Language.espruino_getTime = {
117144 } ;
118145
119146
120- Blockly . Language . espruino_digitalWrite = {
147+ Blockly . Blocks . espruino_digitalWrite = {
121148 category : 'Espruino' ,
122149 init : function ( ) {
123150 this . appendValueInput ( 'PIN' )
124151 . setCheck ( 'Pin' )
125- . appendTitle ( 'digitalWrite Pin' ) ;
152+ . appendField ( 'digitalWrite Pin' ) ;
126153 this . appendValueInput ( 'VAL' )
127154 . setCheck ( [ 'Number' , 'Boolean' ] )
128- . appendTitle ( 'Value' ) ;
155+ . appendField ( 'Value' ) ;
129156
130157 this . setPreviousStatement ( true ) ;
131158 this . setNextStatement ( true ) ;
@@ -134,17 +161,17 @@ Blockly.Language.espruino_digitalWrite = {
134161 this . setTooltip ( 'Writes a Digital Value to a Pin' ) ;
135162 }
136163} ;
137- Blockly . Language . espruino_digitalPulse = {
164+ Blockly . Blocks . espruino_digitalPulse = {
138165 category : 'Espruino' ,
139166 init : function ( ) {
140167 this . appendValueInput ( 'PIN' )
141168 . setCheck ( 'Pin' )
142- . appendTitle ( 'digitalPulse Pin' ) ;
169+ . appendField ( 'digitalPulse Pin' ) ;
143170 this . appendValueInput ( 'VAL' )
144171 . setCheck ( [ 'Boolean' ] ) ;
145172 this . appendValueInput ( 'TIME' )
146173 . setCheck ( [ 'Number' ] )
147- . appendTitle ( 'Milliseconds' ) ;
174+ . appendField ( 'Milliseconds' ) ;
148175
149176 this . setPreviousStatement ( true ) ;
150177 this . setNextStatement ( true ) ;
@@ -153,12 +180,12 @@ Blockly.Language.espruino_digitalPulse = {
153180 this . setTooltip ( 'Pulses a pin for the given number of milliseconds' ) ;
154181 }
155182 } ;
156- Blockly . Language . espruino_digitalRead = {
183+ Blockly . Blocks . espruino_digitalRead = {
157184 category : 'Espruino' ,
158185 init : function ( ) {
159186 this . appendValueInput ( 'PIN' )
160187 . setCheck ( 'Pin' )
161- . appendTitle ( 'digitalRead Pin' ) ;
188+ . appendField ( 'digitalRead Pin' ) ;
162189
163190 this . setOutput ( true , 'Boolean' ) ;
164191 this . setColour ( ESPRUINO_COL ) ;
@@ -167,15 +194,15 @@ Blockly.Language.espruino_digitalRead = {
167194 }
168195} ;
169196
170- Blockly . Language . espruino_analogWrite = {
197+ Blockly . Blocks . espruino_analogWrite = {
171198 category : 'Espruino' ,
172199 init : function ( ) {
173200 this . appendValueInput ( 'PIN' )
174201 . setCheck ( 'Pin' )
175- . appendTitle ( 'analogWrite Pin' ) ;
202+ . appendField ( 'analogWrite Pin' ) ;
176203 this . appendValueInput ( 'VAL' )
177204 . setCheck ( [ 'Number' , 'Boolean' ] )
178- . appendTitle ( 'Value' ) ;
205+ . appendField ( 'Value' ) ;
179206
180207 this . setPreviousStatement ( true ) ;
181208 this . setNextStatement ( true ) ;
@@ -184,12 +211,12 @@ Blockly.Language.espruino_analogWrite = {
184211 this . setTooltip ( 'Writes an Analog Value to a Pin' ) ;
185212 }
186213 } ;
187- Blockly . Language . espruino_analogRead = {
214+ Blockly . Blocks . espruino_analogRead = {
188215 category : 'Espruino' ,
189216 init : function ( ) {
190217 this . appendValueInput ( 'PIN' )
191218 . setCheck ( 'Pin' )
192- . appendTitle ( 'analogRead Pin' ) ;
219+ . appendField ( 'analogRead Pin' ) ;
193220
194221 this . setOutput ( true , 'Number' ) ;
195222 this . setColour ( ESPRUINO_COL ) ;
0 commit comments