2017-10-19 15:43:39 +00:00
|
|
|
#ifndef ESPUI_h
|
|
|
|
#define ESPUI_h
|
2017-05-18 22:05:32 +00:00
|
|
|
|
2017-11-13 15:10:56 +00:00
|
|
|
#define debug true
|
|
|
|
|
2017-05-18 22:05:32 +00:00
|
|
|
#include "Arduino.h"
|
|
|
|
#include "ArduinoJson.h"
|
2017-10-16 22:10:48 +00:00
|
|
|
#include "FS.h"
|
2017-11-14 11:09:52 +00:00
|
|
|
#include "stdlib_noniso.h"
|
2017-10-16 13:00:53 +00:00
|
|
|
|
2017-12-01 16:11:16 +00:00
|
|
|
#if defined(ESP32)
|
|
|
|
|
|
|
|
#include "SPIFFS.h"
|
|
|
|
#include "WiFi.h"
|
2017-10-16 13:00:53 +00:00
|
|
|
#include <AsyncTCP.h>
|
|
|
|
#include <ESPAsyncWebServer.h>
|
2017-05-18 22:05:32 +00:00
|
|
|
|
2017-12-01 16:11:16 +00:00
|
|
|
#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
|
|
|
|
|
2017-11-14 11:09:52 +00:00
|
|
|
typedef struct Control {
|
2017-11-13 15:10:56 +00:00
|
|
|
unsigned int type;
|
|
|
|
unsigned int id; // just mirroring the id here for practical reasons
|
|
|
|
const char *label;
|
2017-11-14 11:09:52 +00:00
|
|
|
void (*callback)(Control, int);
|
2017-11-13 15:10:56 +00:00
|
|
|
String value;
|
2017-11-14 11:09:52 +00:00
|
|
|
unsigned int color;
|
2017-10-19 11:46:47 +00:00
|
|
|
} Control;
|
|
|
|
|
|
|
|
// Types
|
|
|
|
#define UI_TITEL 0
|
|
|
|
#define UI_LABEL 1
|
|
|
|
#define UI_BUTTON 2
|
|
|
|
#define UI_SWITCHER 3
|
|
|
|
#define UI_PAD 4
|
|
|
|
#define UI_CPAD 5
|
|
|
|
#define UPDATE_LABEL 6
|
2017-11-29 10:32:07 +00:00
|
|
|
#define UPDATE_SWITCHER 7
|
2017-11-28 12:48:58 +00:00
|
|
|
#define UI_SLIDER 8
|
|
|
|
#define UPDATE_SLIDER 9
|
2017-10-19 11:46:47 +00:00
|
|
|
|
|
|
|
// Values
|
|
|
|
#define B_DOWN -1
|
2017-11-14 11:09:52 +00:00
|
|
|
#define B_UP 1
|
2017-10-19 11:46:47 +00:00
|
|
|
|
|
|
|
#define P_LEFT_DOWN -2
|
|
|
|
#define P_LEFT_UP 2
|
|
|
|
#define P_RIGHT_DOWN -3
|
|
|
|
#define P_RIGHT_UP 3
|
|
|
|
#define P_FOR_DOWN -4
|
|
|
|
#define P_FOR_UP 4
|
|
|
|
#define P_BACK_DOWN -5
|
|
|
|
#define P_BACK_UP 5
|
|
|
|
#define P_CENTER_DOWN -6
|
|
|
|
#define P_CENTER_UP 6
|
2017-11-29 10:32:07 +00:00
|
|
|
|
2017-10-19 15:30:32 +00:00
|
|
|
#define S_ACTIVE -7
|
|
|
|
#define S_INACTIVE 7
|
2017-10-19 11:46:47 +00:00
|
|
|
|
2017-11-29 10:32:07 +00:00
|
|
|
#define SL_VALUE 8
|
|
|
|
|
2017-10-19 11:46:47 +00:00
|
|
|
|
2017-11-14 11:09:52 +00:00
|
|
|
// Colors
|
|
|
|
#define COLOR_TURQUOISE 0
|
|
|
|
#define COLOR_EMERALD 1
|
|
|
|
#define COLOR_PETERRIVER 2
|
|
|
|
#define COLOR_WETASPHALT 3
|
|
|
|
#define COLOR_SUNFLOWER 4
|
|
|
|
#define COLOR_CARROT 5
|
|
|
|
#define COLOR_ALIZARIN 6
|
2017-11-14 11:12:12 +00:00
|
|
|
#define COLOR_NONE 6
|
2017-11-14 11:09:52 +00:00
|
|
|
|
2017-05-18 22:05:32 +00:00
|
|
|
|
2017-11-13 15:10:56 +00:00
|
|
|
class ESPUIClass {
|
2017-05-18 22:05:32 +00:00
|
|
|
|
|
|
|
public:
|
2017-11-14 11:09:52 +00:00
|
|
|
void begin(const char *_title); // Setup servers and page
|
|
|
|
|
2017-11-28 12:48:58 +00:00
|
|
|
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS
|
|
|
|
|
2017-11-14 11:09:52 +00:00
|
|
|
// Creating Elements
|
|
|
|
void label(const char *label, int color, String value = ""); // Create Label
|
|
|
|
void button(const char *label, void (*callBack)(Control, int), int color,
|
|
|
|
String value = ""); // Create Event Button
|
|
|
|
void switcher(const char *label, bool startState,
|
|
|
|
void (*callBack)(Control, int),
|
|
|
|
int color); // Create Toggle Button
|
|
|
|
void pad(const char *label, bool centerButton, void (*callBack)(Control, int),
|
|
|
|
int color); // Create Pad Control
|
2017-11-28 12:48:58 +00:00
|
|
|
void slider(const char *label, void (*callBack)(Control, int), int color, String value); // Create Slider Control
|
2017-11-14 11:09:52 +00:00
|
|
|
|
|
|
|
// Update Elements
|
|
|
|
void print(int id, String value);
|
|
|
|
void print(String label, String value);
|
|
|
|
|
2017-11-29 10:32:07 +00:00
|
|
|
void updateSwitcher(int id, bool nValue, int clientId = -1);
|
|
|
|
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);
|
2017-11-14 11:09:52 +00:00
|
|
|
|
2017-11-29 10:32:07 +00:00
|
|
|
void textThem(String text, int clientId);
|
2017-11-28 12:48:58 +00:00
|
|
|
|
2017-11-14 11:09:52 +00:00
|
|
|
// Variables ---
|
|
|
|
const char *ui_title = "ESPUI"; // Store UI Title and Header Name
|
|
|
|
int cIndex = 0; // Control index
|
|
|
|
Control *controls[25];
|
|
|
|
void jsonDom(AsyncWebSocketClient *client);
|
|
|
|
int getIdByLabel(String label);
|
|
|
|
bool labelExists(String label);
|
2017-05-18 22:05:32 +00:00
|
|
|
|
2017-10-19 11:46:47 +00:00
|
|
|
private:
|
2017-11-14 11:09:52 +00:00
|
|
|
AsyncWebServer *server;
|
|
|
|
AsyncWebSocket *ws;
|
2017-05-18 22:05:32 +00:00
|
|
|
};
|
|
|
|
|
2017-10-19 15:43:39 +00:00
|
|
|
extern ESPUIClass ESPUI;
|
2017-05-18 22:05:32 +00:00
|
|
|
#endif
|