1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-06-18 16:34:14 +00:00
ESPUI/src/ESPUI.h

92 lines
2.0 KiB
C
Raw Normal View History

2017-10-19 15:43:39 +00:00
#ifndef ESPUI_h
#define ESPUI_h
2017-05-18 22:05:32 +00:00
2017-10-16 13:00:53 +00:00
#define HARDWARE "esp32"
2017-11-13 15:10:56 +00:00
#define debug true
2017-10-16 13:00:53 +00:00
//ifdef 8266
//#include "Hash.h"
2017-05-18 22:05:32 +00:00
#include "Arduino.h"
#include "stdlib_noniso.h"
#include "ArduinoJson.h"
2017-10-16 22:10:48 +00:00
#include "FS.h"
#include "SPIFFS.h"
2017-10-16 13:00:53 +00:00
#include "WiFi.h"
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
2017-05-18 22:05:32 +00:00
2017-10-19 11:46:47 +00:00
typedef struct Control
2017-10-16 23:10:29 +00:00
{
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;
void (*callback)(Control*, int);
String value;
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-10-19 15:30:32 +00:00
#define UPDATE_SWITCH 7
2017-10-19 11:46:47 +00:00
// Values
#define B_DOWN -1
#define B_UP 1
#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-10-19 15:30:32 +00:00
#define S_ACTIVE -7
#define S_INACTIVE 7
2017-10-19 11:46:47 +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-13 15:10:56 +00:00
void begin(const char* _title); // Setup servers and page
// Creating Elements
void label(const char* label, String value = ""); // Create Label
2017-11-13 16:22:02 +00:00
void button(const char* label, void (* callBack)(Control*, int), String value = ""); // Create Event Button
2017-11-13 15:10:56 +00:00
void switcher(const char* label, bool startState, void (* callBack)(Control*, int)); // Create Toggle Button
void pad(const char* label, bool centerButton, void (* callBack)(Control*, int)); // Create Pad Control
2017-05-18 22:05:32 +00:00
2017-11-13 15:10:56 +00:00
// Update Elements
void print(int id, String value);
void print(String label, String value);
2017-05-18 22:05:32 +00:00
2017-11-13 15:10:56 +00:00
void updateSwitcher(int id, bool nValue);
void updateSwitcher(String label, bool nValue);
2017-05-18 22:05:32 +00:00
2017-11-13 15:10:56 +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-13 15:10:56 +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