diff --git a/aREST_UI.h b/aREST_UI.h index 6a23d48..5f658f4 100644 --- a/aREST_UI.h +++ b/aREST_UI.h @@ -28,6 +28,21 @@ aREST_UI() { } +typedef struct { + String function_name; + String description; +} function_button_t; + +typedef enum { + TYPE_BUTTON=0, + TYPE_FUNCTION_BUTTON, + TYPE_FUNCTION_WITH_INPUT_BUTTON, + TYPE_SLIDER, + TYPE_VARIABLE_LABEL, + TYPE_LABEL +} ui_type_t; + + // Get title void title(String the_title) { ui_title = the_title; @@ -43,6 +58,41 @@ void button(int pin){ buttons[buttons_index] = pin; buttons_index++; + // Set in the ui_order_list + ui_order_list[ui_order_index] = TYPE_BUTTON; + ui_order_index++; +} + +// Create function button +void function_button(char *function_name, char *description, int (*f)(String)){ + + // Setup function + aREST::function(function_name, f); + + // Set in function button array + function_buttons[function_buttons_index].function_name = String(function_name); + function_buttons[function_buttons_index].description = String(description); + function_buttons_index++; + + // Set in the ui_order_list + ui_order_list[ui_order_index] = TYPE_FUNCTION_BUTTON; + ui_order_index++; +} + +// Create function button +void function_with_input_button(char *function_name, char *description, int (*f)(String)){ + + // Setup function + aREST::function(function_name, f); + + // Set in function with input button array + func_with_input_buttons[func_with_input_buttons_index].function_name = String(function_name); + func_with_input_buttons[func_with_input_buttons_index].description = String(description); + func_with_input_buttons_index++; + + // Set in the ui_order_list + ui_order_list[ui_order_index] = TYPE_FUNCTION_WITH_INPUT_BUTTON; + ui_order_index++; } void slider(int pin) { @@ -54,14 +104,148 @@ void slider(int pin) { sliders[sliders_index] = pin; sliders_index++; + // Set in the ui_order_list + ui_order_list[ui_order_index] = TYPE_SLIDER; + ui_order_index++; +} + +void variable_label(char *variable_name, char *label_text, int *var){ + + // Initialize var + aREST::variable(variable_name, var); + variable_label_add(variable_name, label_text); +} + +// Float variables (Mega & ESP only, or without CC3000) +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(ESP8266) || defined(CORE_WILDFIRE) || !defined(ADAFRUIT_CC3000_H) +void variable_label(char *variable_name, char *label_text, float *var){ + + // Initialize variable + aREST::variable(variable_name, var); + variable_label_add(variable_name, label_text); +} +#endif + +// String variables (Mega & ESP only, or without CC3000) +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(ESP8266) || defined(CORE_WILDFIRE) || !defined(ADAFRUIT_CC3000_H) +void variable_label(char *variable_name, char *label_text, String *var){ + + // Initialize var + aREST::variable(variable_name, var); + variable_label_add(variable_name, label_text); +} +#endif + +// Create variable label +void variable_label_add(char *variable_name, char *label_text){ + + var_labels_names[var_labels_index] = variable_name; + var_labels_text[var_labels_index] = label_text; + var_labels_index++; + + // Set in the ui_order_list + ui_order_list[ui_order_index] = TYPE_VARIABLE_LABEL; + ui_order_index++; } // Create label -void label(char * label_name){ +void label(char *label_text, bool small_text=false){ + + labels_text[labels_index] = label_text; + labels_text_should_be_small[labels_index] = small_text; + labels_index++; + + // Set in the ui_order_list + ui_order_list[ui_order_index] = TYPE_LABEL; + ui_order_index++; +} + +void add_next_button() { + addToBuffer("