GithubHelp home page GithubHelp logo

zakimadaoui / guiconnecthelper Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 3.0 2.38 MB

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

License: MIT License

C 100.00%
arduino stm32 embedded embedded-systems embeddedlinux esp esp32 esp8266 microcontroller pic

guiconnecthelper's Introduction

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

guiconnecthelper's People

Contributors

zakimadaoui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

guiconnecthelper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.