I am attempting to create a thread which would execute functions from the gfx library. What is happening is that when I run the functions in the main thread everything executes correctly, as soon as I implement this code in a static thread the system hangs. Initially while in normal priority nothing would display, and then when I gave the thread high priority it would display a frame. However after displaying the frame the system hangs and is not capable of taking in touch input. I am unsure of if this is based on the way I am implementing the thread or is it because of what the thread is responsible for (ugfx functions).
Below is my main file which initializes and calls the thread, "mythread".
Code: Select all
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#include "nfc.h"
#include "test.h"
#include "string.h"
#include <stdio.h>
#include "GUI.h"
static GHandle ghAccounts,ghExit,ghConsole;
static GListener gl;
static GEvent *pe;
static void createWidgets(void) {
// Apply the console parameters
uint8_t width = 192;
uint8_t height = 200;
uint8_t y = 100;
uint8_t x = 20;
font_t font = gdispOpenFont("Small Narrow");
// Create the actual console
ghConsole = gwinCreateConsole(NULL,x,y,width,height,font);
// Set the console fore- and background colors
gwinSetColor(ghConsole, Yellow);
gwinSetBgColor(ghConsole, Black);
// Clear the console
gwinClear(ghConsole);
}
void ghConsoleprint(const char *fmt){
gwinPrintf(ghConsole, fmt) ;
}
void GUI_init(void) {
//GSourceHandle gs;
/* initialize the LCD */
gfxInit();
//gdispClear(Black);
/* Initialize the mouse -- mouse refers to touch */
geventListenerInit(&gl);
//gs = ginputGetMouse(0);
ginputGetMouse(0);
}
void testScreen(void){
//coord_t swidth, sheight;
//GHandle ghc;
font_t font;
GButtonObject gAccounts;
GButtonObject gExit;
GSourceHandle gsAccounts, gsExit;
/* Get the display dimensions */
//swidth = gdispGetWidth();
//sheight = gdispGetHeight();
ghAccounts = ghExit = 0;
/* choose our font */
font = gdispOpenFont("Larger Double");
/**********************************************************/
/**change position of objects based on swidth and sheight**/
/**********************************************************/
/* create the "exit" button */
ghExit = gwinCreateButton(&gExit, 10, 50, 100, 50, font, GBTN_NORMAL);
gwinSetButtonText(ghExit, "Exit", FALSE);
gsExit = gwinGetButtonSource(ghExit);
geventAttachSource(&gl, gsExit, 0);
gwinAttachButtonMouse(ghExit, 0);
/* create the "Accounts" button */
ghAccounts = gwinCreateButton(&gAccounts, 130, 50, 100, 50, font, GBTN_NORMAL);
gwinSetButtonText(ghAccounts, "Accounts", FALSE);
gsAccounts = gwinGetButtonSource(ghAccounts);
geventAttachSource(&gl, gsAccounts, 0);
gwinAttachButtonMouse(ghAccounts, 0);
/* draw the buttons */
gwinButtonDraw(ghExit);
gwinButtonDraw(ghAccounts);
// Create the widget
createWidgets();
while(TRUE){
GEventGWinButton *peb;
pe = geventEventWait(&gl, TIME_INFINITE);
if(pe->type == GEVENT_GWIN_BUTTON){
peb = (GEventGWinButton *)pe;
if (peb->button == ghAccounts) { gwinPrintf(ghConsole, "Accounts\r\n");}
else if (peb->button == ghExit) { gwinPrintf(ghConsole, "Exit\r\n");}
//else {return BTN_NONE;}
}
}
}
static WORKING_AREA(myThreadWorkingArea, 100000);
static msg_t myThread(void *arg) {
uint8_t buttonpress=0;
GUI_init();
testScreen();
while(TRUE) {
ghConsoleprint("Welcome to the G");
buttonpress=whichbuttonpressed2();
ghConsoleprint("WIN c");
if (buttonpress == BTN_ACCOUNTS) {
palSetPad(GPIOD, GPIOD_LED3); /* Orange*/
ghConsoleprint("Welcome to the GWIN console!\r\n");
}
else if (buttonpress == BTN_EXIT)
palClearPad(GPIOD, GPIOD_LED3); /* Orange*/
}
}
int main(void) {
/* initialize the hardware and the OS */
halInit();
chSysInit();
(void)chThdCreateStatic(myThreadWorkingArea,
sizeof(myThreadWorkingArea),
HIGHPRIO, /* Initial priority. */
myThread, /* Thread function. */
NULL);
return 0;
}