1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-22 09:10:54 +00:00

Cleanup and reformat header

- Construct inside library
- Adds setVerbosity
This commit is contained in:
Lukas Bachschwell 2019-03-24 16:06:35 +01:00
parent b9a087c169
commit 63b6761044
3 changed files with 143 additions and 123 deletions

View File

@ -24,14 +24,26 @@ THIS IS THE 2.0.0 development branch
**Roadmap for 2.0.0:** **Roadmap for 2.0.0:**
- ArduinoJSON 6.10.0 Support - ArduinoJSON 6.10.0 Support
- Tabs by engerlingi ISSUE #45 - 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 - OptionList by engerlingi
- Better returnvalues - Better returnvalues
- Min Max on slider - Min Max on slider
- Accelerometer Widget - Accelerometer Widget
- Cleanup Example - Cleanup Example
- New Documentation - New Documentation
- Numberfield
- Textfield
- Data directory
- Graph Usage
- Accelerometer
- Slider
- OptionList
- Tab usage
## Dependencies ## Dependencies

View File

@ -838,3 +838,7 @@ void ESPUIClass::begin(const char* _title, const char* username,
Serial.println("UI Initialized"); Serial.println("UI Initialized");
} }
} }
void ESPUIClass::setVerbosity(Verbosity v) { this->verbosity = v; }
ESPUIClass ESPUI;

View File

