mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-21 17:40:54 +00:00
Make stuff work and efficient
This commit is contained in:
parent
994eff2b6d
commit
ccc1286c56
@ -1,250 +0,0 @@
|
||||
const char CSS_NORMALIZE[] PROGMEM = R"=====(
|
||||
|
||||
html {
|
||||
font-family: sans-serif; /* 1 */
|
||||
-ms-text-size-adjust: 100%; /* 2 */
|
||||
-webkit-text-size-adjust: 100%; /* 2 */
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* HTML5 display definitions
|
||||
========================================================================== */
|
||||
|
||||
article,
|
||||
aside,
|
||||
details,
|
||||
figcaption,
|
||||
figure,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
main,
|
||||
menu,
|
||||
nav,
|
||||
section,
|
||||
summary {
|
||||
display: block;
|
||||
}
|
||||
|
||||
audio,
|
||||
canvas,
|
||||
progress,
|
||||
video {
|
||||
display: inline-block; /* 1 */
|
||||
vertical-align: baseline; /* 2 */
|
||||
}
|
||||
|
||||
audio:not([controls]) {
|
||||
display: none;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
[hidden],
|
||||
template {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Links
|
||||
========================================================================== */
|
||||
|
||||
a {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
a:active,
|
||||
a:hover {
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
/* Text-level semantics
|
||||
========================================================================== */
|
||||
|
||||
abbr[title] {
|
||||
border-bottom: 1px dotted;
|
||||
}
|
||||
|
||||
b,
|
||||
strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
dfn {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2em;
|
||||
margin: 0.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;
|
||||
}
|
||||
|
||||
/* Embedded content
|
||||
========================================================================== */
|
||||
|
||||
img {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
svg:not(:root) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Grouping content
|
||||
========================================================================== */
|
||||
|
||||
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; /* 1 */
|
||||
font: inherit; /* 2 */
|
||||
margin: 0; /* 3 */
|
||||
}
|
||||
|
||||
button {
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
button,
|
||||
select {
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
button,
|
||||
html input[type="button"], /* 1 */
|
||||
input[type="reset"],
|
||||
input[type="submit"] {
|
||||
-webkit-appearance: button; /* 2 */
|
||||
cursor: pointer; /* 3 */
|
||||
}
|
||||
|
||||
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; /* 1 */
|
||||
padding: 0; /* 2 */
|
||||
}
|
||||
|
||||
input[type="number"]::-webkit-inner-spin-button,
|
||||
input[type="number"]::-webkit-outer-spin-button {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
input[type="search"] {
|
||||
-webkit-appearance: textfield; /* 1 */
|
||||
-moz-box-sizing: content-box;
|
||||
-webkit-box-sizing: content-box; /* 2 */
|
||||
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: 0.35em 0.625em 0.75em;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Correct `color` not being inherited in IE 8/9/10/11.
|
||||
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
|
||||
*/
|
||||
|
||||
legend {
|
||||
border: 0; /* 1 */
|
||||
padding: 0; /* 2 */
|
||||
}
|
||||
|
||||
textarea {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't inherit the `font-weight` (applied by a rule above).
|
||||
* NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
|
||||
*/
|
||||
|
||||
optgroup {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Tables
|
||||
========================================================================== */
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
td,
|
||||
th {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
)=====";
|
402
src/CSS_STYLE.h
402
src/CSS_STYLE.h
@ -1,402 +0,0 @@
|
||||
const char CSS_STYLE[] PROGMEM = R"=====(
|
||||
body{
|
||||
background-color: #F4F3EF;
|
||||
}
|
||||
.container {
|
||||
position: relative;
|
||||
width: 79%;
|
||||
margin: 20px;
|
||||
box-sizing: border-box; }
|
||||
.column,
|
||||
.columns {
|
||||
width: 100%;
|
||||
float: left; }
|
||||
|
||||
.card{
|
||||
margin-top: 2%;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 2px rgba(204, 197, 185, 0.5);
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
margin-bottom: 10px;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.label {
|
||||
box-sizing: border-box;
|
||||
white-space: nowrap;
|
||||
border-radius: 0.2em;
|
||||
padding: 0.12em 0.4em 0.14em;
|
||||
text-align: center;
|
||||
color: #ffffff;
|
||||
font-size: 0.75em;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
display: inline;
|
||||
white-space: nowrap;
|
||||
vertical-align: baseline;
|
||||
position: relative;
|
||||
top: -0.15em;
|
||||
background-color: #999999; }
|
||||
|
||||
.label { ... }
|
||||
|
||||
.label.color-blue { background-color: #6f9ad1; }
|
||||
.label.color-red { background-color: #d37c7c; }
|
||||
.label.color-green { background-color: #9bc268; }
|
||||
.label.color-orange { background-color: #dea154; }
|
||||
.label.color-yellow { background-color: #e9d641; }
|
||||
.label.color-purple { background-color: #9f83d1; }
|
||||
|
||||
/* For devices larger than 400px */
|
||||
@media (min-width: 400px) {
|
||||
.container {
|
||||
width: 84%;}
|
||||
|
||||
}
|
||||
|
||||
/* For devices larger than 550px */
|
||||
@media (min-width: 630px) {
|
||||
.container {
|
||||
width: 98%; }
|
||||
.column,
|
||||
.columns {
|
||||
margin-right: 2%; }
|
||||
.column:first-child,
|
||||
.columns:first-child {
|
||||
margin-left: 0; }
|
||||
|
||||
.one.column,
|
||||
.one.columns { width: 4.66666666667%; }
|
||||
.two.columns { width: 13.3333333333%; }
|
||||
.three.columns { width: 22%; }
|
||||
.four.columns { width: 30.6666666667%; }
|
||||
.five.columns { width: 39.3333333333%; }
|
||||
.six.columns { width: 48%; }
|
||||
.seven.columns { width: 56.6666666667%; }
|
||||
.eight.columns { width: 65.3333333333%; }
|
||||
.nine.columns { width: 74.0%; }
|
||||
.ten.columns { width: 82.6666666667%; }
|
||||
.eleven.columns { width: 91.3333333333%; }
|
||||
.twelve.columns { width: 100%; margin-left: 0; }
|
||||
|
||||
.one-third.column { width: 30.6666666667%; }
|
||||
.two-thirds.column { width: 65.3333333333%; }
|
||||
|
||||
.one-half.column { width: 48%; }
|
||||
|
||||
/* Offsets */
|
||||
.offset-by-one.column,
|
||||
.offset-by-one.columns { margin-left: 8.66666666667%; }
|
||||
.offset-by-two.column,
|
||||
.offset-by-two.columns { margin-left: 17.3333333333%; }
|
||||
.offset-by-three.column,
|
||||
.offset-by-three.columns { margin-left: 26%; }
|
||||
.offset-by-four.column,
|
||||
.offset-by-four.columns { margin-left: 34.6666666667%; }
|
||||
.offset-by-five.column,
|
||||
.offset-by-five.columns { margin-left: 43.3333333333%; }
|
||||
.offset-by-six.column,
|
||||
.offset-by-six.columns { margin-left: 52%; }
|
||||
.offset-by-seven.column,
|
||||
.offset-by-seven.columns { margin-left: 60.6666666667%; }
|
||||
.offset-by-eight.column,
|
||||
.offset-by-eight.columns { margin-left: 69.3333333333%; }
|
||||
.offset-by-nine.column,
|
||||
.offset-by-nine.columns { margin-left: 78.0%; }
|
||||
.offset-by-ten.column,
|
||||
.offset-by-ten.columns { margin-left: 86.6666666667%; }
|
||||
.offset-by-eleven.column,
|
||||
.offset-by-eleven.columns { margin-left: 95.3333333333%; }
|
||||
|
||||
.offset-by-one-third.column,
|
||||
.offset-by-one-third.columns { margin-left: 34.6666666667%; }
|
||||
.offset-by-two-thirds.column,
|
||||
.offset-by-two-thirds.columns { margin-left: 69.3333333333%; }
|
||||
|
||||
.offset-by-one-half.column,
|
||||
.offset-by-one-half.columns { margin-left: 52%; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Base Styles
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
/* NOTE
|
||||
html is set to 62.5% so that all the REM measurements throughout Skeleton
|
||||
are based on 10px sizing. So basically 1.5rem = 15px :) */
|
||||
html {
|
||||
font-size: 62.5%; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-size: 1.5em; /* currently ems cause chrome bug misinterpreting rems on body element */
|
||||
line-height: 1.0;
|
||||
font-weight: 400;
|
||||
font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
color: #222; }
|
||||
|
||||
|
||||
/* Typography
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 300; }
|
||||
h1 { font-size: 4.0rem; line-height: 1.2; letter-spacing: -.1rem;}
|
||||
h2 { font-size: 3.6rem; line-height: 1.25; letter-spacing: -.1rem; }
|
||||
h3 { font-size: 3.0rem; line-height: 1.3; letter-spacing: -.1rem; }
|
||||
h4 { font-size: 2.4rem; line-height: 1.35; letter-spacing: -.08rem; }
|
||||
h5 { font-size: 1.8rem; line-height: 1.5; letter-spacing: -.05rem; }
|
||||
h6 { font-size: 1.5rem; line-height: 1.6; letter-spacing: 0; }
|
||||
|
||||
/* Larger than phablet */
|
||||
@media (min-width: 630px) {
|
||||
h1 { font-size: 5.0rem; }
|
||||
h2 { font-size: 4.2rem; }
|
||||
h3 { font-size: 3.6rem; }
|
||||
h4 { font-size: 3.0rem; }
|
||||
h5 { font-size: 2.0rem; }
|
||||
h6 { font-size: 1.5rem; }
|
||||
}
|
||||
|
||||
p {
|
||||
margin-top: 0; }
|
||||
|
||||
|
||||
/* Links
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
a {
|
||||
color: #1EAEDB; }
|
||||
a:hover {
|
||||
color: #0FA0CE; }
|
||||
|
||||
|
||||
/* Buttons
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
.button,
|
||||
button,
|
||||
input[type="submit"],
|
||||
input[type="reset"],
|
||||
input[type="button"] {
|
||||
display: inline-block;
|
||||
height: 38px;
|
||||
padding: 0 30px;
|
||||
color: #555;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
line-height: 38px;
|
||||
letter-spacing: .1rem;
|
||||
text-transform: uppercase;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
background-color: transparent;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #bbb;
|
||||
cursor: pointer;
|
||||
box-sizing: border-box; }
|
||||
.button:hover,
|
||||
button:hover,
|
||||
input[type="submit"]:hover,
|
||||
input[type="reset"]:hover,
|
||||
input[type="button"]:hover,
|
||||
.button:focus,
|
||||
button:focus,
|
||||
input[type="submit"]:focus,
|
||||
input[type="reset"]:focus,
|
||||
input[type="button"]:focus {
|
||||
color: #333;
|
||||
border-color: #888;
|
||||
outline: 0; }
|
||||
.button.button-primary,
|
||||
button.button-primary,
|
||||
input[type="submit"].button-primary,
|
||||
input[type="reset"].button-primary,
|
||||
input[type="button"].button-primary {
|
||||
color: #FFF;
|
||||
background-color: #33C3F0;
|
||||
border-color: #33C3F0; }
|
||||
.button.button-primary:hover,
|
||||
button.button-primary:hover,
|
||||
input[type="submit"].button-primary:hover,
|
||||
input[type="reset"].button-primary:hover,
|
||||
input[type="button"].button-primary:hover,
|
||||
.button.button-primary:focus,
|
||||
button.button-primary:focus,
|
||||
input[type="submit"].button-primary:focus,
|
||||
input[type="reset"].button-primary:focus,
|
||||
input[type="button"].button-primary:focus {
|
||||
color: #FFF;
|
||||
background-color: #1EAEDB;
|
||||
border-color: #1EAEDB; }
|
||||
|
||||
|
||||
/* Forms
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
input[type="email"],
|
||||
input[type="number"],
|
||||
input[type="search"],
|
||||
input[type="text"],
|
||||
input[type="tel"],
|
||||
input[type="url"],
|
||||
input[type="password"],
|
||||
textarea,
|
||||
select {
|
||||
height: 38px;
|
||||
padding: 6px 10px; /* The 6px vertically centers text on FF, ignored by Webkit */
|
||||
background-color: #fff;
|
||||
border: 1px solid #D1D1D1;
|
||||
border-radius: 4px;
|
||||
box-shadow: none;
|
||||
box-sizing: border-box; }
|
||||
/* Removes awkward default styles on some inputs for iOS */
|
||||
input[type="email"],
|
||||
input[type="number"],
|
||||
input[type="search"],
|
||||
input[type="text"],
|
||||
input[type="tel"],
|
||||
input[type="url"],
|
||||
input[type="password"],
|
||||
textarea {
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none; }
|
||||
textarea {
|
||||
min-height: 65px;
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px; }
|
||||
input[type="email"]:focus,
|
||||
input[type="number"]:focus,
|
||||
input[type="search"]:focus,
|
||||
input[type="text"]:focus,
|
||||
input[type="tel"]:focus,
|
||||
input[type="url"]:focus,
|
||||
input[type="password"]:focus,
|
||||
textarea:focus,
|
||||
select:focus {
|
||||
border: 1px solid #33C3F0;
|
||||
outline: 0; }
|
||||
label,
|
||||
legend {
|
||||
display: block;
|
||||
margin-bottom: .5rem;
|
||||
font-weight: 600; }
|
||||
fieldset {
|
||||
padding: 0;
|
||||
border-width: 0; }
|
||||
input[type="checkbox"],
|
||||
input[type="radio"] {
|
||||
display: inline; }
|
||||
label > .label-body {
|
||||
display: inline-block;
|
||||
margin-left: .5rem;
|
||||
font-weight: normal; }
|
||||
|
||||
|
||||
/* Lists
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
ul {
|
||||
list-style: circle inside; }
|
||||
ol {
|
||||
list-style: decimal inside; }
|
||||
ol, ul {
|
||||
padding-left: 0;
|
||||
margin-top: 0; }
|
||||
ul ul,
|
||||
ul ol,
|
||||
ol ol,
|
||||
ol ul {
|
||||
margin: 1.5rem 0 1.5rem 3rem;
|
||||
font-size: 90%; }
|
||||
li {
|
||||
margin-bottom: 1rem; }
|
||||
|
||||
|
||||
/* Code
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
code {
|
||||
padding: .2rem .5rem;
|
||||
margin: 0 .2rem;
|
||||
font-size: 90%;
|
||||
white-space: nowrap;
|
||||
background: #F1F1F1;
|
||||
border: 1px solid #E1E1E1;
|
||||
border-radius: 4px; }
|
||||
pre > code {
|
||||
display: block;
|
||||
padding: 1rem 1.5rem;
|
||||
white-space: pre; }
|
||||
|
||||
|
||||
/* 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
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
button,
|
||||
.button {
|
||||
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
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
.u-full-width {
|
||||
width: 100%;
|
||||
box-sizing: border-box; }
|
||||
.u-max-full-width {
|
||||
max-width: 100%;
|
||||
box-sizing: border-box; }
|
||||
.u-pull-right {
|
||||
float: right; }
|
||||
.u-pull-left {
|
||||
float: left; }
|
||||
|
||||
|
||||
/* Misc
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
hr {
|
||||
margin-top: 0.5rem;
|
||||
margin-bottom: 1.2rem;
|
||||
border-width: 0;
|
||||
border-top: 1px solid #E1E1E1; }
|
||||
|
||||
|
||||
/* Clearing
|
||||
–––––––––––––––––––––––––––––––––––––––––––––––––– */
|
||||
|
||||
/* Self Clearing Goodness */
|
||||
.container:after,
|
||||
.row:after,
|
||||
.u-cf {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both; }
|
||||
|
||||
)=====";
|
134
src/EasyUI.cpp
134
src/EasyUI.cpp
@ -1,67 +1,7 @@
|
||||
#include "EasyUI.h"
|
||||
|
||||
#include "HTML_PAGE.h" // Added HTML Index Page
|
||||
#include "CSS_STYLE.h" // Added Main CSS Style
|
||||
#include "CSS_NORMALIZE.h" // Added Normalize CSS
|
||||
#include "JS_ZEPTO.h"
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
#include <functional>
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
/*
|
||||
// Generate Websockets Script for Webpage
|
||||
void EasyUIClass::handleSockets(AsyncWebServerRequest *request){
|
||||
String ip;
|
||||
if(WiFi.localIP().toString() != "0.0.0.0"){
|
||||
ip = WiFi.localIP().toString();
|
||||
}
|
||||
else if(WiFi.softAPIP().toString() != "0.0.0.0"){
|
||||
ip = WiFi.softAPIP().toString();
|
||||
}
|
||||
|
||||
String wsString;
|
||||
wsString = "var connection = new WebSocket(\"ws://"+ip+":81/\", ['easyui']);";
|
||||
wsString += " var keys = {};";
|
||||
wsString += " connection.onopen = function () {";
|
||||
wsString += " $(\"#connection_status\").toggleClass(\"color-green\");";
|
||||
wsString += " $(\"#connection_status\").text(\"Connected\");";
|
||||
wsString += String(" connection.send(")+"\"{'mode': 'check_tb_status'}\");";
|
||||
for(int i=0; i<tb_index; i++){
|
||||
wsString += String(" $(document).on('click',")+"'#tb"+i+"', function() {";
|
||||
wsString += String(" if($('#tb")+i+"').hasClass(\"button\")){ console.log(\"Button Clicked!\"); connection.send("+"\"{'mode': 'tb_click', 'index': '"+i+"', 'status': 'on'}\""+"); }";
|
||||
wsString += String(" else if($('#tb")+i+"').hasClass(\"button-primary\")){ connection.send("+"\"{'mode': 'tb_click', 'index': '"+i+"', 'status': 'off'}\""+"); } });";
|
||||
}
|
||||
wsString += " };";
|
||||
wsString += " connection.onerror = function (error) { $('#connection_status').toggleClass(\"color-red\"); $(\"#connection_status\").text(\"Error / No Connection\"); };";
|
||||
wsString += " connection.onmessage = function (e) {";
|
||||
wsString += " console.log(e.data); ";
|
||||
wsString += " var obj = jQuery.parseJSON(e.data);";
|
||||
wsString += " if(obj.mode === 'create_label'){ $('#row').append(\"<div class='two columns card'><h5>\"+obj.l_title+\"</h5><hr /><h3><span class='label'>\"+obj.l_value+\"</span></h3></div>\");}";
|
||||
wsString += " else if(obj.mode === 'create_tbutton'){ $('#row').append(\"<div class='two columns card'><h5>\"+obj.tb_title+\"</h5><hr/><button id=\"+\"tb\"+obj.index+\"></button></div>\");}";
|
||||
wsString += " else if(obj.mode === 't_button_startup'){ var tb_index = obj.index; for(i=0; i<tb_index; i++){ var tb_index2 = \"tb\"+i; var tb_status = obj[tb_index2]; var tb_index3 = \"#\"+tb_index2; console.log(tb_status); if(tb_status === \"1\"){$(tb_index3).toggleClass('button-primary'); $(tb_index3).text('Turn Off');} else if(tb_status === \"0\"){$(tb_index3).toggleClass('button'); $(tb_index3).text('Turn On');} } }";
|
||||
wsString += " else if(obj.mode === 't_button_click'){ var tb_index = \"tb\"+obj.index; var tb_status = obj[tb_index]; var tb_index3 = \"#\"+tb_index; console.log(tb_status); if(tb_status == \"1\"){ console.log(\"Status Tuned ON\"); $(tb_index3).text('Turn Off'); $(tb_index3).removeClass( \"button\" ).addClass( \"button-primary\" );} else if(tb_status == \"0\"){console.log(\"Status Tuned OFF\"); $(tb_index3).text('Turn On'); $(tb_index3).removeClass( \"button-primary\" ).addClass( \"button\" ); } } };";
|
||||
request->send(200, "application/javascript", wsString);
|
||||
}
|
||||
|
||||
// Handle Index HTML
|
||||
void EasyUIClass::handleRoot(AsyncWebServerRequest *request){
|
||||
String rootString;
|
||||
//request->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
rootString += HTML_HEAD1;
|
||||
rootString += String("<title>")+ui_title+"</title>";
|
||||
rootString += HTML_HEAD2;
|
||||
rootString += String("<h4>")+ui_title+" <span id=\"connection_status\" class=\"label\">Offline</span></h4></div><hr />";
|
||||
rootString += HTML_BODY;
|
||||
rootString += "<script src=\"/js/zepto.js\"></script>";
|
||||
|
||||
rootString += HTML_END;
|
||||
request->send(200,"text/html", rootString);
|
||||
//server->client().stop();
|
||||
}
|
||||
*/
|
||||
/*
|
||||
// Handle Websockets Communication
|
||||
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
switch(type) {
|
||||
@ -72,26 +12,33 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
|
||||
{
|
||||
//Serial.printf("[WSc] Connected to url: %s\n", payload);
|
||||
Serial.println("Connected");
|
||||
EasyUI.handleWebpage();
|
||||
EasyUI.handleWebpage(client);
|
||||
Serial.println("JSON Data Sent to Client!");
|
||||
}
|
||||
break;
|
||||
case WS_EVT_DATA:
|
||||
Serial.print("WS Event");
|
||||
String msg = "";
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
msg += (char) data[i];
|
||||
}
|
||||
Serial.println(msg);
|
||||
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(data);
|
||||
String mode = root["mode"];
|
||||
if(mode == "check_tb_status"){
|
||||
EasyUI.tbuttonStatus();
|
||||
//EasyUI.tbuttonStatus();
|
||||
}
|
||||
else if(mode == "tb_click"){
|
||||
String status = root["status"];
|
||||
String index = root["index"];
|
||||
EasyUI.tbClick(index, status);
|
||||
//EasyUI.tbClick(index, status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void EasyUIClass::title(const char* _title){
|
||||
ui_title = _title;
|
||||
}
|
||||
@ -116,7 +63,6 @@ void EasyUIClass::toggleButton(uint8_t pin, const char* tbutton_label, int star
|
||||
// Create a generic Button
|
||||
void EasyUIClass::button(uint8_t pin, const char* tbutton_label, int start_state, bool swap_state){
|
||||
//TODO: Implement
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, start_state);
|
||||
tbutton_swap[tb_index] = swap_state;
|
||||
tbutton_pinout[tb_index] = pin;
|
||||
@ -189,60 +135,45 @@ void EasyUIClass::tbClick(String _index, String _status){
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
// Convert & Transfer Arduino elements to JSON elements
|
||||
void EasyUIClass::handleWebpage(){
|
||||
|
||||
// Convert & Transfer Arduino elements to JSON elements
|
||||
void EasyUIClass::handleWebpage(AsyncWebSocketClient * client){
|
||||
// Labels
|
||||
for(int i=0; i<l_index; i++){
|
||||
String json;
|
||||
StaticJsonBuffer<200> jsonBuffer1;
|
||||
JsonObject& root1 = jsonBuffer1.createObject();
|
||||
root1["mode"] = "create_label";
|
||||
root1["type"] = "domLabel";
|
||||
root1["l_title"] = String(label_title[i]);
|
||||
root1["l_value"] = String(label_value[i]);
|
||||
root1["label"] = String(label_value[i]);
|
||||
root1.printTo(json);
|
||||
webSocket->broadcastTXT(json);
|
||||
client->text(json);
|
||||
}
|
||||
|
||||
// Buttons
|
||||
for(int i=0; i<tb_index; i++){
|
||||
String json;
|
||||
StaticJsonBuffer<200> jsonBuffer2;
|
||||
JsonObject& root2 = jsonBuffer2.createObject();
|
||||
root2["mode"] = "create_tbutton";
|
||||
root2["type"] = "domButton";
|
||||
root2["index"] = String(i);
|
||||
root2["tb_title"] = tbuttontitle[i];
|
||||
root2["label"] = tbuttontitle[i];
|
||||
root2.printTo(json);
|
||||
webSocket->broadcastTXT(json);
|
||||
client->text(json);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void EasyUIClass::begin(){
|
||||
server.reset(new AsyncWebServer(80));
|
||||
//ws.reset(new AsyncWebSocket("/ws"));
|
||||
//SPIFFS.begin();
|
||||
server = new AsyncWebServer(80);
|
||||
ws = new AsyncWebSocket("/ws");
|
||||
SPIFFS.begin(false);
|
||||
|
||||
ws->onEvent(onWsEvent);
|
||||
server->addHandler(ws);
|
||||
|
||||
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
|
||||
|
||||
//ws->onEvent(onWsEvent);
|
||||
//server->addHandler(&ws);
|
||||
/*
|
||||
server->on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
EasyUI.handleRoot(request);
|
||||
});
|
||||
server->on("/js/sockets.js", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
EasyUI.handleSockets(request);
|
||||
});
|
||||
*/
|
||||
// Static constant serving =P
|
||||
server->on("/js/zepto.js", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
request->send(200, "application/javascript", JS_ZEPTO);
|
||||
});
|
||||
server->on("/css/normalize.css", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
request->send(200, "text/css", CSS_NORMALIZE);
|
||||
});
|
||||
server->on("/css/style.css", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
request->send(200, "text/css", CSS_STYLE);
|
||||
});
|
||||
//Heap for general Servertest
|
||||
server->on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||
@ -253,12 +184,7 @@ void EasyUIClass::begin(){
|
||||
});
|
||||
|
||||
server->begin();
|
||||
//webSocket->onEvent(webSocketEvent);
|
||||
|
||||
Serial.println("UI Initialized");
|
||||
}
|
||||
|
||||
void EasyUIClass::loop(){
|
||||
}
|
||||
|
||||
EasyUIClass EasyUI;
|
||||
|
19
src/EasyUI.h
19
src/EasyUI.h
@ -9,7 +9,8 @@
|
||||
#include "Arduino.h"
|
||||
#include "stdlib_noniso.h"
|
||||
#include "ArduinoJson.h"
|
||||
//#include "FS.h"
|
||||
#include "FS.h"
|
||||
#include "SPIFFS.h"
|
||||
#include "WiFi.h"
|
||||
|
||||
#include <AsyncTCP.h>
|
||||
@ -24,8 +25,6 @@ public:
|
||||
void toggleButton(uint8_t pin, const char* tbutton_label, int start_state = 0, bool swap_state = false); // Create Toggle Button
|
||||
void button(uint8_t pin, const char* tbutton_label, int start_state = 0, bool swap_state = false); // Create Toggle Button
|
||||
void label(const char* label_name, const char* label_val); // Create Label
|
||||
void loop(); // Do All Loop Work
|
||||
|
||||
// Variables ---
|
||||
const char* ui_title = "EasyUI"; // Store UI Title and Header Name
|
||||
int tb_index; // Calculate How Many Toggle Buttons
|
||||
@ -43,21 +42,13 @@ public:
|
||||
String webpage; // Coverts Arduino elements to JSON elements
|
||||
String wsString = ""; // Stores Websockets Script
|
||||
|
||||
// Don't Issue the Below functions in your Sketch! - These are Resposible for Webpage functioning.
|
||||
void tbClick(String _index, String _status);
|
||||
void tbuttonStatus();
|
||||
void handleWebpage();
|
||||
|
||||
void handleWebpage(AsyncWebSocketClient * client);
|
||||
|
||||
private:
|
||||
std::unique_ptr<AsyncWebServer> server; // Create Unique Instance for Webserver
|
||||
std::unique_ptr<AsyncWebSocket> ws; // Create Unique Instance for WebSocketsServer
|
||||
|
||||
void handleRoot(AsyncWebServerRequest *request); // Handle MainPage
|
||||
void handleNotFound(); // Handle Page Not-Found
|
||||
void handleSockets(AsyncWebServerRequest *request); // Handle Sockets Script
|
||||
|
||||
|
||||
AsyncWebServer* server; // Create Unique Instance for Webserver
|
||||
AsyncWebSocket* ws;
|
||||
};
|
||||
|
||||
extern EasyUIClass EasyUI;
|
||||
|
@ -9,7 +9,7 @@ const char HTML_HEAD2[] PROGMEM = R"=====(
|
||||
<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/skeleton.css">
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user