This is a helper library for GuiConnect+: a quick GUI creator for microcontroller projects
- Getting started with GuiConnect+: blinky example
- Creating custom commands and using constant parameters with a servo robot arm example
Constructor function to initialize the state and register the callback function.
void GCH_init(GuiConnectHelper* handle, GCHCallbackHandler callback)
handle: a pointer to a GuiConnectHelper instance.
callback: pointer to a callback function which is called each time a command is fully recieved.
#include"GuiConnectHelper.h"
GuiConnectHelper gcHandle;
void onCommandRecieved(){
//callback code here
}
void setup(){
//init and register the callback
GCH_init(&gcHandle, onCommandRecieved);
}
This function must be called every time some new bytes are received from the GuiConnect+ application. You should use this in your super loop if there is no blocking code inside, or preferably in an ISR (like a UART isr), Or use a separate task for it if you are using an RTOS.
void GCH_loadNextbyte(GuiConnectHelper* handle, uint8_t byte)
handle: a pointer to a GuiConnectHelper instance.
byte: a byte received from GuiConnect+ application through a certain connection (TCP/IP, UART, BT).
void loop(){
//load any newly available data from serial
while(Serial.available()) {
GCH_loadNextbyte(&gcHandle, Serial.read());
}
//other non blocking code......
}
This must be called within the callback function. It returns the received command name as a character sequence (string). Please do not call free() on the returned data.
char* GCH_GetStrCommandName(GuiConnectHelper* handle);
handle: a pointer to a GuiConnectHelper instance.
#include "string.h"
void onCommandRecieved(){
char* cmdName = GCH_GetStrCommandName(&gcHandle);
if(strcmp(cmdName, "cmd-name1") == 0){
//do something
}
else if(strcmp(cmdName, "cmd-name2") == 0){
//do something
}//......
}
Same as the previous one, but returns a single character instead of a string. This is very useful if all your commands use a single character as a command name.
char GCH_GetCharCommandName(GuiConnectHelper* handle);
handle: a pointer to a GuiConnectHelper instance.
void onCommandRecieved(){
char cmdName = GCH_GetCharCommandName(&gcHandle)
switch (cmdName){
case 'k': // a knob was rotated
/*do something...*/
break;
case 'b': // a button was clicked
/*do something...*/
break;
case 's': // a switch was toggled
/*do something...*/
break;
/*and so on ....*/
}
}
returns the nbr of parameters of the received command.
uint8_t GCH_getParamsNbr(GuiConnectHelper *handle)
handle: a pointer to a GuiConnectHelper instance.
int paramsNbr = GCH_getParamsNbr(&gcHandle);
returns one of the received command's parameters. The return type depends on which function is called. In order to know which datatype you should use always refer to the widget documentation specified in the GuiConnect+ app.
int GCH_GetParamAsInt(GuiConnectHelper* h, uint8_t param_index);
long GCH_GetParamAslong(GuiConnectHelper* h, uint8_t param_index);
char GCH_GetParamAsChar(GuiConnectHelper* h, uint8_t param_index);
char* GCH_GetParamAsString(GuiConnectHelper* h, uint8_t param_index);
float GCH_GetParamAsFloat(GuiConnectHelper* h, uint8_t param_index);
h: a pointer to a GuiConnectHelper instance.
param_index: index of the desired command parameter. Note that the first index is always 0.
void onCommandRecieved(){
char cmdName = GCH_GetCharCommandName(&gcHandle);
int angle, servoIndex;
switch (cmdName){
case 'k': // a knob is rotated
servoIndex = GCH_GetParamAsInt(&gcHandle, 0); //get parameter 0 as an integer value
angle = GCH_GetParamAsInt(&gcHandle, 1); //get parameter 1 as an integer value
servo[servoIndex].write(angle);
break;
/*other cases ....*/
}
}
TODO: add demo video