mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-25 14:10:54 +00:00
Cleanup and reformat header
- Construct inside library - Adds setVerbosity
This commit is contained in:
parent
b9a087c169
commit
63b6761044
14
README.md
14
README.md
@ -24,14 +24,26 @@ THIS IS THE 2.0.0 development branch
|
||||
|
||||
**Roadmap for 2.0.0:**
|
||||
|
||||
- ArduinoJSON 6.10.0 Support
|
||||
- ArduinoJSON 6.10.0 Support ✅
|
||||
- Tabs by engerlingi ISSUE #45
|
||||
- remove black line without tabs
|
||||
- API changes by engerlingi
|
||||
- less updateCotrol functions
|
||||
- proper wrappers for all create/update actions
|
||||
- OptionList by engerlingi
|
||||
- Better returnvalues
|
||||
- Min Max on slider
|
||||
- Accelerometer Widget
|
||||
- Cleanup Example
|
||||
- New Documentation
|
||||
- Numberfield
|
||||
- Textfield
|
||||
- Data directory
|
||||
- Graph Usage
|
||||
- Accelerometer
|
||||
- Slider
|
||||
- OptionList
|
||||
- Tab usage
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
@ -838,3 +838,7 @@ void ESPUIClass::begin(const char* _title, const char* username,
|
||||
Serial.println("UI Initialized");
|
||||
}
|
||||
}
|
||||
|
||||
void ESPUIClass::setVerbosity(Verbosity v) { this->verbosity = v; }
|
||||
|
||||
ESPUIClass ESPUI;
|
248
src/ESPUI.h
248
src/ESPUI.h
@ -75,26 +75,26 @@ enum ControlType : uint8_t {
|
||||
InitialGui = 200
|
||||
};
|
||||
|
||||
#define UI_INITIAL_GUI ControlType::InitialGui
|
||||
#define UI_INITIAL_GUI ControlType::InitialGui
|
||||
|
||||
#define UI_TITLE ControlType::Title
|
||||
#define UI_LABEL ControlType::Label
|
||||
#define UI_BUTTON ControlType::Button
|
||||
#define UI_SWITCHER ControlType::Switcher
|
||||
#define UI_PAD ControlType::Pad
|
||||
#define UI_CPAD ControlType::Cpad
|
||||
#define UI_SLIDER ControlType::Slider
|
||||
#define UI_NUMBER ControlType::Number
|
||||
#define UI_TEXT_INPUT ControlType::Text
|
||||
#define UI_GRAPH ControlType::Graph
|
||||
#define UI_ADD_GRAPH_POINT ControlType::GraphPoint
|
||||
#define UI_TITLE ControlType::Title
|
||||
#define UI_LABEL ControlType::Label
|
||||
#define UI_BUTTON ControlType::Button
|
||||
#define UI_SWITCHER ControlType::Switcher
|
||||
#define UI_PAD ControlType::Pad
|
||||
#define UI_CPAD ControlType::Cpad
|
||||
#define UI_SLIDER ControlType::Slider
|
||||
#define UI_NUMBER ControlType::Number
|
||||
#define UI_TEXT_INPUT ControlType::Text
|
||||
#define UI_GRAPH ControlType::Graph
|
||||
#define UI_ADD_GRAPH_POINT ControlType::GraphPoint
|
||||
|
||||
#define UPDATE_LABEL ControlType::UpdateLabel
|
||||
#define UPDATE_SWITCHER ControlType::UpdateSwitcher
|
||||
#define UPDATE_SLIDER ControlType::UpdateSlider
|
||||
#define UPDATE_NUMBER ControlType::UpdateNumber
|
||||
#define UPDATE_TEXT_INPUT ControlType::UpdateText
|
||||
#define CLEAR_GRAPH ControlType::ClearGraph
|
||||
#define UPDATE_LABEL ControlType::UpdateLabel
|
||||
#define UPDATE_SWITCHER ControlType::UpdateSwitcher
|
||||
#define UPDATE_SLIDER ControlType::UpdateSlider
|
||||
#define UPDATE_NUMBER ControlType::UpdateNumber
|
||||
#define UPDATE_TEXT_INPUT ControlType::UpdateText
|
||||
#define CLEAR_GRAPH ControlType::ClearGraph
|
||||
|
||||
// Colors
|
||||
enum ControlColor : uint8_t {
|
||||
@ -108,49 +108,56 @@ enum ControlColor : uint8_t {
|
||||
Dark,
|
||||
None = 0xFF
|
||||
};
|
||||
#define COLOR_TURQUOISE ControlColor::Turquoise
|
||||
#define COLOR_EMERALD ControlColor::Emerald
|
||||
#define COLOR_PETERRIVER ControlColor::Peterriver
|
||||
#define COLOR_WETASPHALT ControlColor::Wetasphalt
|
||||
#define COLOR_SUNFLOWER ControlColor::Sunflower
|
||||
#define COLOR_CARROT ControlColor::Carrot
|
||||
#define COLOR_ALIZARIN ControlColor::Alizarin
|
||||
#define COLOR_DARK ControlColor::Dark
|
||||
#define COLOR_NONE ControlColor::None
|
||||
#define COLOR_TURQUOISE ControlColor::Turquoise
|
||||
#define COLOR_EMERALD ControlColor::Emerald
|
||||
#define COLOR_PETERRIVER ControlColor::Peterriver
|
||||
#define COLOR_WETASPHALT ControlColor::Wetasphalt
|
||||
#define COLOR_SUNFLOWER ControlColor::Sunflower
|
||||
#define COLOR_CARROT ControlColor::Carrot
|
||||
#define COLOR_ALIZARIN ControlColor::Alizarin
|
||||
#define COLOR_DARK ControlColor::Dark
|
||||
#define COLOR_NONE ControlColor::None
|
||||
|
||||
class Control {
|
||||
public:
|
||||
ControlType type;
|
||||
uint16_t id; // just mirroring the id here for practical reasons
|
||||
const char* label;
|
||||
void ( *callback )( Control*, int );
|
||||
String value;
|
||||
ControlColor color;
|
||||
uint16_t parentControl;
|
||||
Control* next;
|
||||
public:
|
||||
ControlType type;
|
||||
uint16_t id; // just mirroring the id here for practical reasons
|
||||
const char* label;
|
||||
void (*callback)(Control*, int);
|
||||
String value;
|
||||
ControlColor color;
|
||||
uint16_t parentControl;
|
||||
Control* next;
|
||||
|
||||
static constexpr uint16_t noParent = 0xffff;
|
||||
static constexpr uint16_t noParent = 0xffff;
|
||||
|
||||
Control(
|
||||
ControlType type, const char* label,
|
||||
void ( *callback )( Control*, int ),
|
||||
String value, ControlColor color, uint16_t parentControl = Control::noParent )
|
||||
: type( type ), label( label ), callback( callback ), value( value ), color( color ), parentControl( parentControl ), next( nullptr ) {
|
||||
id = idCounter++;
|
||||
// Serial.print( "Control id: " );
|
||||
// Serial.println( id );
|
||||
}
|
||||
Control(ControlType type, const char* label, void (*callback)(Control*, int),
|
||||
String value, ControlColor color,
|
||||
uint16_t parentControl = Control::noParent)
|
||||
: type(type),
|
||||
label(label),
|
||||
callback(callback),
|
||||
value(value),
|
||||
color(color),
|
||||
parentControl(parentControl),
|
||||
next(nullptr) {
|
||||
id = idCounter++;
|
||||
}
|
||||
|
||||
Control( const Control& control )
|
||||
: type( control.type ), id( control.id ), label( control.label ),
|
||||
callback( control.callback ), value( control.value ),
|
||||
color( control.color ), parentControl( control.parentControl ), next( control.next ) {}
|
||||
Control(const Control& control)
|
||||
: type(control.type),
|
||||
id(control.id),
|
||||
label(control.label),
|
||||
callback(control.callback),
|
||||
value(control.value),
|
||||
color(control.color),
|
||||
parentControl(control.parentControl),
|
||||
next(control.next) {}
|
||||
|
||||
private:
|
||||
static uint16_t idCounter;
|
||||
private:
|
||||
static uint16_t idCounter;
|
||||
};
|
||||
|
||||
|
||||
// Values
|
||||
#define B_DOWN -1
|
||||
#define B_UP 1
|
||||
@ -174,100 +181,97 @@ class Control {
|
||||
#define T_VALUE 10
|
||||
#define S_VALUE 11
|
||||
|
||||
enum Verbosity : uint8_t {
|
||||
Quiet = 0,
|
||||
Verbose,
|
||||
VerboseJSON
|
||||
};
|
||||
enum Verbosity : uint8_t { Quiet = 0, Verbose, VerboseJSON };
|
||||
|
||||
class ESPUIClass {
|
||||
public:
|
||||
ESPUIClass( Verbosity verbosity = Verbosity::Quiet )
|
||||
: verbosity( verbosity ) {}
|
||||
public:
|
||||
ESPUIClass() { verbosity = Verbosity::Quiet; }
|
||||
|
||||
// void begin( const char* _title, bool enableDebug=false ); // Setup servers and page in Memorymode
|
||||
void begin( const char* _title, const char* username = nullptr, const char* password = nullptr );
|
||||
void setVerbosity(Verbosity verbosity);
|
||||
// Setup server and page in Memorymode
|
||||
void begin(const char* _title, const char* username = nullptr,
|
||||
const char* password = nullptr);
|
||||
|
||||
// void beginSPIFFS( const char* _title, bool enableDebug=false ); // Setup servers and page in SPIFFSmode
|
||||
void beginSPIFFS( const char* _title, const char* username = nullptr, const char* password = nullptr );
|
||||
// Setup server and page in SPIFFSmode
|
||||
void beginSPIFFS(const char* _title, const char* username = nullptr,
|
||||
const char* password = nullptr);
|
||||
|
||||
void prepareFileSystem(); // Initially preps the filesystem and loads a lot
|
||||
// of stuff into SPIFFS
|
||||
void list();
|
||||
// Creating Elements
|
||||
void prepareFileSystem(); // Initially preps the filesystem and loads a lot
|
||||
// of stuff into SPIFFS
|
||||
void list();
|
||||
// Creating Elements
|
||||
|
||||
uint16_t addControl( ControlType type, const char* label,
|
||||
String value = String( "" ), ControlColor color = ControlColor::Turquoise,
|
||||
uint16_t parentControl = Control::noParent, void ( *callback )( Control*, int ) = nullptr );
|
||||
uint16_t addControl(ControlType type, const char* label,
|
||||
String value = String(""),
|
||||
ControlColor color = ControlColor::Turquoise,
|
||||
uint16_t parentControl = Control::noParent,
|
||||
void (*callback)(Control*, int) = nullptr);
|
||||
|
||||
int button( const char* label,
|
||||
void ( *callback )( Control*, int ), ControlColor color,
|
||||
String value = "" ); // Create Event Button
|
||||
int switcher( const char* label, bool startState,
|
||||
void ( *callback )( Control*, int ),
|
||||
ControlColor color ); // Create Toggle Button
|
||||
int pad( const char* label, bool centerButton,
|
||||
void ( *callback )( Control*, int ),
|
||||
ControlColor color ); // Create Pad Control
|
||||
int slider( const char* label,
|
||||
void ( *callback )( Control*, int ),
|
||||
ControlColor color, String value ); // Create Slider Control
|
||||
int number( const char* label,
|
||||
void ( *callback )( Control*, int ),
|
||||
ControlColor color, int number, int min, int max ); // Create a Number Input Control
|
||||
int text( const char* label,
|
||||
void ( *callback )( Control*, int ),
|
||||
ControlColor color, String value = "" ); // Create a Text Input Control
|
||||
int button(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color,
|
||||
String value = ""); // Create Event Button
|
||||
int switcher(const char* label, bool startState,
|
||||
void (*callback)(Control*, int),
|
||||
ControlColor color); // Create Toggle Button
|
||||
int pad(const char* label, bool centerButton, void (*callback)(Control*, int),
|
||||
ControlColor color); // Create Pad Control
|
||||
int slider(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color, String value); // Create Slider Control
|
||||
int number(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color, int number, int min,
|
||||
int max); // Create a Number Input Control
|
||||
int text(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color,
|
||||
String value = ""); // Create a Text Input Control
|
||||
|
||||
// Output only
|
||||
int label( const char* label, ControlColor color, String value = "" ); // Create Label
|
||||
int graph( const char* label, ControlColor color ); // Create Graph display
|
||||
// Output only
|
||||
int label(const char* label, ControlColor color,
|
||||
String value = ""); // Create Label
|
||||
int graph(const char* label, ControlColor color); // Create Graph display
|
||||
|
||||
// Update Elements
|
||||
// Update Elements
|
||||
|
||||
Control* getControl( uint16_t id );
|
||||
Control* getControl(uint16_t id);
|
||||
|
||||
// Update Elements
|
||||
void updateControl( uint16_t id, String value, int clientId = -1 );
|
||||
void updateControl( Control* control, String value, int clientId = -1 );
|
||||
void updateControl( uint16_t id, int clientId = -1 );
|
||||
void updateControl( Control* control, int clientId = -1 );
|
||||
// Update Elements
|
||||
void updateControl(uint16_t id, String value, int clientId = -1);
|
||||
void updateControl(Control* control, String value, int clientId = -1);
|
||||
|
||||
void print( uint16_t id, String value );
|
||||
void updateControl(uint16_t id, int clientId = -1);
|
||||
void updateControl(Control* control, int clientId = -1);
|
||||
|
||||
void updateLabel( uint16_t id, String value );
|
||||
void print(uint16_t id, String value);
|
||||
|
||||
void updateSwitcher( uint16_t id, bool nValue, int clientId = -1 );
|
||||
void updateLabel(uint16_t id, String value);
|
||||
|
||||
void updateSlider( uint16_t id, int nValue, int clientId = -1 );
|
||||
void updateSwitcher(uint16_t id, bool nValue, int clientId = -1);
|
||||
|
||||
void updateNumber( uint16_t id, int nValue, int clientId = -1 );
|
||||
void updateSlider(uint16_t id, int nValue, int clientId = -1);
|
||||
|
||||
void updateText( uint16_t id, String nValue, int clientId = -1 );
|
||||
void updateNumber(uint16_t id, int nValue, int clientId = -1);
|
||||
|
||||
void updateSelect( uint16_t id, String nValue, int clientId = -1 );
|
||||
void updateText(uint16_t id, String nValue, int clientId = -1);
|
||||
|
||||
void clearGraph( uint16_t id, int clientId = -1 );
|
||||
void updateSelect(uint16_t id, String nValue, int clientId = -1);
|
||||
|
||||
void addGraphPoint( uint16_t id, int nValue, int clientId = -1 );
|
||||
void clearGraph(uint16_t id, int clientId = -1);
|
||||
|
||||
// void textThem( String text, int clientId = -1 );
|
||||
void addGraphPoint(uint16_t id, int nValue, int clientId = -1);
|
||||
|
||||
// Variables ---
|
||||
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
|
||||
Control* controls = nullptr;
|
||||
void jsonDom( AsyncWebSocketClient* client );
|
||||
// Variables ---
|
||||
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
|
||||
Control* controls = nullptr;
|
||||
void jsonDom(AsyncWebSocketClient* client);
|
||||
|
||||
Verbosity verbosity;
|
||||
Verbosity verbosity;
|
||||
|
||||
private:
|
||||
const char* basicAuthUsername = nullptr;
|
||||
const char* basicAuthPassword = nullptr;
|
||||
bool basicAuth = true;
|
||||
AsyncWebServer* server;
|
||||
AsyncWebSocket* ws;
|
||||
private:
|
||||
const char* basicAuthUsername = nullptr;
|
||||
const char* basicAuthPassword = nullptr;
|
||||
bool basicAuth = true;
|
||||
AsyncWebServer* server;
|
||||
AsyncWebSocket* ws;
|
||||
};
|
||||
|
||||
extern ESPUIClass ESPUI;
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user