Jump to content

How can I pass a text from another chibios thread ?


Recommended Posts

Posted

If GDISP_NEED_MULTITHREAD is set to TRUE in your gfxconf.h then ugfx is fully re-entrant. Just use the standard gdispDrawStringBox or any other gdisp or gwin text api call on any thread and it all should just work.

If you are looking at a simple way to periodically update something in the background, have a look at GTIMER which can provide a callback (automatically on another thread) either one - off after a delay or periodically.

Posted

thank you very much :),

now, I'm able to retreive the data and update it in the screen, but in the reverse way I can't.

I'm using Hy-mini32D and I want to light on a led on the PORTE when I click on a button, using chibios alone, I can flush all the leds without problems, but when I use ugfx I cannot do that.

Could you please help me to resolve this issue ?

Posted

Simply light up the LED in the event loop where you check which button was pressed:


switch(pe->type) {
case GEVENT_GWIN_BUTTON:
if (((GEventGWinButton*)pe)->gwin == ghButtonOn) { // Turn on the LED
palClearPad(GPIOB, 1);
} else if (((GEventGWinButton*)pe)->gwin == ghButtonOff) { // Turn of the LED
palSetPad(GPIOB, 1);
}
break;

default:
break;
}

~ Tectu

Posted

Thank you Tectu,

The led within the kit is working fine, but the other pads don't work, even from other threads, I made a simple example as following, as result the led within the kit blinks but the other output which are also connected to led dont do.

Please help me to correct the problem.

Blink thread


static WORKING_AREA(mythreadblinkLED1, 100);
static msg_t Thread1(void *arg) {

(void)arg;
chRegSetThreadName("blinker");

while (TRUE) {
sysLock();
palClearPad(GPIOB, 0);
palClearPad(GPIOE,12);
palClearPad(GPIOE,13);
palClearPad(GPIOE,14);
palClearPad(GPIOE,15);
chThdSleepMilliseconds(500);
palSetPad(GPIOB, 0);
palSetPad(GPIOE,12);
palSetPad(GPIOE,13);
palSetPad(GPIOE,14);
palSetPad(GPIOE,15);
chThdSleepMilliseconds(500);
sysUnlock();
}
}

The main is simple and without events :




halInit();
chSysInit();
palSetPadMode(GPIOE, 12, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOE, 13, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOE, 14, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOE, 15, PAL_MODE_OUTPUT_PUSHPULL);
GEvent* pe;
gfxInit();
gwinSetDefaultFont(gdispOpenFont("UI2"));
gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
gdispClear(White);
gwinAttachMouse(0);
createWidgets();
geventListenerInit(&gl);
gwinAttachListener(&gl);

chThdCreateStatic(mythreadblinkLED1, sizeof(mythreadblinkLED1), NORMALPRIO, Thread1, NULL);

while(1) {

pe = geventEventWait(&gl, TIME_INFINITE);

switch(pe->type) {
case GEVENT_GWIN_BUTTON:
break;

default:
break;
}
}

return 0;

Thanks in advance!!

Posted

Looking at your blink thread, you are doing a couple of wait's inside a kernel locked region. That is a definite no-no.

make sure there are no sleeps inside the lock/unlock pair and try again.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...