implemented guiDrawButton()

This commit is contained in:
Tectu 2012-06-07 19:01:37 +02:00
parent c7eddd1bf3
commit 8c95db3a79
2 changed files with 36 additions and 4 deletions

30
gui.c
View File

@ -6,7 +6,16 @@
volatile uint16_t x, y; volatile uint16_t x, y;
static WORKING_AREA(waTouchPadThread, 512); static msg_t buttonThread(struct buttonStruct_t *a) {
while(TRUE) {
if(x >= a->x0 && x <= a->x1 && y >= a->y0 && y <= a->y1)
*(a->state) = 1;
else
*(a->state) = 0;
chThdSleepMilliseconds(50);
}
}
static msg_t TouchPadThread(void *arg) { static msg_t TouchPadThread(void *arg) {
(void)arg; (void)arg;
unsigned char buffer[10]; unsigned char buffer[10];
@ -30,10 +39,25 @@ static msg_t TouchPadThread(void *arg) {
void guiInit(void) { void guiInit(void) {
chThdCreateStatic(TouchPadThread, sizeof(TouchPadThread), HIGHPRIO, TouchPadThread, NULL); Thread *tp = NULL;
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), HIGHPRIO-1, TouchPadThread, NULL);
} }
void guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state) { Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state) {
struct buttonStruct_t *buttonStruct;
Thread *tp = NULL;
buttonStruct = chHeapAlloc(NULL, sizeof(struct buttonStruct_t));
buttonStruct->x0 = 100;
buttonStruct->y0 = 100;
buttonStruct->x1 = 200;
buttonStruct->y1 = 200;
buttonStruct->state = state;
lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor);
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(128), NORMALPRIO+1, buttonThread, buttonStruct);
return tp;
} }

10
gui.h
View File

@ -1,7 +1,15 @@
#ifndef GUI_H #ifndef GUI_H
#define GUI_H #define GUI_H
void guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state); struct buttonStruct_t {
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
uint8_t *state;
};
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state);
#endif #endif