From 48b57e8c99c6c6b01fcc1983b13d02ed8c58c6e8 Mon Sep 17 00:00:00 2001 From: roboticafacil Date: Fri, 8 Dec 2017 15:16:24 +0100 Subject: [PATCH 1/2] new file: ESPUI_blocks.js deleted: blocks.js new file: img/blocks/acknowledgements.html new file: img/blocks/button_pressed.svg new file: img/blocks/button_released.svg new file: img/blocks/controller_center_pressed.svg new file: img/blocks/controller_center_released.svg new file: img/blocks/controller_down_pressed.svg new file: img/blocks/controller_down_released.svg new file: img/blocks/controller_left_pressed.svg new file: img/blocks/controller_left_released.svg new file: img/blocks/controller_right_pressed.svg new file: img/blocks/controller_right_released.svg new file: img/blocks/controller_up_pressed.svg new file: img/blocks/controller_up_released.svg new file: img/blocks/switch_off.svg new file: img/blocks/switch_on.svg new file: lang/ESPUI.json --- ESPUI_blocks.js | 278 ++++++++++++++++++ blocks.js | 339 ---------------------- img/blocks/acknowledgements.html | 2 + img/blocks/button_pressed.svg | 54 ++++ img/blocks/button_released.svg | 53 ++++ img/blocks/controller_center_pressed.svg | 97 +++++++ img/blocks/controller_center_released.svg | 97 +++++++ img/blocks/controller_down_pressed.svg | 97 +++++++ img/blocks/controller_down_released.svg | 97 +++++++ img/blocks/controller_left_pressed.svg | 97 +++++++ img/blocks/controller_left_released.svg | 97 +++++++ img/blocks/controller_right_pressed.svg | 97 +++++++ img/blocks/controller_right_released.svg | 97 +++++++ img/blocks/controller_up_pressed.svg | 97 +++++++ img/blocks/controller_up_released.svg | 97 +++++++ img/blocks/switch_off.svg | 64 ++++ img/blocks/switch_on.svg | 61 ++++ lang/ESPUI.json | 27 ++ 18 files changed, 1509 insertions(+), 339 deletions(-) create mode 100644 ESPUI_blocks.js delete mode 100644 blocks.js create mode 100644 img/blocks/acknowledgements.html create mode 100644 img/blocks/button_pressed.svg create mode 100644 img/blocks/button_released.svg create mode 100644 img/blocks/controller_center_pressed.svg create mode 100644 img/blocks/controller_center_released.svg create mode 100644 img/blocks/controller_down_pressed.svg create mode 100644 img/blocks/controller_down_released.svg create mode 100644 img/blocks/controller_left_pressed.svg create mode 100644 img/blocks/controller_left_released.svg create mode 100644 img/blocks/controller_right_pressed.svg create mode 100644 img/blocks/controller_right_released.svg create mode 100644 img/blocks/controller_up_pressed.svg create mode 100644 img/blocks/controller_up_released.svg create mode 100644 img/blocks/switch_off.svg create mode 100644 img/blocks/switch_on.svg create mode 100644 lang/ESPUI.json diff --git a/ESPUI_blocks.js b/ESPUI_blocks.js new file mode 100644 index 0000000..d45fb97 --- /dev/null +++ b/ESPUI_blocks.js @@ -0,0 +1,278 @@ +// This is a block definition for projects like roboblocks +// +// Main Block +Facilino.LANG_COLOUR_ESPUI = '#B1B1B1'; + +Blockly.Blocks['espui'] = { + category: Facilino.locales.getKey('LANG_CATEGORY_HTML'), + subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_ESPUI'), + helpUrl: Facilino.getHelpUrl('espui'), + tags: ['webinterface'], + examples: ['lol.bly'], + category_colour: Facilino.LANG_COLOUR_HTML, + colour: Facilino.LANG_COLOUR_ESPUI, + init: function() { + var wifiOptions = [['No', false],['Yes', true]]; + this.appendDummyInput().appendField('UI Title:').appendField(new Blockly.FieldTextInput(Facilino.locales.getKey('LANG_ESPUI_ESPUI_TITLE')), 'ui_name'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_ESPUI_HOTSPOT')).appendField(new Blockly.FieldDropdown(wifiOptions), 'wifi_option'); + this.appendStatementInput('ui_elements').setCheck('ui_element'); + this.setColour(Facilino.LANG_COLOUR_ESPUI); + this.setTooltip(Facilino.locales.getKey('LANG_ESPUI_ESPUI_TOOLTIP')); + } +}; + +Blockly.Arduino['espui'] = function(block) { + var ui_name = block.getFieldValue('ui_name'); + var wifi_option = block.getFieldValue('wifi_option'); + var ui_elements = Blockly.Arduino.statementToCode(block, 'ui_elements'); + Blockly.Arduino.definitions_['define_wifi_h'] = '#include '; + Blockly.Arduino.definitions_['define_espui_h'] = '#include '; + Blockly.Arduino.setups_['setup_espui'] = '\n'; + if(wifi_option){ + Blockly.Arduino.setups_['setup_espui'] += + ' Serial.begin(115200);\n\n' + + ' WiFi.mode(WIFI_AP);\n' + + ' WiFi.softAP("' + ui_name + '");\n' + + ' Serial.print("IP address: ");\n' + + ' Serial.println(WiFi.softAPIP());\n\n'; + } + Blockly.Arduino.setups_['setup_espui'] += ui_elements; + Blockly.Arduino.setups_['setup_espui'] += ' ESPUI.begin("' + ui_name + '");\n'; + return null; +}; + +//Elements + +Blockly.Blocks['espui_button'] = { + category: Facilino.locales.getKey('LANG_CATEGORY_HTML'), + subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_ESPUI'), + helpUrl: Facilino.getHelpUrl('espui_button'), + tags: ['webinterface'], + examples: ['lol.bly'], + category_colour: Facilino.LANG_COLOUR_HTML, + colour: Facilino.LANG_COLOUR_ESPUI, + init: function() { + var colour = new Blockly.FieldColour('#000000'); + colour.setColours(['#000000','#40e0d0','#50c878','#3498dc','#687894','#e4d422','#eb8921','#e32636']).setColumns(2); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_BUTTON_BUTTON')).appendField(new Blockly.FieldTextInput(Facilino.locales.getKey('LANG_ESPUI_NAME')), 'ui_name'); + //this.appendDummyInput().appendField('UI Color').appendField(new Blockly.FieldDropdown(colorOptions), 'ui_color'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_COLOR')).appendField(colour, 'ui_color'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_TEXT')).appendField(new Blockly.FieldTextInput(Facilino.locales.getKey('LANG_ESPUI_TEXT')), 'button_text'); + this.setColour(Facilino.LANG_COLOUR_ESPUI); + this.setPreviousStatement(true, 'ui_element'); + this.setNextStatement(true, 'ui_element'); + this.setTooltip(Facilino.locales.getKey('LANG_ESPUI_BUTTON_TOOLTIP')); + this.appendStatementInput('on_down').appendField(new Blockly.FieldImage('img/blocks/button_pressed.svg', 24*options.zoom, 24*options.zoom)).setCheck(null); + this.appendStatementInput('on_up').appendField(new Blockly.FieldImage('img/blocks/button_released.svg', 24*options.zoom, 24*options.zoom)).setCheck(null); + } +}; + +Blockly.Arduino['espui_button'] = function(block) { + var ui_name = block.getFieldValue('ui_name'); + var color = block.getFieldValue('ui_color'); + var colorOptions = {"#000000": "COLOR_NONE", "#40e0d0": "COLOR_TURQUOISE", "#50c878": "COLOR_EMERALD", "#3498dc": "COLOR_PETERRIVER", "#687894": "COLOR_WETASPHALT", "#e4d422": "COLOR_SUNFLOWER", "#eb8921": "COLOR_CARROT", "#e32636": "COLOR_ALIZARIN"}; + var ui_color = colorOptions[color]; + var button_text = block.getFieldValue('button_text'); + var ui_name_clean = ui_name.replace(' ', '_'); + var on_down = Blockly.Arduino.statementToCode(block, 'on_down'); + var on_up = Blockly.Arduino.statementToCode(block, 'on_up'); + Blockly.Arduino.definitions_['define_ui_button_' + ui_name_clean] = + 'void button_' + ui_name_clean + '(Control c, int type) {\n' + + ' switch(type){\n' + + ' case B_DOWN:\n' + + on_down + '\n break;\n' + + ' case B_UP:\n' + + on_up + '\n break;\n' + + ' }\n' + + '}\n'; + var code = ' ESPUI.button("' + ui_name + '", &button_' + ui_name_clean + ', ' + ui_color + ', "' + button_text + '");\n'; + return code; +}; + +Blockly.Blocks['espui_label'] = { + category: Facilino.locales.getKey('LANG_CATEGORY_HTML'), + subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_ESPUI'), + helpUrl: Facilino.getHelpUrl('espui_label'), + tags: ['webinterface'], + examples: ['lol.bly'], + category_colour: Facilino.LANG_COLOUR_HTML, + colour: Facilino.LANG_COLOUR_ESPUI, + init: function() { + var colour = new Blockly.FieldColour('#000000'); + colour.setColours(['#000000','#40e0d0','#50c878','#3498dc','#687894','#e4d422','#eb8921','#e32636']).setColumns(2); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_LABEL_LABEL')).appendField(new Blockly.FieldTextInput(Facilino.locales.getKey('LANG_ESPUI_NAME')), 'ui_name'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_COLOR')).appendField(colour, 'ui_color'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_TEXT')).appendField(new Blockly.FieldTextInput('value'), 'start_value'); + this.setColour(Facilino.LANG_COLOUR_ESPUI); + this.setPreviousStatement(true, 'ui_element'); + this.setNextStatement(true, 'ui_element'); + this.setTooltip(Facilino.locales.getKey('LANG_ESPUI_LABEL_TOOLTIP')); + } +}; + +Blockly.Arduino['espui_label'] = function(block) { + var ui_name = block.getFieldValue('ui_name'); + var ui_color = block.getFieldValue('ui_color'); + var ui_name_clean = ui_name.replace(' ', '_'); + var start_value = block.getFieldValue('start_value'); + var code = ' ESPUI.label("' + ui_name + '", ' + ui_color + ', "' + start_value + '");\n'; + return code; +}; + +Blockly.Blocks['espui_switcher'] = { + category: Facilino.locales.getKey('LANG_CATEGORY_HTML'), + subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_ESPUI'), + helpUrl: Facilino.getHelpUrl('espui_switcher'), + tags: ['webinterface'], + examples: ['lol.bly'], + category_colour: Facilino.LANG_COLOUR_HTML, + colour: Facilino.LANG_COLOUR_ESPUI, + init: function() { + var colour = new Blockly.FieldColour('#000000'); + colour.setColours(['#000000','#40e0d0','#50c878','#3498dc','#687894','#e4d422','#eb8921','#e32636']).setColumns(2); + var stateOptions = [['Off', 'false'],['On', 'true']]; + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_SWITCH_SWITCH')).appendField(new Blockly.FieldTextInput(Facilino.locales.getKey('LANG_ESPUI_NAME')), 'ui_name'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_COLOR')).appendField(colour, 'ui_color'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_STATE')).appendField(new Blockly.FieldDropdown(stateOptions), 'switcher_state'); + this.setColour(Facilino.LANG_COLOUR_ESPUI); + this.setPreviousStatement(true, 'ui_element'); + this.setNextStatement(true, 'ui_element'); + this.setTooltip('A web interface button'); + this.appendStatementInput('on_on').appendField(new Blockly.FieldImage('img/blocks/switch_on.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_off').appendField(new Blockly.FieldImage('img/blocks/switch_off.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + } +}; + +Blockly.Arduino['espui_switcher'] = function(block) { + var ui_name = block.getFieldValue('ui_name'); + var color = block.getFieldValue('ui_color'); + var colorOptions = {"#000000": "COLOR_NONE", "#40e0d0": "COLOR_TURQUOISE", "#50c878": "COLOR_EMERALD", "#3498dc": "COLOR_PETERRIVER", "#687894": "COLOR_WETASPHALT", "#e4d422": "COLOR_SUNFLOWER", "#eb8921": "COLOR_CARROT", "#e32636": "COLOR_ALIZARIN"}; + var ui_color = colorOptions[color]; + var switcher_state = block.getFieldValue('switcher_state'); + var ui_name_clean = ui_name.replace(' ', '_'); + var on_on = Blockly.Arduino.statementToCode(block, 'on_down'); + var on_off = Blockly.Arduino.statementToCode(block, 'on_up'); + Blockly.Arduino.definitions_['define_ui_switcher_' + ui_name_clean] = + 'void switcher_' + ui_name_clean + '(Control c, int type) {\n' + + ' switch(type){\n' + + ' case S_ACTIVE:\n' + + on_on + '\n break;\n' + + ' case S_INACTIVE:\n' + + on_off + '\n break;\n' + + ' }\n' + + '}\n'; + var code = ' ESPUI.switcher("' + ui_name + '", ' + switcher_state + ', &switcher_' + ui_name_clean + ', ' + ui_color + ');\n'; + return code; +}; + +Blockly.Blocks['espui_pad'] = { + category: Facilino.locales.getKey('LANG_CATEGORY_HTML'), + subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_ESPUI'), + helpUrl: Facilino.getHelpUrl('espui_pad'), + tags: ['webinterface'], + examples: ['lol.bly'], + category_colour: Facilino.LANG_COLOUR_HTML, + colour: Facilino.LANG_COLOUR_ESPUI, + init: function() { + var colour = new Blockly.FieldColour('#000000'); + colour.setColours(['#000000','#40e0d0','#50c878','#3498dc','#687894','#e4d422','#eb8921','#e32636']).setColumns(2); + var centerOptions = [['Yes', 'false'],['No', 'true']]; + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_PAD_PAD')).appendField(new Blockly.FieldTextInput(Facilino.locales.getKey('LANG_ESPUI_NAME')), 'ui_name'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_COLOR')).appendField(colour, 'ui_color'); + this.appendDummyInput().appendField(Facilino.locales.getKey('LANG_ESPUI_PAD_CENTER')).appendField(new Blockly.FieldDropdown(centerOptions), 'pad_center'); + this.setColour(Facilino.LANG_COLOUR_ESPUI); + this.setPreviousStatement(true, 'ui_element'); + this.setNextStatement(true, 'ui_element'); + this.setTooltip('A web interface button'); + this.appendStatementInput('on_down_for').appendField(new Blockly.FieldImage('img/blocks/controller_up_pressed.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_up_for').appendField(new Blockly.FieldImage('img/blocks/controller_up_released.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_down_back').appendField(new Blockly.FieldImage('img/blocks/controller_down_pressed.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_up_back').appendField(new Blockly.FieldImage('img/blocks/controller_down_released.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_down_left').appendField(new Blockly.FieldImage('img/blocks/controller_right_pressed.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_up_left').appendField(new Blockly.FieldImage('img/blocks/controller_right_released.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_down_right').appendField(new Blockly.FieldImage('img/blocks/controller_left_pressed.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_up_right').appendField(new Blockly.FieldImage('img/blocks/controller_left_released.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_down_center').appendField(new Blockly.FieldImage('img/blocks/controller_center_pressed.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_up_center').appendField(new Blockly.FieldImage('img/blocks/controller_center_released.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.lastOption=this.getFieldValue('pad_center'); + }, + onchange() { + if (this.lastOption!==this.getFieldValue('pad_center')) + { + if (this.getFieldValue('pad_center')==='false') + { + try{ + + this.removeInput('on_down_center'); + this.removeInput('on_up_center'); + this.appendStatementInput('on_down_center').appendField(new Blockly.FieldImage('img/blocks/controller_center_pressed.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + this.appendStatementInput('on_up_center').appendField(new Blockly.FieldImage('img/blocks/controller_center_released.svg', 24*options.zoom, 24*options.zoom)).setCheck('code'); + } + catch(e) + { + } + } + else + { + try{ + this.removeInput('on_down_center'); + this.removeInput('on_up_center'); + } + catch(e) + { + } + } + this.lastOption=this.getFieldValue('pad_center'); + } + } +}; + +Blockly.Arduino['espui_pad'] = function(block) { + var ui_name = block.getFieldValue('ui_name'); + var color = block.getFieldValue('ui_color'); + var colorOptions = {"#000000": "COLOR_NONE", "#40e0d0": "COLOR_TURQUOISE", "#50c878": "COLOR_EMERALD", "#3498dc": "COLOR_PETERRIVER", "#687894": "COLOR_WETASPHALT", "#e4d422": "COLOR_SUNFLOWER", "#eb8921": "COLOR_CARROT", "#e32636": "COLOR_ALIZARIN"}; + var ui_color = colorOptions[color]; + var pad_center = block.getFieldValue('pad_center'); + var ui_name_clean = ui_name.replace(' ', '_'); + var on_down_for = Blockly.Arduino.statementToCode(block, 'on_down_for'); + var on_up_for = Blockly.Arduino.statementToCode(block, 'on_up_for'); + var on_down_back = Blockly.Arduino.statementToCode(block, 'on_down_back'); + var on_up_back = Blockly.Arduino.statementToCode(block, 'on_up_back'); + var on_down_left = Blockly.Arduino.statementToCode(block, 'on_down_left'); + var on_up_left = Blockly.Arduino.statementToCode(block, 'on_up_left'); + var on_down_right = Blockly.Arduino.statementToCode(block, 'on_down_right'); + var on_up_right = Blockly.Arduino.statementToCode(block, 'on_up_right'); + var on_down_center = Blockly.Arduino.statementToCode(block, 'on_down_center'); + var on_up_center = Blockly.Arduino.statementToCode(block, 'on_up_center'); + Blockly.Arduino.definitions_['define_ui_pad_' + ui_name_clean] = + 'void pad_' + ui_name_clean + '(Control c, int type) {\n' + + ' switch(type){\n' + + ' case P_FOR_DOWN:\n' + + on_down_for + '\n break;\n' + + ' case P_FOR_UP:\n' + + on_up_for + '\n break;\n' + + + ' case P_BACK_DOWN:\n' + + on_down_back + '\n break;\n' + + ' case P_BACK_UP:\n' + + on_up_back + '\n break;\n' + + + ' case P_RIGHT_DOWN:\n' + + on_down_left + '\n break;\n' + + ' case P_RIGHT_UP:\n' + + on_up_left + '\n break;\n' + + + ' case P_LEFT_DOWN:\n' + + on_down_right + '\n break;\n' + + ' case P_LEFT_UP:\n' + + on_up_right + '\n break;\n' + + + ' case P_CENTER_DOWN:\n' + + on_down_center + '\n break;\n' + + ' case P_CENTER_UP:\n' + + on_up_center + '\n break;\n' + + ' }\n' + + '}\n'; + var code = ' ESPUI.pad("' + ui_name + '", ' + pad_center + ', &pad_' + ui_name_clean + ', ' + ui_color + ');\n'; + return code; +}; \ No newline at end of file diff --git a/blocks.js b/blocks.js deleted file mode 100644 index 33591ef..0000000 --- a/blocks.js +++ /dev/null @@ -1,339 +0,0 @@ -// This is a block definition for projects like roboblocks -// -// Main Block -Blockly.Blocks['espui'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('espui'), - tags: ['webinterface'], - examples: ['lol.bly'], - init: function() { - var wifiOptions = [ - ['No', false], - ['Yes', true] - ]; - this.appendDummyInput() - .appendField('ESPUI Title:') - .appendField(new Blockly.FieldTextInput('string'), 'ui_name'); - this.appendDummyInput() - .appendField('Enable Wifi Hotspot Code:') - .appendField(new Blockly.FieldDropdown(wifiOptions), 'wifi_option'); - this.appendStatementInput('ui_elements') - .setCheck('ui_element'); - this.setColour("#37d1f9"); - this.setTooltip("Creates a webinterface on the ESP32"); - } -}; - -Blockly.Arduino['espui'] = function(block) { - var ui_name = block.getFieldValue('ui_name'); - var wifi_option = block.getFieldValue('wifi_option'); - var ui_elements = Blockly.Arduino.statementToCode(block, 'ui_elements'); - Blockly.Arduino.definitions_['define_wifi_h'] = '#include '; - Blockly.Arduino.definitions_['define_espui_h'] = '#include '; - Blockly.Arduino.setups_['setup_espui'] = '\n'; - if(wifi_option){ - Blockly.Arduino.setups_['setup_espui'] += - ' Serial.begin(115200);\n\n' + - ' WiFi.mode(WIFI_AP);\n' + - ' WiFi.softAP("' + ui_name + '");\n' + - ' Serial.print("IP address: ");\n' + - ' Serial.println(WiFi.softAPIP());\n\n'; - } - Blockly.Arduino.setups_['setup_espui'] += ui_elements; - Blockly.Arduino.setups_['setup_espui'] += ' ESPUI.begin("' + ui_name + '");\n'; - return null; -}; - -//Elements - -Blockly.Blocks['espui_button'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('espui'), - tags: ['webinterface'], - examples: ['lol.bly'], - init: function() { - var colorOptions = [ - ['none', 'COLOR_NONE'], - ['turquoise', 'COLOR_TURQUOISE'], - ['emerald', 'COLOR_EMERALD'], - ['peterriver', 'COLOR_PETERRIVER'], - ['wet asphalt', 'COLOR_WETASPHALT'], - ['sunflower', 'COLOR_SUNFLOWER'], - ['carrot', 'COLOR_CARROT'], - ['alizarin', 'COLOR_ALIZARIN'], - ]; - this.appendDummyInput() - .appendField('ESPUI Button') - .appendField(new Blockly.FieldTextInput('name'), 'ui_name'); - this.appendDummyInput() - .appendField('UI Color') - .appendField(new Blockly.FieldDropdown(colorOptions), 'ui_color'); - this.appendDummyInput() - .appendField('Button Text') - .appendField(new Blockly.FieldTextInput('name'), 'button_text'); - this.setColour("#3357c7"); - this.setPreviousStatement(true, 'ui_element'); - this.setNextStatement(true, 'ui_element'); - this.setTooltip('A web interface button'); - this.appendStatementInput('on_down') - .appendField('Pressed:') - .setCheck(null); - this.appendStatementInput('on_up') - .appendField('Released:') - .setCheck(null); - } -}; - -Blockly.Arduino['espui_button'] = function(block) { - var ui_name = block.getFieldValue('ui_name'); - var ui_color = block.getFieldValue('ui_color'); - var button_text = block.getFieldValue('button_text'); - var ui_name_clean = ui_name.replace(' ', '_'); - var on_down = Blockly.Arduino.statementToCode(block, 'on_down'); - var on_up = Blockly.Arduino.statementToCode(block, 'on_up'); - Blockly.Arduino.definitions_['define_ui_button_' + ui_name_clean] = - 'void button_' + ui_name_clean + '(Control c, int type) {\n' + - ' switch(type){\n' + - ' case B_DOWN:\n' + - on_down + '\n break;\n' + - ' case B_UP:\n' + - on_up + '\n break;\n' + - ' }\n' + - '}\n'; - - var code = ' ESPUI.button("' + ui_name + '", &button_' + ui_name_clean + ', ' + ui_color + ', "' + button_text + '");\n'; - return code; -}; - -Blockly.Blocks['espui_label'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('espui'), - tags: ['webinterface'], - examples: ['lol.bly'], - init: function() { - var colorOptions = [ - ['none', 'COLOR_NONE'], - ['turquoise', 'COLOR_TURQUOISE'], - ['emerald', 'COLOR_EMERALD'], - ['peterriver', 'COLOR_PETERRIVER'], - ['wet asphalt', 'COLOR_WETASPHALT'], - ['sunflower', 'COLOR_SUNFLOWER'], - ['carrot', 'COLOR_CARROT'], - ['alizarin', 'COLOR_ALIZARIN'], - ]; - this.appendDummyInput() - .appendField('ESPUI Label') - .appendField(new Blockly.FieldTextInput('label'), 'ui_name'); - this.appendDummyInput() - .appendField('UI Color') - .appendField(new Blockly.FieldDropdown(colorOptions), 'ui_color'); - this.appendDummyInput() - .appendField('Initial Value:') - .appendField(new Blockly.FieldTextInput('value'), 'start_value'); - this.setColour("#3357c7"); - this.setPreviousStatement(true, 'ui_element'); - this.setNextStatement(true, 'ui_element'); - this.setTooltip('A web interface label you can update from your code'); - } -}; - -Blockly.Arduino['espui_label'] = function(block) { - var ui_name = block.getFieldValue('ui_name'); - var ui_color = block.getFieldValue('ui_color'); - var ui_name_clean = ui_name.replace(' ', '_'); - var start_value = block.getFieldValue('start_value'); - - var code = ' ESPUI.label("' + ui_name + '", ' + ui_color + ', "' + start_value + '");\n'; - return code; -}; - -Blockly.Blocks['espui_switcher'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('espui'), - tags: ['webinterface'], - examples: ['lol.bly'], - init: function() { - var colorOptions = [ - ['none', 'COLOR_NONE'], - ['turquoise', 'COLOR_TURQUOISE'], - ['emerald', 'COLOR_EMERALD'], - ['peterriver', 'COLOR_PETERRIVER'], - ['wet asphalt', 'COLOR_WETASPHALT'], - ['sunflower', 'COLOR_SUNFLOWER'], - ['carrot', 'COLOR_CARROT'], - ['alizarin', 'COLOR_ALIZARIN'], - ]; - var stateOptions = [ - ['Off', 'false'], - ['On', 'true'], - ]; - this.appendDummyInput() - .appendField('ESPUI Switcher') - .appendField(new Blockly.FieldTextInput('name'), 'ui_name'); - this.appendDummyInput() - .appendField('UI Color') - .appendField(new Blockly.FieldDropdown(colorOptions), 'ui_color'); - this.appendDummyInput() - .appendField('Initial state') - .appendField(new Blockly.FieldDropdown(stateOptions), 'switcher_state'); - this.setColour("#3357c7"); - this.setPreviousStatement(true, 'ui_element'); - this.setNextStatement(true, 'ui_element'); - this.setTooltip('A web interface button'); - this.appendStatementInput('on_on') - .appendField('When swithed on:') - .setCheck(null); - this.appendStatementInput('on_off') - .appendField('When swithed off:') - .setCheck(null); - } -}; - -Blockly.Arduino['espui_switcher'] = function(block) { - var ui_name = block.getFieldValue('ui_name'); - var ui_color = block.getFieldValue('ui_color'); - var switcher_state = block.getFieldValue('switcher_state'); - var ui_name_clean = ui_name.replace(' ', '_'); - var on_on = Blockly.Arduino.statementToCode(block, 'on_down'); - var on_off = Blockly.Arduino.statementToCode(block, 'on_up'); - Blockly.Arduino.definitions_['define_ui_switcher_' + ui_name_clean] = - 'void switcher_' + ui_name_clean + '(Control c, int type) {\n' + - ' switch(type){\n' + - ' case S_ACTIVE:\n' + - on_on + '\n break;\n' + - ' case S_INACTIVE:\n' + - on_off + '\n break;\n' + - ' }\n' + - '}\n'; - - var code = ' ESPUI.switcher("' + ui_name + '", ' + switcher_state + ', &switcher_' + ui_name_clean + ', ' + ui_color + ');\n'; - return code; -}; - -Blockly.Blocks['espui_pad'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('espui'), - tags: ['webinterface'], - examples: ['lol.bly'], - init: function() { - var colorOptions = [ - ['none', 'COLOR_NONE'], - ['turquoise', 'COLOR_TURQUOISE'], - ['emerald', 'COLOR_EMERALD'], - ['peterriver', 'COLOR_PETERRIVER'], - ['wet asphalt', 'COLOR_WETASPHALT'], - ['sunflower', 'COLOR_SUNFLOWER'], - ['carrot', 'COLOR_CARROT'], - ['alizarin', 'COLOR_ALIZARIN'], - ]; - var centerOptions = [ - ['Yes', 'false'], - ['No', 'true'], - ]; - this.appendDummyInput() - .appendField('ESPUI ButtonPad') - .appendField(new Blockly.FieldTextInput('name'), 'ui_name'); - this.appendDummyInput() - .appendField('UI Color') - .appendField(new Blockly.FieldDropdown(colorOptions), 'ui_color'); - this.appendDummyInput() - .appendField('Center button') - .appendField(new Blockly.FieldDropdown(centerOptions), 'pad_center'); - this.setColour("#3357c7"); - this.setPreviousStatement(true, 'ui_element'); - this.setNextStatement(true, 'ui_element'); - this.setTooltip('A web interface button'); - - this.appendStatementInput('on_down_for') - .appendField('Forward press:') - .setCheck(null); - this.appendStatementInput('on_up_for') - .appendField('Forward release:') - .setCheck(null); - - this.appendStatementInput('on_down_back') - .appendField('Back press:') - .setCheck(null); - this.appendStatementInput('on_up_back') - .appendField('Back release:') - .setCheck(null); - - this.appendStatementInput('on_down_left') - .appendField('Right press:') - .setCheck(null); - this.appendStatementInput('on_up_left') - .appendField('Right release:') - .setCheck(null); - - this.appendStatementInput('on_down_right') - .appendField('Left press:') - .setCheck(null); - this.appendStatementInput('on_up_right') - .appendField('Left release:') - .setCheck(null); - - this.appendStatementInput('on_down_center') - .appendField('Center press:') - .setCheck(null); - this.appendStatementInput('on_up_center') - .appendField('Center release:') - .setCheck(null); - } -}; - -Blockly.Arduino['espui_pad'] = function(block) { - var ui_name = block.getFieldValue('ui_name'); - var ui_color = block.getFieldValue('ui_color'); - var pad_center = block.getFieldValue('pad_center'); - var ui_name_clean = ui_name.replace(' ', '_'); - - var on_down_for = Blockly.Arduino.statementToCode(block, 'on_down_for'); - var on_up_for = Blockly.Arduino.statementToCode(block, 'on_up_for'); - - var on_down_back = Blockly.Arduino.statementToCode(block, 'on_down_back'); - var on_up_back = Blockly.Arduino.statementToCode(block, 'on_up_back'); - - var on_down_left = Blockly.Arduino.statementToCode(block, 'on_down_left'); - var on_up_left = Blockly.Arduino.statementToCode(block, 'on_up_left'); - - var on_down_right = Blockly.Arduino.statementToCode(block, 'on_down_right'); - var on_up_right = Blockly.Arduino.statementToCode(block, 'on_up_right'); - - var on_down_center = Blockly.Arduino.statementToCode(block, 'on_down_center'); - var on_up_center = Blockly.Arduino.statementToCode(block, 'on_up_center'); - - - Blockly.Arduino.definitions_['define_ui_pad_' + ui_name_clean] = - 'void pad_' + ui_name_clean + '(Control c, int type) {\n' + - ' switch(type){\n' + - - ' case P_FOR_DOWN:\n' + - on_down_for + '\n break;\n' + - ' case P_FOR_UP:\n' + - on_up_for + '\n break;\n' + - - ' case P_BACK_DOWN:\n' + - on_down_back + '\n break;\n' + - ' case P_BACK_UP:\n' + - on_up_back + '\n break;\n' + - - ' case P_RIGHT_DOWN:\n' + - on_down_left + '\n break;\n' + - ' case P_RIGHT_UP:\n' + - on_up_left + '\n break;\n' + - - ' case P_LEFT_DOWN:\n' + - on_down_right + '\n break;\n' + - ' case P_LEFT_UP:\n' + - on_up_right + '\n break;\n' + - - ' case P_CENTER_DOWN:\n' + - on_down_center + '\n break;\n' + - ' case P_CENTER_UP:\n' + - on_up_center + '\n break;\n' + - ' }\n' + - '}\n'; - - var code = ' ESPUI.pad("' + ui_name + '", ' + pad_center + ', &pad_' + ui_name_clean + ', ' + ui_color + ');\n'; - return code; -}; diff --git a/img/blocks/acknowledgements.html b/img/blocks/acknowledgements.html new file mode 100644 index 0000000..c29dcbc --- /dev/null +++ b/img/blocks/acknowledgements.html @@ -0,0 +1,2 @@ +
Icons made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY
+
Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
\ No newline at end of file diff --git a/img/blocks/button_pressed.svg b/img/blocks/button_pressed.svg new file mode 100644 index 0000000..c7cf5a1 --- /dev/null +++ b/img/blocks/button_pressed.svg @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/img/blocks/button_released.svg b/img/blocks/button_released.svg new file mode 100644 index 0000000..7be0a56 --- /dev/null +++ b/img/blocks/button_released.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/img/blocks/controller_center_pressed.svg b/img/blocks/controller_center_pressed.svg new file mode 100644 index 0000000..146e841 --- /dev/null +++ b/img/blocks/controller_center_pressed.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_center_released.svg b/img/blocks/controller_center_released.svg new file mode 100644 index 0000000..be2676b --- /dev/null +++ b/img/blocks/controller_center_released.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_down_pressed.svg b/img/blocks/controller_down_pressed.svg new file mode 100644 index 0000000..be13e67 --- /dev/null +++ b/img/blocks/controller_down_pressed.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_down_released.svg b/img/blocks/controller_down_released.svg new file mode 100644 index 0000000..cd091f2 --- /dev/null +++ b/img/blocks/controller_down_released.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_left_pressed.svg b/img/blocks/controller_left_pressed.svg new file mode 100644 index 0000000..b2a800e --- /dev/null +++ b/img/blocks/controller_left_pressed.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_left_released.svg b/img/blocks/controller_left_released.svg new file mode 100644 index 0000000..c66916c --- /dev/null +++ b/img/blocks/controller_left_released.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_right_pressed.svg b/img/blocks/controller_right_pressed.svg new file mode 100644 index 0000000..6e42679 --- /dev/null +++ b/img/blocks/controller_right_pressed.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_right_released.svg b/img/blocks/controller_right_released.svg new file mode 100644 index 0000000..8946a5a --- /dev/null +++ b/img/blocks/controller_right_released.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_up_pressed.svg b/img/blocks/controller_up_pressed.svg new file mode 100644 index 0000000..a67ea73 --- /dev/null +++ b/img/blocks/controller_up_pressed.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/controller_up_released.svg b/img/blocks/controller_up_released.svg new file mode 100644 index 0000000..ec66d54 --- /dev/null +++ b/img/blocks/controller_up_released.svg @@ -0,0 +1,97 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/switch_off.svg b/img/blocks/switch_off.svg new file mode 100644 index 0000000..a216630 --- /dev/null +++ b/img/blocks/switch_off.svg @@ -0,0 +1,64 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/switch_on.svg b/img/blocks/switch_on.svg new file mode 100644 index 0000000..9b1539a --- /dev/null +++ b/img/blocks/switch_on.svg @@ -0,0 +1,61 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/lang/ESPUI.json b/lang/ESPUI.json new file mode 100644 index 0000000..1dbb238 --- /dev/null +++ b/lang/ESPUI.json @@ -0,0 +1,27 @@ +{ + "langs": + { + "en-GB": + { + "keys": + { + "LANG_SUBCATERGORY_ESPUI": "User Interface", + "LANG_ESPUI_ESPUI_TITLE": "Title", + "LANG_ESPUI_ESPUI_HOTSPOT": "Enable Wifi Hotspot Code", + "LANG_ESPUI_ESPUI_TOOLTIP": "Creates a webinterface on the ESP32/ESP8266", + "LANG_ESPUI_BUTTON_BUTTON": "UI Button", + "LANG_ESPUI_NAME": "name", + "LANG_ESPUI_COLOR": "Color", + "LANG_ESPUI_TEXT": "Text", + "LANG_ESPUI_BUTTON_TOOLTIP": "A web interface button", + "LANG_ESPUI_LABEL_LABEL": "UI Label", + "LANG_ESPUI_LABEL": "Label", + "LANG_ESPUI_LABEL_TOOLTIP": "A web interface label you can update from your code", + "LANG_ESPUI_STATE": "State", + "LANG_ESPUI_SWITCH_SWITCH": "UI Switch", + "LANG_ESPUI_PAD_PAD": "UI Pad", + "LANG_ESPUI_PAD_CENTER": "Center button?" + } + } + } +} \ No newline at end of file From 697e8cc86180bb1b397d55b64a7ffa8596eed7f5 Mon Sep 17 00:00:00 2001 From: roboticafacil Date: Sat, 9 Dec 2017 14:16:27 +0100 Subject: [PATCH 2/2] modified: ESPUI_blocks.js --- ESPUI_blocks.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ESPUI_blocks.js b/ESPUI_blocks.js index d45fb97..1813db3 100644 --- a/ESPUI_blocks.js +++ b/ESPUI_blocks.js @@ -1,6 +1,7 @@ // This is a block definition for projects like roboblocks // // Main Block +Facilino.LANG_COLOUR_HTML = '#BDBDBD'; Facilino.LANG_COLOUR_ESPUI = '#B1B1B1'; Blockly.Blocks['espui'] = {