Skip to content

A helper library for GuiConnect+: a quick GUI creator for microcontroller projects

License

Notifications You must be signed in to change notification settings

zakimadaoui/GuiConnectHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GuiConnectHelper library

This is a helper library for GuiConnect+: a quick GUI creator for microcontroller projects

banner


Demo

Tutorials

GuiConnectHelper Documentation

GCH_init()

Description

Constructor function to initialize the state and register the callback function.

Syntax

void GCH_init(GuiConnectHelper* handle, GCHCallbackHandler callback)

Parameters

handle: a pointer to a GuiConnectHelper instance.
callback: pointer to a callback function which is called each time a command is fully recieved.

Example Code

#include"GuiConnectHelper.h"

GuiConnectHelper gcHandle;
void onCommandRecieved(){
    //callback code here
}

void setup(){
    //init and register the callback
	GCH_init(&gcHandle, onCommandRecieved);
}

GCH_loadNextbyte()

Description

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.

Syntax

void GCH_loadNextbyte(GuiConnectHelper* handle, uint8_t byte)

Parameters

handle: a pointer to a GuiConnectHelper instance.
byte: a byte received from GuiConnect+ application through a certain connection (TCP/IP, UART, BT).

Example Code

void loop(){
	//load any newly available data from serial
	while(Serial.available()) {
        GCH_loadNextbyte(&gcHandle, Serial.read());
    }

    //other non blocking code......
}

GCH_GetStrCommandName()

Description

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.

Syntax

char* GCH_GetStrCommandName(GuiConnectHelper* handle);

Parameters

handle: a pointer to a GuiConnectHelper instance.

Example Code

#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
	}//......
}

GCH_GetCharCommandName()

Description

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.

Syntax

char GCH_GetCharCommandName(GuiConnectHelper* handle);

Parameters

handle: a pointer to a GuiConnectHelper instance.

Example Code

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 ....*/

	}
  
}

GCH_getParamsNbr()

Description

returns the nbr of parameters of the received command.

Syntax

uint8_t GCH_getParamsNbr(GuiConnectHelper *handle)

Parameters

handle: a pointer to a GuiConnectHelper instance.

Example Code

int paramsNbr = GCH_getParamsNbr(&gcHandle);

GCH_GetParamAsInt()

GCH_GetParamAslong()

GCH_GetParamAsChar()

GCH_GetParamAsString()

GCH_GetParamAsFloat()

Description

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.

Syntax

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);

Parameters

h: a pointer to a GuiConnectHelper instance.
param_index: index of the desired command parameter. Note that the first index is always 0.

Example Code

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

Releases

No releases published

Packages

No packages published

Languages