mirror of
https://github.com/s00500/ESPUI.git
synced 2025-07-04 01:00:19 +00:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
c54c15dca6 | |||
9a8ca67691 | |||
479792e335 | |||
489ba045fb | |||
aedeb2b2d1 | |||
079ecf7c16 | |||
8d165679d4 | |||
b2c7122547 | |||
d19895faf7 | |||
24dafcc8bb | |||
09e3a9c71b | |||
ac3b8795d4 | |||
d8ae8a70cf | |||
2e05965d45 | |||
7acb9c367d | |||
ba06ff5fbf | |||
fa4499c7ca | |||
d7e5b5cde5 |
59
README.md
59
README.md
@ -2,7 +2,7 @@
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
ESPUI is a simple library to make a web user interface for your projects using the **ESP32**
|
ESPUI is a simple library to make a web user interface for your projects using the **ESP8266** or the **ESP32**
|
||||||
It uses web sockets and lets you create, control, and update elements on your GUI through multiple devices like phones and tablets.
|
It uses web sockets and lets you create, control, and update elements on your GUI through multiple devices like phones and tablets.
|
||||||
|
|
||||||
ESPUI uses simple Arduino-style syntax for creating a solid, functioning user interface without too much boilerplate code.
|
ESPUI uses simple Arduino-style syntax for creating a solid, functioning user interface without too much boilerplate code.
|
||||||
@ -11,13 +11,18 @@ So if you either don't know how or just don't want to waste time: this is your s
|
|||||||
|
|
||||||
I completely rewrote the EasyUI Library created by ayushsharma82 [Here](https://github.com/ayushsharma82/)
|
I completely rewrote the EasyUI Library created by ayushsharma82 [Here](https://github.com/ayushsharma82/)
|
||||||
Now it uses ESPAsyncWebserver and is mainly to be used with the ESP32 Processor.
|
Now it uses ESPAsyncWebserver and is mainly to be used with the ESP32 Processor.
|
||||||
ESP8266 support will be interesting maybe in the future.
|
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
This library is dependent on the following libraries to function properly.
|
This library is dependent on the following libraries to function properly.
|
||||||
- [ESP32 Core Library](https://github.com/espressif/arduino-esp32)
|
|
||||||
- [ESPAsyncWebserver](https://github.com/me-no-dev/ESPAsyncWebServer)
|
- [ESPAsyncWebserver](https://github.com/me-no-dev/ESPAsyncWebServer)
|
||||||
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson)
|
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson)
|
||||||
|
|
||||||
|
**Plus for ESP8266**
|
||||||
|
- [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP)
|
||||||
|
|
||||||
|
**Additionally necessary for ESP32**
|
||||||
|
- [AsyncTCP](https://github.com/me-no-dev/AsyncTCP)
|
||||||
|
|
||||||
|
|
||||||
## How to Install
|
## How to Install
|
||||||
@ -27,7 +32,7 @@ Make sure all the dependencies are installed, then install like so:
|
|||||||
#### Directly Through Arduino IDE
|
#### Directly Through Arduino IDE
|
||||||
|
|
||||||
You can find this Library in the Arduino IDE library manager
|
You can find this Library in the Arduino IDE library manager
|
||||||
Go to Sketch > Include Library > Library Manager > Search for "EasyUI" > Install
|
Go to Sketch > Include Library > Library Manager > Search for "ESPUI" > Install
|
||||||
|
|
||||||
#### Manual Install
|
#### Manual Install
|
||||||
|
|
||||||
@ -44,10 +49,21 @@ Download the [Repository](https://github.com/s00500/ESPUI/archive/master.zip), G
|
|||||||
## Getting started (Filesystem upload)
|
## Getting started (Filesystem upload)
|
||||||
|
|
||||||
ESPUI **NEEDS** its files burnt on the SPIFFS filesystem on the ESP. **Without this ESPUI will NOT work at all**
|
ESPUI **NEEDS** its files burnt on the SPIFFS filesystem on the ESP. **Without this ESPUI will NOT work at all**
|
||||||
|
There are now two ways to do this: you can either use the upload tool or you use the library function `ESPUI.prepareFileSystem()`
|
||||||
|
|
||||||
To do this download and install me-no-devs wonderful [ESP32 sketch data uploader](https://github.com/me-no-dev/arduino-esp32fs-plugin)
|
#### Simple filesystem preparation (recomended)
|
||||||
|
|
||||||
Then open the example sketch and select "ESP32 Upload Sketch Data" from the Tools menu.
|
Just open the example sketch **prepareFileSystem** and run it on the ESP, (give it 5 - 10 seconds),
|
||||||
|
The library will create all needed files.
|
||||||
|
Congratulations, you are done, from now on you just need to to this again when there is a library update, or when you want to use another chip :-)
|
||||||
|
Now you can upload your normal sketch, when you do not call the `ESPUI.prepareFileSystem()` function the compiler will strip out all the unnecessary that is already saved in the chip's filesystem and you have more programm memory to work with.
|
||||||
|
|
||||||
|
|
||||||
|
#### Manual way (mainly for development)
|
||||||
|
|
||||||
|
To do this download and install me-no-devs wonderful [ESP32 sketch data uploader](https://github.com/me-no-dev/arduino-esp32fs-plugin) or for ESP8266 [ESP8266 sketch data uploader](https://github.com/esp8266/arduino-esp8266fs-plugin)
|
||||||
|
|
||||||
|
Then open the **gui** example sketch and select "Upload Sketch Data" from the Tools menu for your processor.
|
||||||
Now you are set to go and use any code you want to with this library
|
Now you are set to go and use any code you want to with this library
|
||||||
|
|
||||||
## User interface Elements
|
## User interface Elements
|
||||||
@ -56,18 +72,19 @@ Now you are set to go and use any code you want to with this library
|
|||||||
- Switch (updateable)
|
- Switch (updateable)
|
||||||
- Control pad
|
- Control pad
|
||||||
- Control pad with center button
|
- Control pad with center button
|
||||||
|
- Slider
|
||||||
|
|
||||||
Checkout the example for the usage
|
Checkout the example for the usage
|
||||||
|
|
||||||
## Roadmap :
|
## Roadmap :
|
||||||
|
|
||||||
- refactor id system
|
- ~~Setup SPIFFS using values in program memory~~
|
||||||
- make button colour customisable
|
- ~~ESP8266 support~~
|
||||||
- do a proper redesign
|
- Document slider
|
||||||
- cleanup unnecessary CSS
|
- proper return value (as int and not as string) for slider
|
||||||
- gzip files to make them load faster
|
- Maybe a slider range setting, meanwhile please use map()
|
||||||
- setup spiffs using values in program memory ? (if you have feedback to this idea let me know)
|
- Improve slider stability
|
||||||
- ESP8266 support
|
- Improve general stability
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
@ -77,7 +94,7 @@ ESPUI does not need network access and can be used in standalone access point mo
|
|||||||
All assets are loaded from the internal SPIFFS filesystem of the ESP32.
|
All assets are loaded from the internal SPIFFS filesystem of the ESP32.
|
||||||
|
|
||||||
This section will explain in detail how the Library is to be used from the Arduino code side. As of now the Facilino blocks are not implemented.
|
This section will explain in detail how the Library is to be used from the Arduino code side. As of now the Facilino blocks are not implemented.
|
||||||
In the arduino setup() routine the interface can be customised by adding UI Elements. This is done by calling the corresponding library methods on the Library object ESPUI. Eg: ESPUI.button(“button”, &myCallback); creates a button in the interface that calls the “my-Callback” function when changed. All buttons and items call their callback whenever there is a state change from them. This means the button will call the callback when it is pressed and also again when it is released. To seperate different events an integer number with the event name is passed to the callback function that can be handled in a switch(){}case{} statement. Here is an overview of the currently implemented different elements of the UI library:
|
In the arduino setup() routine the interface can be customised by adding UI Elements. This is done by calling the corresponding library methods on the Library object ESPUI. Eg: ESPUI.button(“button”, &myCallback); creates a button in the interface that calls the “myCallback” function when changed. All buttons and items call their callback whenever there is a state change from them. This means the button will call the callback when it is pressed and also again when it is released. To separate different events an integer number with the event name is passed to the callback function that can be handled in a switch(){}case{} statement. Here is an overview of the currently implemented different elements of the UI library:
|
||||||
|
|
||||||
|
|
||||||
#### Button
|
#### Button
|
||||||
@ -105,11 +122,15 @@ Button pads come in two flavours: with or without a center button. They are very
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Labels are a nice tool to get information from the robot to the user interface. This can be done to show states, values of sensors and configuration parameters. To send data from the code use ESP.print(labelId, “Text”); . Labels get a name on creation and a initial value. The name is not changeable once the UI initialized.
|
Labels are a nice tool to get information from the robot to the user interface. This can be done to show states, values of sensors and configuration parameters. To send data from the code use ESP.print(labelId, “Text”); . Labels get a name on creation and a initial value. The name is not changeable once the UI initialised.
|
||||||
|
|
||||||
#### Initialization of the UI
|
#### Slider
|
||||||
|
|
||||||
After all the elements are configured you can use ESPUI.begin(“Some Title”); to start the UI interface. The web interface can then be used from multiple devices at once and also shows an connection status in the top bar.
|
There is also an slider component now, needs to be documented though
|
||||||
|
|
||||||
|
#### Initialisation of the UI
|
||||||
|
|
||||||
|
After all the elements are configured you can use ESPUI.begin(“Some Title”); to start the UI interface. Make sure you setup a working network connection or AccesPoint **before** (See example). The web interface can then be used from multiple devices at once and also shows an connection status in the top bar.
|
||||||
The library is designed to be easy to use and can still be extended with a lot of more functionality.
|
The library is designed to be easy to use and can still be extended with a lot of more functionality.
|
||||||
|
|
||||||
|
|
||||||
|
189
blocks.js
189
blocks.js
@ -7,9 +7,16 @@ Blockly.Blocks['espui'] = {
|
|||||||
tags: ['webinterface'],
|
tags: ['webinterface'],
|
||||||
examples: ['lol.bly'],
|
examples: ['lol.bly'],
|
||||||
init: function() {
|
init: function() {
|
||||||
|
var wifiOptions = [
|
||||||
|
['No', false],
|
||||||
|
['Yes', true]
|
||||||
|
];
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField('ESPUI Title:')
|
.appendField('ESPUI Title:')
|
||||||
.appendField(new Blockly.FieldTextInput('string'), 'ui_name');
|
.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')
|
this.appendStatementInput('ui_elements')
|
||||||
.setCheck('ui_element');
|
.setCheck('ui_element');
|
||||||
this.setColour("#37d1f9");
|
this.setColour("#37d1f9");
|
||||||
@ -19,11 +26,21 @@ Blockly.Blocks['espui'] = {
|
|||||||
|
|
||||||
Blockly.Arduino['espui'] = function(block) {
|
Blockly.Arduino['espui'] = function(block) {
|
||||||
var ui_name = block.getFieldValue('ui_name');
|
var ui_name = block.getFieldValue('ui_name');
|
||||||
|
var wifi_option = block.getFieldValue('wifi_option');
|
||||||
var ui_elements = Blockly.Arduino.statementToCode(block, 'ui_elements');
|
var ui_elements = Blockly.Arduino.statementToCode(block, 'ui_elements');
|
||||||
Blockly.Arduino.definitions_['define_wifi_h'] = '#include <WiFi.h>';
|
Blockly.Arduino.definitions_['define_wifi_h'] = '#include <WiFi.h>';
|
||||||
Blockly.Arduino.definitions_['define_espui_h'] = '#include <ESPUI.h>';
|
Blockly.Arduino.definitions_['define_espui_h'] = '#include <ESPUI.h>';
|
||||||
Blockly.Arduino.setups_['setup_espui'] = ui_elements;
|
Blockly.Arduino.setups_['setup_espui'] = '\n';
|
||||||
Blockly.Arduino.setups_['setup_espui'] += '\nESPUI.begin("' + ui_name + '");\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;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,6 +68,9 @@ Blockly.Blocks['espui_button'] = {
|
|||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField('UI Color')
|
.appendField('UI Color')
|
||||||
.appendField(new Blockly.FieldDropdown(colorOptions), '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.setColour("#3357c7");
|
||||||
this.setPreviousStatement(true, 'ui_element');
|
this.setPreviousStatement(true, 'ui_element');
|
||||||
this.setNextStatement(true, 'ui_element');
|
this.setNextStatement(true, 'ui_element');
|
||||||
@ -67,17 +87,21 @@ Blockly.Blocks['espui_button'] = {
|
|||||||
Blockly.Arduino['espui_button'] = function(block) {
|
Blockly.Arduino['espui_button'] = function(block) {
|
||||||
var ui_name = block.getFieldValue('ui_name');
|
var ui_name = block.getFieldValue('ui_name');
|
||||||
var ui_color = block.getFieldValue('ui_color');
|
var ui_color = block.getFieldValue('ui_color');
|
||||||
|
var button_text = block.getFieldValue('button_text');
|
||||||
var ui_name_clean = ui_name.replace(' ', '_');
|
var ui_name_clean = ui_name.replace(' ', '_');
|
||||||
var on_down = Blockly.Arduino.statementToCode(block, 'on_down');
|
var on_down = Blockly.Arduino.statementToCode(block, 'on_down');
|
||||||
var on_up = Blockly.Arduino.statementToCode(block, 'on_up');
|
var on_up = Blockly.Arduino.statementToCode(block, 'on_up');
|
||||||
Blockly.Arduino.definitions_['define_ui_button_' + ui_name_clean] =
|
Blockly.Arduino.definitions_['define_ui_button_' + ui_name_clean] =
|
||||||
'void button_' + ui_name_clean + '(Control c, int type) {\nswitch(type){\ncase B_DOWN:\n' +
|
'void button_' + ui_name_clean + '(Control c, int type) {\n' +
|
||||||
on_down + '\nbreak;\n' +
|
' switch(type){\n' +
|
||||||
'case B_UP:\n' +
|
' case B_DOWN:\n' +
|
||||||
on_up + '\nbreak;\n' +
|
on_down + '\n break;\n' +
|
||||||
|
' case B_UP:\n' +
|
||||||
|
on_up + '\n break;\n' +
|
||||||
|
' }\n' +
|
||||||
'}\n';
|
'}\n';
|
||||||
|
|
||||||
var code = 'ESPUI.button("' + ui_name + '",&button_' + ui_name_clean + ', ' + ui_color + ');\n';
|
var code = ' ESPUI.button("' + ui_name + '", &button_' + ui_name_clean + ', ' + ui_color + ', "' + button_text + '");\n';
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -119,7 +143,7 @@ Blockly.Arduino['espui_label'] = function(block) {
|
|||||||
var ui_name_clean = ui_name.replace(' ', '_');
|
var ui_name_clean = ui_name.replace(' ', '_');
|
||||||
var start_value = block.getFieldValue('start_value');
|
var start_value = block.getFieldValue('start_value');
|
||||||
|
|
||||||
var code = 'ESPUI.label("' + ui_name + '", ' + ui_color + ', "' + start_value + '");\n';
|
var code = ' ESPUI.label("' + ui_name + '", ' + ui_color + ', "' + start_value + '");\n';
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -139,12 +163,19 @@ Blockly.Blocks['espui_switcher'] = {
|
|||||||
['carrot', 'COLOR_CARROT'],
|
['carrot', 'COLOR_CARROT'],
|
||||||
['alizarin', 'COLOR_ALIZARIN'],
|
['alizarin', 'COLOR_ALIZARIN'],
|
||||||
];
|
];
|
||||||
|
var stateOptions = [
|
||||||
|
['Off', 'false'],
|
||||||
|
['On', 'true'],
|
||||||
|
];
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField('ESPUI Switcher')
|
.appendField('ESPUI Switcher')
|
||||||
.appendField(new Blockly.FieldTextInput('name'), 'ui_name');
|
.appendField(new Blockly.FieldTextInput('name'), 'ui_name');
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField('UI Color')
|
.appendField('UI Color')
|
||||||
.appendField(new Blockly.FieldDropdown(colorOptions), '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.setColour("#3357c7");
|
||||||
this.setPreviousStatement(true, 'ui_element');
|
this.setPreviousStatement(true, 'ui_element');
|
||||||
this.setNextStatement(true, 'ui_element');
|
this.setNextStatement(true, 'ui_element');
|
||||||
@ -161,16 +192,148 @@ Blockly.Blocks['espui_switcher'] = {
|
|||||||
Blockly.Arduino['espui_switcher'] = function(block) {
|
Blockly.Arduino['espui_switcher'] = function(block) {
|
||||||
var ui_name = block.getFieldValue('ui_name');
|
var ui_name = block.getFieldValue('ui_name');
|
||||||
var ui_color = block.getFieldValue('ui_color');
|
var ui_color = block.getFieldValue('ui_color');
|
||||||
|
var switcher_state = block.getFieldValue('switcher_state');
|
||||||
var ui_name_clean = ui_name.replace(' ', '_');
|
var ui_name_clean = ui_name.replace(' ', '_');
|
||||||
var on_on = Blockly.Arduino.statementToCode(block, 'on_down');
|
var on_on = Blockly.Arduino.statementToCode(block, 'on_down');
|
||||||
var on_off = Blockly.Arduino.statementToCode(block, 'on_up');
|
var on_off = Blockly.Arduino.statementToCode(block, 'on_up');
|
||||||
Blockly.Arduino.definitions_['define_ui_switcher_' + ui_name_clean] =
|
Blockly.Arduino.definitions_['define_ui_switcher_' + ui_name_clean] =
|
||||||
'void switcher_' + ui_name_clean + '(Control c, int type) {\nswitch(type){\ncase S_ACTIVE:\n' +
|
'void switcher_' + ui_name_clean + '(Control c, int type) {\n' +
|
||||||
on_on + '\nbreak;\n' +
|
' switch(type){\n' +
|
||||||
'case S_INACTIVE:\n' +
|
' case S_ACTIVE:\n' +
|
||||||
on_off + '\nbreak;\n' +
|
on_on + '\n break;\n' +
|
||||||
|
' case S_INACTIVE:\n' +
|
||||||
|
on_off + '\n break;\n' +
|
||||||
|
' }\n' +
|
||||||
'}\n';
|
'}\n';
|
||||||
|
|
||||||
var code = 'ESPUI.switcher("' + ui_name + '",&switcher_' + ui_name_clean + ', ' + ui_color + ', false);\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;
|
return code;
|
||||||
};
|
};
|
||||||
|
1
examples/gui/data/css/normalize.min.css
vendored
Normal file
1
examples/gui/data/css/normalize.min.css
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}
|
@ -1,8 +1,3 @@
|
|||||||
body {
|
|
||||||
font-family: 'Open Sans', sans-serif;
|
|
||||||
background-color: #ecf0f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 79%;
|
width: 79%;
|
||||||
@ -26,6 +21,10 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card-slider {
|
||||||
|
padding-bottom: 10px
|
||||||
|
}
|
||||||
|
|
||||||
.turquoise {
|
.turquoise {
|
||||||
background: #1abc9c;
|
background: #1abc9c;
|
||||||
border-bottom: #16a085 3px solid;
|
border-bottom: #16a085 3px solid;
|
||||||
@ -225,11 +224,11 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
/* currently ems cause chrome bug misinterpreting rems on body element */
|
|
||||||
line-height: 1.0;
|
line-height: 1.0;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
font-family: 'Open Sans', sans-serif;
|
||||||
color: #222;
|
color: #222;
|
||||||
|
background-color: #ecf0f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Typography
|
/* Typography
|
||||||
@ -325,6 +324,9 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Main Head Part
|
||||||
|
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||||
|
|
||||||
#mainHeader {
|
#mainHeader {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
@ -334,23 +336,6 @@
|
|||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tables
|
|
||||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
|
||||||
|
|
||||||
th, td {
|
|
||||||
padding: 12px 15px;
|
|
||||||
text-align: left;
|
|
||||||
border-bottom: 1px solid #E1E1E1;
|
|
||||||
}
|
|
||||||
|
|
||||||
th:first-child, td:first-child {
|
|
||||||
padding-left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
th:last-child, td:last-child {
|
|
||||||
padding-right: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Spacing
|
/* Spacing
|
||||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||||
|
|
||||||
@ -358,14 +343,6 @@
|
|||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
input, textarea, select, fieldset {
|
|
||||||
margin-bottom: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre, blockquote, dl, figure, table, p, ul, ol, form {
|
|
||||||
margin-bottom: 2.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Utilities
|
/* Utilities
|
||||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||||
|
|
||||||
@ -584,3 +561,205 @@
|
|||||||
.switch .icon-remove {
|
.switch .icon-remove {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
Material Design Range Slider - by Ravikumar Chauhan
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
.rkmd-slider {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
font-size: 16px;
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"] {
|
||||||
|
overflow: hidden;
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"] + .slider {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 4px;
|
||||||
|
background-color: #bebebe;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"] + .slider .slider-fill {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
width: 0%;
|
||||||
|
height: 100%;
|
||||||
|
user-select: none;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"] + .slider .slider-handle {
|
||||||
|
cursor: pointer;
|
||||||
|
position: absolute;
|
||||||
|
top: -5.5px;
|
||||||
|
left: 0%;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
margin-left: -8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
transition: all .2s ease;
|
||||||
|
user-select: none;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider {
|
||||||
|
background-color: #b0b0b0 !important;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-fill,
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-handle {
|
||||||
|
cursor: default !important;
|
||||||
|
background-color: #b0b0b0 !important;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-fill .slider-label,
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-handle .slider-label {
|
||||||
|
display: none;
|
||||||
|
background-color: #b0b0b0 !important;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-fill.is-active,
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-handle.is-active {
|
||||||
|
top: -5.5px;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
margin-left: -8px;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-fill.is-active .slider-label,
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-handle.is-active .slider-label {
|
||||||
|
display: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
.rkmd-slider input[type="range"]:disabled + .slider .slider-handle:active {
|
||||||
|
box-shadow: none !important;
|
||||||
|
transform: scale(1) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
Discrete Range Slider - by Ravikumar Chauhan
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
.rkmd-slider.slider-discrete .slider .slider-handle {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete .slider .slider-handle .slider-label {
|
||||||
|
position: absolute;
|
||||||
|
top: -17.5px;
|
||||||
|
left: -2px;
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
-webkit-transform-origin: 50% 100%;
|
||||||
|
transform-origin: 50% 100%;
|
||||||
|
border-radius: 50%;
|
||||||
|
-webkit-transform: scale(0.5) rotate(-45deg);
|
||||||
|
transform: scale(0.5) rotate(-45deg);
|
||||||
|
-webkit-transition: all .2s ease;
|
||||||
|
transition: all .2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete .slider .slider-handle .slider-label span {
|
||||||
|
position: absolute;
|
||||||
|
top: 7px;
|
||||||
|
left: 0px;
|
||||||
|
width: 100%;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
text-align: center;
|
||||||
|
-webkit-transform: rotate(45deg);
|
||||||
|
transform: rotate(45deg);
|
||||||
|
opacity: 0;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-moz-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete .slider .slider-handle.is-active {
|
||||||
|
top: 0px;
|
||||||
|
margin-left: -2px;
|
||||||
|
width: 4px;
|
||||||
|
height: 4px;
|
||||||
|
}
|
||||||
|
.rkmd-slider.slider-discrete .slider .slider-handle.is-active .slider-label {
|
||||||
|
top: -15px;
|
||||||
|
left: -2px;
|
||||||
|
border-radius: 15px 15px 15px 0;
|
||||||
|
-webkit-transform: rotate(-45deg) translate(23px, -25px);
|
||||||
|
transform: rotate(-45deg) translate(23px, -25px);
|
||||||
|
}
|
||||||
|
.rkmd-slider.slider-discrete .slider .slider-handle.is-active .slider-label span {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete.slider-turquoise .slider-label {
|
||||||
|
background-color: #16a085;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete.slider-emerald .slider-label {
|
||||||
|
background-color: #27ae60;
|
||||||
|
}
|
||||||
|
|
||||||
|
.peterriver {
|
||||||
|
background: #3498db;
|
||||||
|
border-bottom: #2980b9 3px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete.slider-peterriver .slider-label {
|
||||||
|
background-color: #2980b9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wetasphalt {
|
||||||
|
background: #34495e;
|
||||||
|
border-bottom: #2c3e50 3px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete.slider-wetasphalt .slider-label {
|
||||||
|
background-color: #2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sunflower {
|
||||||
|
background: #f1c40f;
|
||||||
|
border-bottom: #E6BB0F 3px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete.slider-sunflower .slider-label {
|
||||||
|
background-color: #E6BB0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carrot {
|
||||||
|
background: #e67e22;
|
||||||
|
border-bottom: #d35400 3px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete.slider-carrot .slider-label {
|
||||||
|
background-color: #d35400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alizarin {
|
||||||
|
background: #e74c3c;
|
||||||
|
border-bottom: #c0392b 3px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rkmd-slider.slider-discrete.slider-alizarin .slider-label {
|
||||||
|
background-color: #c0392b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
.rkmd-slider.slider-light input[type="range"] + .slider {
|
||||||
|
background-color: #5c5c5c;
|
||||||
|
}
|
||||||
|
.rkmd-slider.slider-light input[type="range"]:disabled + .slider {
|
||||||
|
background-color: #5c5c5c !important;
|
||||||
|
}
|
||||||
|
.rkmd-slider.slider-light input[type="range"]:disabled + .slider .slider-fill,
|
||||||
|
.rkmd-slider.slider-light input[type="range"]:disabled + .slider .slider-handle {
|
||||||
|
background-color: #5c5c5c !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
1
examples/gui/data/css/style.min.css
vendored
Normal file
1
examples/gui/data/css/style.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -9,10 +9,13 @@
|
|||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="/css/normalize.css">
|
<link rel="stylesheet" href="/css/normalize.css">
|
||||||
<link rel="stylesheet" href="/css/style.css">
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
|
|
||||||
|
<script src="/js/zepto.js"></script>
|
||||||
|
<script src="/js/slider.js"></script>
|
||||||
|
<script src="/js/controls.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="javascript:start();">
|
<body onload="javascript:start();">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h4><div id="mainHeader">Control</div> <span id="conStatus" class="label">Offline</span></h4></div>
|
<h4><div id="mainHeader">Control</div> <span id="conStatus" class="label">Offline</span></h4></div>
|
||||||
<hr />
|
<hr />
|
||||||
@ -20,9 +23,6 @@
|
|||||||
<div id="row" class="row u-full-width">
|
<div id="row" class="row u-full-width">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/js/zepto.js"></script>
|
|
||||||
<script src="/js/controls.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
21
examples/gui/data/js/controls.js
vendored
21
examples/gui/data/js/controls.js
vendored
@ -6,6 +6,8 @@ const UI_PAD = 4;
|
|||||||
const UI_CPAD = 5;
|
const UI_CPAD = 5;
|
||||||
const UPDATE_LABEL = 6;
|
const UPDATE_LABEL = 6;
|
||||||
const UPDATE_SWITCHER = 7;
|
const UPDATE_SWITCHER = 7;
|
||||||
|
const UI_SLIDER = 8;
|
||||||
|
const UPDATE_SLIDER = 9;
|
||||||
|
|
||||||
const FOR = 0;
|
const FOR = 0;
|
||||||
const BACK = 1;
|
const BACK = 1;
|
||||||
@ -214,6 +216,25 @@ function start() {
|
|||||||
else
|
else
|
||||||
switcher(data.id, 1);
|
switcher(data.id, 1);
|
||||||
break;
|
break;
|
||||||
|
case UI_SLIDER:
|
||||||
|
$('#row').append(
|
||||||
|
"<div class='two columns card tcenter card-slider " + colorClass(data.color) + "'>" +
|
||||||
|
"<h5 id='" + data.id + "'>" + data.label + "</h5><hr />" +
|
||||||
|
"<div id='sl" + data.id + "' class='rkmd-slider slider-discrete slider-" + colorClass(data.color) + "'>" +
|
||||||
|
"<input type='range' min='0' max='100' value='" + data.value + "'>" +
|
||||||
|
"</div>" +
|
||||||
|
"</div>"
|
||||||
|
);
|
||||||
|
$('#row').append(
|
||||||
|
"<script>" +
|
||||||
|
"rkmd_rangeSlider('#sl" + data.id + "');" +
|
||||||
|
"</script>"
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UPDATE_SLIDER:
|
||||||
|
slider_move($('#sl'+data.id), data.value ,'100', false);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.error('Unknown type or event');
|
console.error('Unknown type or event');
|
||||||
break;
|
break;
|
||||||
|
1
examples/gui/data/js/controls.min.js
vendored
Normal file
1
examples/gui/data/js/controls.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
125
examples/gui/data/js/slider.js
Normal file
125
examples/gui/data/js/slider.js
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/* -----------------------------------------------------
|
||||||
|
Material Design Sliders
|
||||||
|
CodePen URL: https://codepen.io/rkchauhan/pen/xVGGpR
|
||||||
|
By: Ravikumar Chauhan
|
||||||
|
-------------------------------------------------------- */
|
||||||
|
function rkmd_rangeSlider(selector) {
|
||||||
|
var self, slider_width, slider_offset, curnt, sliderDiscrete, range, slider;
|
||||||
|
self = $(selector);
|
||||||
|
slider_width = self.width();
|
||||||
|
slider_offset = self.offset().left;
|
||||||
|
sliderDiscrete = self;
|
||||||
|
|
||||||
|
sliderDiscrete.each(function(i, v) {
|
||||||
|
curnt = $(this);
|
||||||
|
curnt.append(sliderDiscrete_tmplt());
|
||||||
|
range = curnt.find('input[type="range"]');
|
||||||
|
slider = curnt.find('.slider');
|
||||||
|
slider_fill = slider.find('.slider-fill');
|
||||||
|
slider_handle = slider.find('.slider-handle');
|
||||||
|
slider_label = slider.find('.slider-label');
|
||||||
|
|
||||||
|
var range_val = parseInt(range.val());
|
||||||
|
slider_fill.css('width', range_val + '%');
|
||||||
|
slider_handle.css('left', range_val + '%');
|
||||||
|
slider_label.find('span').text(range_val);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.on('mousedown touchstart', '.slider-handle', function(e) {
|
||||||
|
if (e.button === 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var parents = $(this).parents('.rkmd-slider');
|
||||||
|
var slider_width = parents.width();
|
||||||
|
var slider_offset = parents.offset().left;
|
||||||
|
var check_range = parents.find('input[type="range"]').is(':disabled');
|
||||||
|
if (check_range === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$(this).addClass('is-active');
|
||||||
|
var moveFu =
|
||||||
|
function(e) {
|
||||||
|
var slider_new_width = e.pageX - slider_offset;
|
||||||
|
|
||||||
|
if (slider_new_width <= slider_width && !(slider_new_width < '0')) {
|
||||||
|
slider_move(parents, slider_new_width, slider_width, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var upFu =
|
||||||
|
function(e) {
|
||||||
|
$(this).off(handlers);
|
||||||
|
parents.find('.is-active').removeClass('is-active');
|
||||||
|
};
|
||||||
|
|
||||||
|
var handlers = {
|
||||||
|
mousemove: moveFu,
|
||||||
|
touchmove: moveFu,
|
||||||
|
mouseup: upFu,
|
||||||
|
touchend: upFu
|
||||||
|
};
|
||||||
|
$(document).on(handlers);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.on('mousedown touchstart', '.slider', function(e) {
|
||||||
|
if (e.button === 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parents = $(this).parents('.rkmd-slider');
|
||||||
|
var slider_width = parents.width();
|
||||||
|
var slider_offset = parents.offset().left;
|
||||||
|
var check_range = parents.find('input[type="range"]').is(':disabled');
|
||||||
|
|
||||||
|
if (check_range === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var slider_new_width = e.pageX - slider_offset;
|
||||||
|
if (slider_new_width <= slider_width && !(slider_new_width < '0')) {
|
||||||
|
slider_move(parents, slider_new_width, slider_width, true);
|
||||||
|
}
|
||||||
|
var upFu =
|
||||||
|
function(e) {
|
||||||
|
$(this).off(handlers);
|
||||||
|
};
|
||||||
|
|
||||||
|
var handlers = {
|
||||||
|
mouseup: upFu,
|
||||||
|
touchend: upFu
|
||||||
|
};
|
||||||
|
$(document).on(handlers);
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function sliderDiscrete_tmplt() {
|
||||||
|
var tmplt = '<div class="slider">' +
|
||||||
|
'<div class="slider-fill"></div>' +
|
||||||
|
'<div class="slider-handle"><div class="slider-label"><span>0</span></div></div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
return tmplt;
|
||||||
|
}
|
||||||
|
|
||||||
|
function slider_move(parents, newW, sliderW, send) {
|
||||||
|
var slider_new_val = parseInt(Math.round(newW / sliderW * 100));
|
||||||
|
|
||||||
|
var slider_fill = parents.find('.slider-fill');
|
||||||
|
var slider_handle = parents.find('.slider-handle');
|
||||||
|
var range = parents.find('input[type="range"]');
|
||||||
|
|
||||||
|
slider_fill.css('width', slider_new_val + '%');
|
||||||
|
slider_handle.css({
|
||||||
|
'left': slider_new_val + '%',
|
||||||
|
'transition': 'none',
|
||||||
|
'-webkit-transition': 'none',
|
||||||
|
'-moz-transition': 'none'
|
||||||
|
});
|
||||||
|
|
||||||
|
range.val(slider_new_val);
|
||||||
|
if (parents.find('.slider-handle span').text() != slider_new_val) {
|
||||||
|
parents.find('.slider-handle span').text(slider_new_val);
|
||||||
|
var number = parents.attr('id').substring(2);
|
||||||
|
if (send) websock.send('slvalue:' + slider_new_val + ':' + number);
|
||||||
|
}
|
||||||
|
}
|
1
examples/gui/data/js/slider.min.js
vendored
Normal file
1
examples/gui/data/js/slider.min.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function rkmd_rangeSlider(b){var f,e,c,a,g,d,h;f=$(b);e=f.width();c=f.offset().left;g=f;g.each(function(k,j){a=$(this);a.append(sliderDiscrete_tmplt());d=a.find('input[type="range"]');h=a.find(".slider");slider_fill=h.find(".slider-fill");slider_handle=h.find(".slider-handle");slider_label=h.find(".slider-label");var l=parseInt(d.val());slider_fill.css("width",l+"%");slider_handle.css("left",l+"%");slider_label.find("span").text(l)});f.on("mousedown touchstart",".slider-handle",function(o){if(o.button===2){return false}var m=$(this).parents(".rkmd-slider");var l=m.width();var i=m.offset().left;var k=m.find('input[type="range"]').is(":disabled");if(k===true){return false}$(this).addClass("is-active");var p=function(r){var q=r.pageX-i;if(q<=l&&!(q<"0")){slider_move(m,q,l,true)}};var n=function(q){$(this).off(j);m.find(".is-active").removeClass("is-active")};var j={mousemove:p,touchmove:p,mouseup:n,touchend:n};$(document).on(j)});f.on("mousedown touchstart",".slider",function(p){if(p.button===2){return false}var m=$(this).parents(".rkmd-slider");var l=m.width();var i=m.offset().left;var k=m.find('input[type="range"]').is(":disabled");if(k===true){return false}var o=p.pageX-i;if(o<=l&&!(o<"0")){slider_move(m,o,l,true)}var n=function(q){$(this).off(j)};var j={mouseup:n,touchend:n};$(document).on(j)})}function sliderDiscrete_tmplt(){var a='<div class="slider"><div class="slider-fill"></div><div class="slider-handle"><div class="slider-label"><span>0</span></div></div></div>';return a}function slider_move(g,a,h,e){var i=parseInt(Math.round(a/h*100));var b=g.find(".slider-fill");var c=g.find(".slider-handle");var f=g.find('input[type="range"]');b.css("width",i+"%");c.css({left:i+"%",transition:"none","-webkit-transition":"none","-moz-transition":"none"});f.val(i);if(g.find(".slider-handle span").text()!=i){g.find(".slider-handle span").text(i);var d=g.attr("id").substring(2);if(e){websock.send("slvalue:"+i+":"+d)}}};
|
@ -1,7 +1,12 @@
|
|||||||
#include <ESPUI.h>
|
#include <ESPUI.h>
|
||||||
#include <WiFi.h>
|
|
||||||
|
|
||||||
const char *ssid = "ESP32";
|
#if defined(ESP32)
|
||||||
|
#include <WiFi.h>
|
||||||
|
#else
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char *ssid = "ESPUI";
|
||||||
const char *password = "";
|
const char *password = "";
|
||||||
|
|
||||||
long oldTime = 0;
|
long oldTime = 0;
|
||||||
@ -10,7 +15,13 @@ bool switchi = false;
|
|||||||
void setup(void) {
|
void setup(void) {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.setHostname(ssid);
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
WiFi.setHostname(ssid);
|
||||||
|
#else
|
||||||
|
WiFi.hostname(ssid);
|
||||||
|
#endif
|
||||||
|
|
||||||
WiFi.softAP(ssid);
|
WiFi.softAP(ssid);
|
||||||
// WiFi.softAP(ssid, password);
|
// WiFi.softAP(ssid, password);
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
@ -40,6 +51,8 @@ void setup(void) {
|
|||||||
ESPUI.pad("Pad without center", false, &padExample, COLOR_CARROT);
|
ESPUI.pad("Pad without center", false, &padExample, COLOR_CARROT);
|
||||||
ESPUI.switcher("Switch one", false, &switchExample, COLOR_ALIZARIN);
|
ESPUI.switcher("Switch one", false, &switchExample, COLOR_ALIZARIN);
|
||||||
ESPUI.switcher("Switch two", true, &otherSwitchExample, COLOR_NONE);
|
ESPUI.switcher("Switch two", true, &otherSwitchExample, COLOR_NONE);
|
||||||
|
ESPUI.slider("Slider one", &slider, COLOR_ALIZARIN, "30");
|
||||||
|
ESPUI.slider("Slider two", &slider, COLOR_NONE, "100");
|
||||||
|
|
||||||
ESPUI.begin("ESP32 Control");
|
ESPUI.begin("ESP32 Control");
|
||||||
}
|
}
|
||||||
@ -53,6 +66,10 @@ void loop(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void slider(Control sender, int type) {
|
||||||
|
Serial.println(sender.value);
|
||||||
|
}
|
||||||
|
|
||||||
void buttonCallback(Control sender, int type) {
|
void buttonCallback(Control sender, int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case B_DOWN:
|
case B_DOWN:
|
||||||
|
9
examples/prepareFilesystem/prepareFilesystem.ino
Normal file
9
examples/prepareFilesystem/prepareFilesystem.ino
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <ESPUI.h>
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
Serial.begin(115200);
|
||||||
|
ESPUI.prepareFileSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
}
|
38
keywords.txt
38
keywords.txt
@ -1,10 +1,48 @@
|
|||||||
|
#######################################
|
||||||
|
# Syntax Coloring Map For ESPUI
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Datatypes (KEYWORD1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
ESPUI KEYWORD1
|
ESPUI KEYWORD1
|
||||||
|
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Methods and Functions (KEYWORD2)
|
||||||
|
#######################################
|
||||||
|
|
||||||
label KEYWORD2
|
label KEYWORD2
|
||||||
button KEYWORD2
|
button KEYWORD2
|
||||||
switcher KEYWORD2
|
switcher KEYWORD2
|
||||||
pad KEYWORD2
|
pad KEYWORD2
|
||||||
|
slider KEYWORD2
|
||||||
|
|
||||||
begin KEYWORD2
|
begin KEYWORD2
|
||||||
print KEYWORD2
|
print KEYWORD2
|
||||||
updateSwitcher KEYWORD2
|
updateSwitcher KEYWORD2
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Instances (KEYWORD2)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Constants (LITERAL1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
B_DOWN LITERAL1
|
||||||
|
B_UP LITERAL1
|
||||||
|
P_LEFT_DOWN LITERAL1
|
||||||
|
P_LEFT_UP LITERAL1
|
||||||
|
P_RIGHT_DOWN LITERAL1
|
||||||
|
P_RIGHT_UP LITERAL1
|
||||||
|
P_FOR_DOWN LITERAL1
|
||||||
|
P_FOR_UP LITERAL1
|
||||||
|
P_BACK_DOWN LITERAL1
|
||||||
|
P_BACK_UP LITERAL1
|
||||||
|
P_CENTER_DOWN LITERAL1
|
||||||
|
P_CENTER_UP LITERAL1
|
||||||
|
S_ACTIVE LITERAL1
|
||||||
|
S_INACTIVE LITERAL1
|
||||||
|
SL_VALUE LITERAL1
|
||||||
|
15
library.json
15
library.json
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ESPUI",
|
|
||||||
"keywords": "ESPUI, esp32, ui, espui, user, interface, gui, iot, arduino, Wifi, server, webinterface, web",
|
|
||||||
"description": "Quickly create an user interface on an ESP32",
|
|
||||||
"repository":
|
|
||||||
{
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/s00500/ESPUI.git"
|
|
||||||
},
|
|
||||||
"frameworks": "arduino",
|
|
||||||
"platforms":
|
|
||||||
[
|
|
||||||
"espressif"
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,9 +1,9 @@
|
|||||||
name=ESPUI
|
name=ESPUI
|
||||||
version=1.2.0
|
version=1.4.0
|
||||||
author=Lukas Bachschwell
|
author=Lukas Bachschwell
|
||||||
maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
|
maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
|
||||||
sentence=ESP32 Web Interface Library
|
sentence=ESP32 and ESP8266 Web Interface Library
|
||||||
paragraph=A simple library that implements a web graphical user interface for ESP32. It is simple to use and works side by side with your sketch.
|
paragraph=A simple library that implements a web graphical user interface for ESP32 and ESP8266. It is simple to use and works side by side with your sketch.
|
||||||
category=Communication
|
category=Communication
|
||||||
url=https://github.com/s00500/ESPUI
|
url=https://github.com/s00500/ESPUI
|
||||||
architectures=*
|
architectures=*
|
||||||
|
178
src/ESPUI.cpp
178
src/ESPUI.cpp
@ -1,7 +1,85 @@
|
|||||||
#include "ESPUI.h"
|
#include "ESPUI.h"
|
||||||
|
|
||||||
|
#include "uploadDataIndex.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "uploadDataStyle.h"
|
||||||
|
#include "uploadDataNormalize.h"
|
||||||
|
|
||||||
|
#include "uploadDataControls.h"
|
||||||
|
#include "uploadDataZepto.h"
|
||||||
|
#include "uploadDataSlider.h"
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
// ################# Spiffs functions
|
||||||
|
void deleteFile(fs::FS &fs, const char * path){
|
||||||
|
if(!fs.exists(path)){
|
||||||
|
Serial.printf("File: %s does not exist, not deleting\n", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.printf("Deleting file: %s\n", path);
|
||||||
|
|
||||||
|
if(fs.remove(path)){
|
||||||
|
Serial.println("File deleted");
|
||||||
|
} else {
|
||||||
|
Serial.println("Delete failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeFile(fs::FS &fs, const char * path, const char * data){
|
||||||
|
Serial.printf("Writing file: %s\n", path);
|
||||||
|
|
||||||
|
File file = fs.open(path, FILE_WRITE);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("Failed to open file for writing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(FPSTR(data))){
|
||||||
|
Serial.println("File written");
|
||||||
|
} else {
|
||||||
|
Serial.println("Write failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// end Spiffs functions
|
||||||
|
|
||||||
|
void ESPUIClass::prepareFileSystem(){
|
||||||
|
// this function should only be used once
|
||||||
|
|
||||||
|
Serial.println('About to prepare filesystem...');
|
||||||
|
if(!SPIFFS.begin()) {
|
||||||
|
Serial.println("SPIFFS Mount Failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteFile(SPIFFS, "/index.htm");
|
||||||
|
|
||||||
|
deleteFile(SPIFFS, "/css/style.css");
|
||||||
|
deleteFile(SPIFFS, "/css/normalize.css");
|
||||||
|
|
||||||
|
deleteFile(SPIFFS, "/js/controls.js");
|
||||||
|
deleteFile(SPIFFS, "/js/zepto.js");
|
||||||
|
deleteFile(SPIFFS, "/js/slider.js");
|
||||||
|
|
||||||
|
Serial.println('Cleanup done');
|
||||||
|
|
||||||
|
// Now write
|
||||||
|
writeFile(SPIFFS, "/index.htm", HTML_INDEX);
|
||||||
|
|
||||||
|
writeFile(SPIFFS, "/css/style.css", CSS_STYLE);
|
||||||
|
writeFile(SPIFFS, "/css/normalize.css", CSS_NORMALIZE);
|
||||||
|
|
||||||
|
writeFile(SPIFFS, "/js/zepto.js", JS_ZEPTO);
|
||||||
|
writeFile(SPIFFS, "/js/controls.js", JS_CONTROLS);
|
||||||
|
writeFile(SPIFFS, "/js/slider.js", JS_SLIDER);
|
||||||
|
|
||||||
|
Serial.println("Done Initializing filesystem :-)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle Websockets Communication
|
// Handle Websockets Communication
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
|
||||||
AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||||
@ -22,50 +100,47 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
|
|||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
msg += (char)data[i];
|
msg += (char)data[i];
|
||||||
}
|
}
|
||||||
|
int id = msg.substring(msg.lastIndexOf(':') + 1).toInt();
|
||||||
|
if (id >= ESPUI.cIndex){
|
||||||
|
if(debug) Serial.println("Maleformated id in websocket message");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Control *c = ESPUI.controls[msg.substring(msg.lastIndexOf(':') + 1).toInt()];
|
||||||
|
|
||||||
if (msg.startsWith("bdown:")) {
|
if (msg.startsWith("bdown:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(6).toInt()];
|
|
||||||
c->callback(*c, B_DOWN);
|
c->callback(*c, B_DOWN);
|
||||||
} else if (msg.startsWith("bup:")) {
|
} else if (msg.startsWith("bup:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(4).toInt()];
|
|
||||||
c->callback(*c, B_UP);
|
c->callback(*c, B_UP);
|
||||||
} else if (msg.startsWith("pfdown:")) {
|
} else if (msg.startsWith("pfdown:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(7).toInt()];
|
|
||||||
c->callback(*c, P_FOR_DOWN);
|
c->callback(*c, P_FOR_DOWN);
|
||||||
} else if (msg.startsWith("pfup:")) {
|
} else if (msg.startsWith("pfup:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(5).toInt()];
|
|
||||||
c->callback(*c, P_FOR_UP);
|
c->callback(*c, P_FOR_UP);
|
||||||
} else if (msg.startsWith("pldown:")) {
|
} else if (msg.startsWith("pldown:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(7).toInt()];
|
|
||||||
c->callback(*c, P_LEFT_DOWN);
|
c->callback(*c, P_LEFT_DOWN);
|
||||||
} else if (msg.startsWith("plup:")) {
|
} else if (msg.startsWith("plup:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(5).toInt()];
|
|
||||||
c->callback(*c, P_LEFT_UP);
|
c->callback(*c, P_LEFT_UP);
|
||||||
} else if (msg.startsWith("prdown:")) {
|
} else if (msg.startsWith("prdown:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(7).toInt()];
|
|
||||||
c->callback(*c, P_RIGHT_DOWN);
|
c->callback(*c, P_RIGHT_DOWN);
|
||||||
} else if (msg.startsWith("prup:")) {
|
} else if (msg.startsWith("prup:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(5).toInt()];
|
|
||||||
c->callback(*c, P_RIGHT_UP);
|
c->callback(*c, P_RIGHT_UP);
|
||||||
} else if (msg.startsWith("pbdown:")) {
|
} else if (msg.startsWith("pbdown:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(7).toInt()];
|
|
||||||
c->callback(*c, P_BACK_DOWN);
|
c->callback(*c, P_BACK_DOWN);
|
||||||
} else if (msg.startsWith("pbup:")) {
|
} else if (msg.startsWith("pbup:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(5).toInt()];
|
|
||||||
c->callback(*c, P_BACK_UP);
|
c->callback(*c, P_BACK_UP);
|
||||||
} else if (msg.startsWith("pcdown:")) {
|
} else if (msg.startsWith("pcdown:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(7).toInt()];
|
|
||||||
c->callback(*c, P_CENTER_DOWN);
|
c->callback(*c, P_CENTER_DOWN);
|
||||||
} else if (msg.startsWith("pcup:")) {
|
} else if (msg.startsWith("pcup:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(5).toInt()];
|
|
||||||
c->callback(*c, P_CENTER_UP);
|
c->callback(*c, P_CENTER_UP);
|
||||||
} else if (msg.startsWith("sactive:")) {
|
} else if (msg.startsWith("sactive:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(8).toInt()];
|
|
||||||
ESPUI.updateSwitcher(c->id, true);
|
ESPUI.updateSwitcher(c->id, true);
|
||||||
c->callback(*c, S_ACTIVE);
|
c->callback(*c, S_ACTIVE);
|
||||||
} else if (msg.startsWith("sinactive:")) {
|
} else if (msg.startsWith("sinactive:")) {
|
||||||
Control *c = ESPUI.controls[msg.substring(10).toInt()];
|
|
||||||
ESPUI.updateSwitcher(c->id, false);
|
ESPUI.updateSwitcher(c->id, false);
|
||||||
c->callback(*c, S_INACTIVE);
|
c->callback(*c, S_INACTIVE);
|
||||||
|
} else if (msg.startsWith("slvalue:")) {
|
||||||
|
int value = msg.substring(msg.indexOf(':') + 1, msg.lastIndexOf(':')).toInt();
|
||||||
|
ESPUI.updateSlider(c->id, value, client->id());
|
||||||
|
c->callback(*c, SL_VALUE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -93,6 +168,29 @@ void ESPUIClass::label(const char *label, int color, String value) {
|
|||||||
cIndex++;
|
cIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this still needs a range setting
|
||||||
|
void ESPUIClass::slider(const char *label, void (*callBack)(Control, int), int color, String value) {
|
||||||
|
if (labelExists(label)) {
|
||||||
|
if (debug)
|
||||||
|
Serial.println("UI ERROR: Element " + String(label) +
|
||||||
|
" exists, skipping creating element!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Control *newSL = new Control();
|
||||||
|
newSL->type = UI_SLIDER;
|
||||||
|
newSL->label = label;
|
||||||
|
newSL->color = color;
|
||||||
|
if (value != "")
|
||||||
|
newSL->value = value;
|
||||||
|
else
|
||||||
|
newSL->value = ""; // TODO: init with half value
|
||||||
|
newSL->callback = callBack;
|
||||||
|
newSL->id = cIndex;
|
||||||
|
controls[cIndex] = newSL;
|
||||||
|
cIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
void ESPUIClass::button(const char *label, void (*callBack)(Control, int),
|
void ESPUIClass::button(const char *label, void (*callBack)(Control, int),
|
||||||
int color, String value) {
|
int color, String value) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
@ -187,17 +285,17 @@ void ESPUIClass::print(String label, String value) {
|
|||||||
print(getIdByLabel(label), value);
|
print(getIdByLabel(label), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::updateSwitcher(int id, bool nValue) {
|
void ESPUIClass::updateSwitcher(int id, bool nValue, int clientId ) {
|
||||||
if (id < cIndex && controls[id]->type == UI_SWITCHER) {
|
if (id < cIndex && controls[id]->type == UI_SWITCHER) {
|
||||||
controls[id]->value = nValue ? 1 : 0;
|
controls[id]->value = nValue ? 1 : 0;
|
||||||
String json;
|
String json;
|
||||||
StaticJsonBuffer<200> jsonBuffer;
|
StaticJsonBuffer<200> jsonBuffer;
|
||||||
JsonObject &root = jsonBuffer.createObject();
|
JsonObject &root = jsonBuffer.createObject();
|
||||||
root["type"] = UPDATE_SWITCH;
|
root["type"] = UPDATE_SWITCHER;
|
||||||
root["value"] = nValue ? 1 : 0;
|
root["value"] = nValue ? 1 : 0;
|
||||||
root["id"] = String(id);
|
root["id"] = String(id);
|
||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
this->ws->textAll(json);
|
textThem(json, clientId);
|
||||||
} else {
|
} else {
|
||||||
if (debug)
|
if (debug)
|
||||||
Serial.println(String("Error: ") + String(id) +
|
Serial.println(String("Error: ") + String(id) +
|
||||||
@ -205,14 +303,40 @@ void ESPUIClass::updateSwitcher(int id, bool nValue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::updateSwitcher(String label, bool nValue) {
|
void ESPUIClass::updateSlider(int id, int nValue, int clientId ) {
|
||||||
|
if (id < cIndex && controls[id]->type == UI_SLIDER) {
|
||||||
|
controls[id]->value = nValue;
|
||||||
|
String json;
|
||||||
|
StaticJsonBuffer<200> jsonBuffer;
|
||||||
|
JsonObject &root = jsonBuffer.createObject();
|
||||||
|
root["type"] = UPDATE_SLIDER;
|
||||||
|
root["value"] = nValue;
|
||||||
|
root["id"] = String(id);
|
||||||
|
root.printTo(json);
|
||||||
|
textThem(json, clientId);
|
||||||
|
} else {
|
||||||
|
if (debug)
|
||||||
|
Serial.println(String("Error: ") + String(id) +
|
||||||
|
String(" is no slider"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ESPUIClass::updateSwitcher(String label, bool nValue, int clientId) {
|
||||||
if (!labelExists(label)) {
|
if (!labelExists(label)) {
|
||||||
if (debug)
|
if (debug)
|
||||||
Serial.println("UI ERROR: Element does not " + String(label) +
|
Serial.println("UI ERROR: Element does not " + String(label) +
|
||||||
" exist, cannot update!");
|
" exist, cannot update!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateSwitcher(getIdByLabel(label), nValue);
|
updateSwitcher(getIdByLabel(label), nValue, clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ESPUIClass::textThem(String text, int clientId){
|
||||||
|
for(int i = 1; i <= this->ws->count(); i++){
|
||||||
|
if(clientId!=i){
|
||||||
|
this->ws->client(i)->text(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESPUIClass::getIdByLabel(String label) {
|
int ESPUIClass::getIdByLabel(String label) {
|
||||||
@ -253,10 +377,20 @@ void ESPUIClass::jsonDom(AsyncWebSocketClient *client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::begin(const char *_title) {
|
void ESPUIClass::begin(const char *_title) {
|
||||||
|
|
||||||
ui_title = _title;
|
ui_title = _title;
|
||||||
server = new AsyncWebServer(80);
|
server = new AsyncWebServer(80);
|
||||||
ws = new AsyncWebSocket("/ws");
|
ws = new AsyncWebSocket("/ws");
|
||||||
SPIFFS.begin();
|
if(!SPIFFS.begin()) {
|
||||||
|
Serial.println("SPIFFS Mount Failed, PLEASE CHECK THE README ON HOW TO PREPARE YOUR ESP!!!!!!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!SPIFFS.exists( "/index.htm")) {
|
||||||
|
Serial.println("Please read the README!!!!!!!, Make sure to ESPUI.prepareFileSystem() once in an empty sketch");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ws->onEvent(onWsEvent);
|
ws->onEvent(onWsEvent);
|
||||||
server->addHandler(ws);
|
server->addHandler(ws);
|
||||||
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
|
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
|
||||||
@ -267,7 +401,9 @@ void ESPUIClass::begin(const char *_title) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server->onNotFound(
|
server->onNotFound(
|
||||||
[](AsyncWebServerRequest *request) { request->send(404); });
|
[](AsyncWebServerRequest *request) {
|
||||||
|
request->send(404);
|
||||||
|
});
|
||||||
|
|
||||||
server->begin();
|
server->begin();
|
||||||
if (debug)
|
if (debug)
|
||||||
|
45
src/ESPUI.h
45
src/ESPUI.h
@ -1,23 +1,35 @@
|
|||||||
#ifndef ESPUI_h
|
#ifndef ESPUI_h
|
||||||
#define ESPUI_h
|
#define ESPUI_h
|
||||||
|
|
||||||
#define HARDWARE "esp32"
|
|
||||||
|
|
||||||
#define debug true
|
#define debug true
|
||||||
|
|
||||||
// ifdef 8266
|
|
||||||
//#include "Hash.h"
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#include "SPIFFS.h"
|
|
||||||
#include "WiFi.h"
|
|
||||||
#include "stdlib_noniso.h"
|
#include "stdlib_noniso.h"
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
|
||||||
|
#include "SPIFFS.h"
|
||||||
|
#include "WiFi.h"
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
|
#include <FS.h>
|
||||||
|
#include <Hash.h>
|
||||||
|
#include <ESPAsyncTCP.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <SPIFFSEditor.h>
|
||||||
|
|
||||||
|
#define FILE_WRITE "w"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct Control {
|
typedef struct Control {
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
unsigned int id; // just mirroring the id here for practical reasons
|
unsigned int id; // just mirroring the id here for practical reasons
|
||||||
@ -35,7 +47,9 @@ typedef struct Control {
|
|||||||
#define UI_PAD 4
|
#define UI_PAD 4
|
||||||
#define UI_CPAD 5
|
#define UI_CPAD 5
|
||||||
#define UPDATE_LABEL 6
|
#define UPDATE_LABEL 6
|
||||||
#define UPDATE_SWITCH 7
|
#define UPDATE_SWITCHER 7
|
||||||
|
#define UI_SLIDER 8
|
||||||
|
#define UPDATE_SLIDER 9
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
#define B_DOWN -1
|
#define B_DOWN -1
|
||||||
@ -51,9 +65,12 @@ typedef struct Control {
|
|||||||
#define P_BACK_UP 5
|
#define P_BACK_UP 5
|
||||||
#define P_CENTER_DOWN -6
|
#define P_CENTER_DOWN -6
|
||||||
#define P_CENTER_UP 6
|
#define P_CENTER_UP 6
|
||||||
|
|
||||||
#define S_ACTIVE -7
|
#define S_ACTIVE -7
|
||||||
#define S_INACTIVE 7
|
#define S_INACTIVE 7
|
||||||
|
|
||||||
|
#define SL_VALUE 8
|
||||||
|
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
#define COLOR_TURQUOISE 0
|
#define COLOR_TURQUOISE 0
|
||||||
@ -71,6 +88,8 @@ class ESPUIClass {
|
|||||||
public:
|
public:
|
||||||
void begin(const char *_title); // Setup servers and page
|
void begin(const char *_title); // Setup servers and page
|
||||||
|
|
||||||
|
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS
|
||||||
|
|
||||||
// Creating Elements
|
// Creating Elements
|
||||||
void label(const char *label, int color, String value = ""); // Create Label
|
void label(const char *label, int color, String value = ""); // Create Label
|
||||||
void button(const char *label, void (*callBack)(Control, int), int color,
|
void button(const char *label, void (*callBack)(Control, int), int color,
|
||||||
@ -80,13 +99,19 @@ public:
|
|||||||
int color); // Create Toggle Button
|
int color); // Create Toggle Button
|
||||||
void pad(const char *label, bool centerButton, void (*callBack)(Control, int),
|
void pad(const char *label, bool centerButton, void (*callBack)(Control, int),
|
||||||
int color); // Create Pad Control
|
int color); // Create Pad Control
|
||||||
|
void slider(const char *label, void (*callBack)(Control, int), int color, String value); // Create Slider Control
|
||||||
|
|
||||||
// Update Elements
|
// Update Elements
|
||||||
void print(int id, String value);
|
void print(int id, String value);
|
||||||
void print(String label, String value);
|
void print(String label, String value);
|
||||||
|
|
||||||
void updateSwitcher(int id, bool nValue);
|
void updateSwitcher(int id, bool nValue, int clientId = -1);
|
||||||
void updateSwitcher(String label, bool nValue);
|
void updateSwitcher(String label, bool nValue, int clientId = -1);
|
||||||
|
|
||||||
|
void updateSlider(int id, int nValue, int clientId = -1);
|
||||||
|
void updateSlider(String label, int nValue, int clientId = -1);
|
||||||
|
|
||||||
|
void textThem(String text, int clientId);
|
||||||
|
|
||||||
// Variables ---
|
// Variables ---
|
||||||
const char *ui_title = "ESPUI"; // Store UI Title and Header Name
|
const char *ui_title = "ESPUI"; // Store UI Title and Header Name
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
const char INDEX[] PROGMEM = R"=====(
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
</html>
|
|
||||||
)=====";
|
|
||||||
|
|
||||||
const char CSS_NORMALIZE[] PROGMEM = R"=====(
|
|
||||||
<style></style>
|
|
||||||
)=====";
|
|
||||||
|
|
||||||
const char CSS_STYLE[] PROGMEM = R"=====(
|
|
||||||
<style></style>
|
|
||||||
)=====";
|
|
||||||
|
|
||||||
const char JS_ZEPTO[] PROGMEM = R"=====(
|
|
||||||
<script></script>
|
|
||||||
)=====";
|
|
||||||
|
|
||||||
const char JS_CONTROLS[] PROGMEM = R"=====(
|
|
||||||
<script></script>
|
|
||||||
)=====";
|
|
3
src/uploadDataControls.h
Normal file
3
src/uploadDataControls.h
Normal file
File diff suppressed because one or more lines are too long
27
src/uploadDataIndex.h
Normal file
27
src/uploadDataIndex.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
const char HTML_INDEX[] PROGMEM = R"=====(
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Control</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAPFBMVEUAAACA1VWR21qQ2liR3FqR3FqS3VuR3VqR3VuR3VqO21mS21uS3FqS3FqS21uJ2GKQ21qR3FuR3FoAAAB/3Gu7AAAAEnRSTlMABoA3kPBwz8i5Kzioxg4NVcU3uEJHAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAAN1wAADdcBQiibeAAAAAd0SU1FB+EFEhcEM+HpYwQAAABYSURBVBjThY/JDsAgCESt4lpX/v9jLQZJ6qF9t3khAyj1xXUKbQ4BVowDwqOYgExkkW4iY6lPaF06RqM8YItOuRbMaz6xjbsusDAW/drplBg47jP696cXE8bPA1eUDeK2AAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE3LTA1LTE4VDIzOjA0OjUxKzAyOjAwxE59ewAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNy0wNS0xOFQyMzowNDo1MSswMjowMLUTxccAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC"
|
||||||
|
/>
|
||||||
|
<link rel="stylesheet" href="/css/normalize.css">
|
||||||
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
|
|
||||||
|
<script src="/js/zepto.js"></script>
|
||||||
|
<script src="/js/slider.js"></script>
|
||||||
|
<script src="/js/controls.js"></script>
|
||||||
|
</head>
|
||||||
|
<body onload="javascript:start();">
|
||||||
|
<div>
|
||||||
|
<h4><div id="mainHeader">Control</div> <span id="conStatus" class="label">Offline</span></h4></div>
|
||||||
|
<hr />
|
||||||
|
<div class="container">
|
||||||
|
<div id="row" class="row u-full-width">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)=====";
|
3
src/uploadDataNormalize.h
Normal file
3
src/uploadDataNormalize.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const char CSS_NORMALIZE[] PROGMEM = R"=====(
|
||||||
|
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}
|
||||||
|
)=====";
|
3
src/uploadDataSlider.h
Normal file
3
src/uploadDataSlider.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const char JS_SLIDER[] PROGMEM = R"=====(
|
||||||
|
function rkmd_rangeSlider(b){var f,e,c,a,g,d,h;f=$(b);e=f.width();c=f.offset().left;g=f;g.each(function(k,j){a=$(this);a.append(sliderDiscrete_tmplt());d=a.find('input[type="range"]');h=a.find(".slider");slider_fill=h.find(".slider-fill");slider_handle=h.find(".slider-handle");slider_label=h.find(".slider-label");var l=parseInt(d.val());slider_fill.css("width",l+"%");slider_handle.css("left",l+"%");slider_label.find("span").text(l)});f.on("mousedown touchstart",".slider-handle",function(o){if(o.button===2){return false}var m=$(this).parents(".rkmd-slider");var l=m.width();var i=m.offset().left;var k=m.find('input[type="range"]').is(":disabled");if(k===true){return false}$(this).addClass("is-active");var p=function(r){var q=r.pageX-i;if(q<=l&&!(q<"0")){slider_move(m,q,l,true)}};var n=function(q){$(this).off(j);m.find(".is-active").removeClass("is-active")};var j={mousemove:p,touchmove:p,mouseup:n,touchend:n};$(document).on(j)});f.on("mousedown touchstart",".slider",function(p){if(p.button===2){return false}var m=$(this).parents(".rkmd-slider");var l=m.width();var i=m.offset().left;var k=m.find('input[type="range"]').is(":disabled");if(k===true){return false}var o=p.pageX-i;if(o<=l&&!(o<"0")){slider_move(m,o,l,true)}var n=function(q){$(this).off(j)};var j={mouseup:n,touchend:n};$(document).on(j)})}function sliderDiscrete_tmplt(){var a='<div class="slider"><div class="slider-fill"></div><div class="slider-handle"><div class="slider-label"><span>0</span></div></div></div>';return a}function slider_move(g,a,h,e){var i=parseInt(Math.round(a/h*100));var b=g.find(".slider-fill");var c=g.find(".slider-handle");var f=g.find('input[type="range"]');b.css("width",i+"%");c.css({left:i+"%",transition:"none","-webkit-transition":"none","-moz-transition":"none"});f.val(i);if(g.find(".slider-handle span").text()!=i){g.find(".slider-handle span").text(i);var d=g.attr("id").substring(2);if(e){websock.send("slvalue:"+i+":"+d)}}};
|
||||||
|
)=====";
|
3
src/uploadDataStyle.h
Normal file
3
src/uploadDataStyle.h
Normal file
File diff suppressed because one or more lines are too long
4
src/uploadDataZepto.h
Normal file
4
src/uploadDataZepto.h
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user