ugfx/gui.c

62 lines
1.3 KiB
C
Raw Normal View History

2012-06-07 12:37:29 +00:00
#include "ch.h"
#include "hal.h"
#include "gui.h"
#include "glcd.h"
#include "touchpad.h"
volatile uint16_t x, y;
2012-06-09 13:41:28 +00:00
static msg_t buttonThread(struct button_t *a) {
uint16_t x0, y0, x1, y1;
x0 = a->x0;
y0 = a->y0;
x1 = a->x1;
y1 = a->y1;
2012-06-07 17:01:37 +00:00
while(TRUE) {
2012-06-09 13:41:28 +00:00
if(x >= x0 && x <= x1 && y >= y0 && y <= y1)
2012-06-07 17:01:37 +00:00
*(a->state) = 1;
else
*(a->state) = 0;
2012-06-09 13:41:28 +00:00
chThdSleepMilliseconds(a->interval);
}
}
2012-06-07 21:48:51 +00:00
static msg_t TouchPadThread(uint16_t updateInterval) {
2012-06-07 12:37:29 +00:00
chRegSetThreadName("GUI");
while(TRUE) {
2012-06-07 17:06:13 +00:00
x = tpReadX();
y = tpReadY();
2012-06-07 12:37:29 +00:00
2012-06-07 21:48:51 +00:00
chThdSleepMilliseconds(updateInterval);
2012-06-07 12:37:29 +00:00
}
}
2012-06-07 21:48:51 +00:00
void guiInit(uint16_t updateInterval) {
2012-06-07 17:01:37 +00:00
Thread *tp = NULL;
2012-06-07 21:48:51 +00:00
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval);
2012-06-07 12:37:29 +00:00
}
2012-06-09 13:41:28 +00:00
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *state) {
struct button_t *button;
2012-06-07 17:01:37 +00:00
Thread *tp = NULL;
2012-06-09 13:41:28 +00:00
button = chHeapAlloc(NULL, sizeof(struct button_t));
button->x0 = x0;
button->y0 = y0;
button->x1 = x1;
button->y1 = y1;
button->state = state;
button->interval = interval;
2012-06-07 17:01:37 +00:00
2012-06-07 12:37:29 +00:00
lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor);
2012-06-09 13:41:28 +00:00
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), NORMALPRIO, buttonThread, button);
return tp;
}