@ -75,26 +75,26 @@ enum ControlType : uint8_t {
InitialGui = 200 InitialGui = 200
}; };
#define UI_INITIAL_GUI ControlType::InitialGui #define UI_INITIAL_GUI ControlType::InitialGui
#define UI_TITLE ControlType::Title #define UI_TITLE ControlType::Title
#define UI_LABEL ControlType::Label #define UI_LABEL ControlType::Label
#define UI_BUTTON ControlType::Button #define UI_BUTTON ControlType::Button
#define UI_SWITCHER ControlType::Switcher #define UI_SWITCHER ControlType::Switcher
#define UI_PAD ControlType::Pad #define UI_PAD ControlType::Pad
#define UI_CPAD ControlType::Cpad #define UI_CPAD ControlType::Cpad
#define UI_SLIDER ControlType::Slider #define UI_SLIDER ControlType::Slider
#define UI_NUMBER ControlType::Number #define UI_NUMBER ControlType::Number
#define UI_TEXT_INPUT ControlType::Text #define UI_TEXT_INPUT ControlType::Text
#define UI_GRAPH ControlType::Graph #define UI_GRAPH ControlType::Graph
#define UI_ADD_GRAPH_POINT ControlType::GraphPoint #define UI_ADD_GRAPH_POINT ControlType::GraphPoint
#define UPDATE_LABEL ControlType::UpdateLabel #define UPDATE_LABEL ControlType::UpdateLabel
#define UPDATE_SWITCHER ControlType::UpdateSwitcher #define UPDATE_SWITCHER ControlType::UpdateSwitcher
#define UPDATE_SLIDER ControlType::UpdateSlider #define UPDATE_SLIDER ControlType::UpdateSlider
#define UPDATE_NUMBER ControlType::UpdateNumber #define UPDATE_NUMBER ControlType::UpdateNumber
#define UPDATE_TEXT_INPUT ControlType::UpdateText #define UPDATE_TEXT_INPUT ControlType::UpdateText
#define CLEAR_GRAPH ControlType::ClearGraph #define CLEAR_GRAPH ControlType::ClearGraph
// Colors // Colors
enum ControlColor : uint8_t { enum ControlColor : uint8_t {
@ -108,49 +108,56 @@ enum ControlColor : uint8_t {
Dark, Dark,
None = 0xFF None = 0xFF
}; };
#define COLOR_TURQUOISE ControlColor::Turquoise #define COLOR_TURQUOISE ControlColor::Turquoise
#define COLOR_EMERALD ControlColor::Emerald #define COLOR_EMERALD ControlColor::Emerald
#define COLOR_PETERRIVER ControlColor::Peterriver #define COLOR_PETERRIVER ControlColor::Peterriver
#define COLOR_WETASPHALT ControlColor::Wetasphalt #define COLOR_WETASPHALT ControlColor::Wetasphalt
#define COLOR_SUNFLOWER ControlColor::Sunflower #define COLOR_SUNFLOWER ControlColor::Sunflower
#define COLOR_CARROT ControlColor::Carrot #define COLOR_CARROT ControlColor::Carrot
#define COLOR_ALIZARIN ControlColor::Alizarin #define COLOR_ALIZARIN ControlColor::Alizarin
#define COLOR_DARK ControlColor::Dark #define COLOR_DARK ControlColor::Dark
#define COLOR_NONE ControlColor::None #define COLOR_NONE ControlColor::None
class Control { class Control {
public: public:
ControlType type; ControlType type;
uint16_t id; // just mirroring the id here for practical reasons uint16_t id; // just mirroring the id here for practical reasons
const char* label; const char* label;
void ( *callback )( Control*, int ); void (*callback)(Control*, int);
String value; String value;
ControlColor color; ControlColor color;
uint16_t parentControl; uint16_t parentControl;
Control* next; Control* next;
static constexpr uint16_t noParent = 0xffff; static constexpr uint16_t noParent = 0xffff;
Control( Control(ControlType type, const char* label, void (*callback)(Control*, int),
ControlType type, const char* label, String value, ControlColor color,
void ( *callback )( Control*, int ), uint16_t parentControl = Control::noParent)
String value, ControlColor color, uint16_t parentControl = Control::noParent ) : type(type),
: type( type ), label( label ), callback( callback ), value( value ), color( color ), parentControl( parentControl ), next( nullptr ) { label(label),
id = idCounter++; callback(callback),
// Serial.print( "Control id: " ); value(value),
// Serial.println( id ); color(color),
} parentControl(parentControl),
next(nullptr) {
id = idCounter++;
}
Control( const Control& control ) Control(const Control& control)
: type( control.type ), id( control.id ), label( control.label ), : type(control.type),
callback( control.callback ), value( control.value ), id(control.id),
color( control.color ), parentControl( control.parentControl ), next( control.next ) {} label(control.label),
callback(control.callback),
value(control.value),
color(control.color),
parentControl(control.parentControl),
next(control.next) {}
private: private:
static uint16_t idCounter; static uint16_t idCounter;
}; };
// Values // Values
#define B_DOWN -1 #define B_DOWN -1
#define B_UP 1 #define B_UP 1
@ -174,100 +181,97 @@ class Control {
#define T_VALUE 10 #define T_VALUE 10
#define S_VALUE 11 #define S_VALUE 11
enum Verbosity : uint8_t { enum Verbosity : uint8_t { Quiet = 0, Verbose, VerboseJSON };
Quiet = 0,
Verbose,
VerboseJSON
};
class ESPUIClass { class ESPUIClass {
public: public:
ESPUIClass( Verbosity verbosity = Verbosity::Quiet ) ESPUIClass() { verbosity = Verbosity::Quiet; }
: verbosity( verbosity ) {}
// void begin( const char* _title, bool enableDebug=false ); // Setup servers and page in Memorymode void setVerbosity(Verbosity verbosity);
void begin( const char* _title, const char* username = nullptr, const char* password = nullptr ); // 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 // Setup server and page in SPIFFSmode
void beginSPIFFS( const char* _title, const char* username = nullptr, const char* password = nullptr ); void beginSPIFFS(const char* _title, const char* username = nullptr,
const char* password = nullptr);
void prepareFileSystem(); // Initially preps the filesystem and loads a lot void prepareFileSystem(); // Initially preps the filesystem and loads a lot
// of stuff into SPIFFS // of stuff into SPIFFS
void list(); void list();
// Creating Elements // Creating Elements
uint16_t addControl( ControlType type, const char* label, uint16_t addControl(ControlType type, const char* label,
String value = String( "" ), ControlColor color = ControlColor::Turquoise, String value = String(""),
uint16_t parentControl = Control::noParent, void ( *callback )( Control*, int ) = nullptr ); ControlColor color = ControlColor::Turquoise,
uint16_t parentControl = Control::noParent,
void (*callback)(Control*, int) = nullptr);
int button( const char* label, int button(const char* label, void (*callback)(Control*, int),
void ( *callback )( Control*, int ), ControlColor color, ControlColor color,
String value = "" ); // Create Event Button String value = ""); // Create Event Button
int switcher( const char* label, bool startState, int switcher(const char* label, bool startState,
void ( *callback )( Control*, int ), void (*callback)(Control*, int),
ControlColor color ); // Create Toggle Button ControlColor color); // Create Toggle Button
int pad( const char* label, bool centerButton, int pad(const char* label, bool centerButton, void (*callback)(Control*, int),
void ( *callback )( Control*, int ), ControlColor color); // Create Pad Control
ControlColor color ); // Create Pad Control int slider(const char* label, void (*callback)(Control*, int),
int slider( const char* label, ControlColor color, String value); // Create Slider Control
void ( *callback )( Control*, int ), int number(const char* label, void (*callback)(Control*, int),
ControlColor color, String value ); // Create Slider Control ControlColor color, int number, int min,
int number( const char* label, int max); // Create a Number Input Control
void ( *callback )( Control*, int ), int text(const char* label, void (*callback)(Control*, int),
ControlColor color, int number, int min, int max ); // Create a Number Input Control ControlColor color,
int text( const char* label, String value = ""); // Create a Text Input Control
void ( *callback )( Control*, int ),
ControlColor color, String value = "" ); // Create a Text Input Control
// Output only // Output only
int label( const char* label, ControlColor color, String value = "" ); // Create Label int label(const char* label, ControlColor color,
int graph( const char* label, ControlColor color ); // Create Graph display 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 // Update Elements
void updateControl( uint16_t id, String value, int clientId = -1 ); void updateControl(uint16_t id, String value, int clientId = -1);
void updateControl( Control* control, 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 );
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 --- // Variables ---
const char* ui_title = "ESPUI"; // Store UI Title and Header Name const char* ui_title = "ESPUI"; // Store UI Title and Header Name
Control* controls = nullptr; Control* controls = nullptr;
void jsonDom( AsyncWebSocketClient* client ); void jsonDom(AsyncWebSocketClient* client);
Verbosity verbosity; Verbosity verbosity;
private: private:
const char* basicAuthUsername = nullptr; const char* basicAuthUsername = nullptr;
const char* basicAuthPassword = nullptr; const char* basicAuthPassword = nullptr;
bool basicAuth = true; bool basicAuth = true;
AsyncWebServer* server; AsyncWebServer* server;
AsyncWebSocket* ws; AsyncWebSocket* ws;
}; };
extern ESPUIClass ESPUI; extern ESPUIClass ESPUI;
#endif #endif