From 94e949bd630e84d18bc1539ba2007b9424dd996f Mon Sep 17 00:00:00 2001 From: Tectu Date: Sat, 9 Jun 2012 15:41:28 +0200 Subject: [PATCH] added not working guiDrawKeymatrix() --- glcd.h | 2 +- gui.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++------- gui.h | 26 ++++++++++++-- 3 files changed, 123 insertions(+), 17 deletions(-) diff --git a/glcd.h b/glcd.h index bc5064c6..4ad21e42 100644 --- a/glcd.h +++ b/glcd.h @@ -1,7 +1,7 @@ #ifndef GLCD_H #define GLCD_H -#include // types +#include #include #define SCREEN_WIDTH 240 diff --git a/gui.c b/gui.c index 10c5a72d..114979cc 100644 --- a/gui.c +++ b/gui.c @@ -6,13 +6,64 @@ volatile uint16_t x, y; -static msg_t buttonThread(struct buttonStruct_t *a) { +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; + while(TRUE) { - if(x >= a->x0 && x <= a->x1 && y >= a->y0 && y <= a->y1) + if(x >= x0 && x <= x1 && y >= y0 && y <= y1) *(a->state) = 1; else *(a->state) = 0; - chThdSleepMilliseconds(50); + + chThdSleepMilliseconds(a->interval); + } +} + +static msg_t keymatrixThread(struct keymatrix_t *a) { + uint16_t i, x0, y0, size, off; + + x0 = a->x0; + y0 = a->y0; + off = a->off; + size = a->size; + memset(a->number, 0, sizeof(a->number)); + + while(TRUE) { + + for(i = 0; i < a->digits; i++) { + while(tpIRQ()); + if(x >= x0 && x <= x0+size && y >= y0 && y <= y0+size) + a->number[i] = 7; + else if(x >= x0+off && x <= x0+off+size && y >= y0 && y <= y0+size) + a->number[i] = 8; + else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0 && y <= y0+size) + a->number[i] = 9; + else if(x >= x0 && x <= x0+size && y >= y0+off && y <= y0+off+size) + a->number[i] = 4; + else if(x >= x0+off && x <= x0+off+size && y >= y0+off && y <= y0+off+size) + a->number[i] = 5; + else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0+off && y <= y0+off+size) + a->number[i] = 6; + else if(x >= x0 && x <= x0+size && y >= y0+off+off && y <= y0+off+off+size) + a->number[i] = 1; + else if(x >= x0+off && x <= x0+off+size && y >= y0+off+off && y <= y0+off+off+size) + a->number[i] = 2; + else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0+off+off && y <= y0+off+off+size) + a->number[i] = 3; + else if(x >= x0 && x <= x0+size && y >= y0+off+off+off && y <= y0+off+off+off+size) + a->number[i] = 0; + else if(x >= x0+off && x <= x0+off+size && y >= y0+off+off+off && y <= y0+off+off+off+size) + a->number[i] = 0; + else if(x >= x0+off+off && x <= x0+off+off+size && y >= y0+off+off+off && y <= y0+off+off+off+size) + a->number[i] = 0; + while(!tpIRQ()); + chThdSleepMilliseconds(a->interval); + } } } @@ -33,20 +84,55 @@ void guiInit(uint16_t updateInterval) { tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval); } -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 *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; Thread *tp = NULL; - buttonStruct = chHeapAlloc(NULL, sizeof(struct buttonStruct_t)); - - buttonStruct->x0 = x0; - buttonStruct->y0 = y0; - buttonStruct->x1 = x1; - buttonStruct->y1 = y1; - buttonStruct->state = state; + 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; lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); - tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO+1, buttonThread, buttonStruct); + tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), NORMALPRIO, buttonThread, button); + + return tp; +} + +Thread *guiDrawKeymatrix(uint16_t x0, uint16_t y0, uint16_t size, uint16_t space, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint16_t digits, uint32_t *number) { + struct keymatrix_t *keymatrix; + Thread *tp = NULL; + uint16_t off; + uint8_t i, j; + + off = size+space; + + keymatrix = chHeapAlloc(NULL, sizeof(struct keymatrix_t)); + keymatrix->x0 = x0; + keymatrix->y0 = y0; + keymatrix->off = off; + keymatrix->size = size; + keymatrix->digits = digits; + keymatrix->number = number; + keymatrix->interval = interval; + + lcdDrawRectString(x0, y0, x0+size, y0+size, "7", fontColor, buttonColor); + lcdDrawRectString(x0+off, y0, x0+off+size, y0+size, "8", fontColor, buttonColor); + lcdDrawRectString(x0+off+off, y0, x0+off+off+size, y0+size, "9", fontColor, buttonColor); + lcdDrawRectString(x0, y0+off, x0+size, y0+off+size, "4", fontColor, buttonColor); + lcdDrawRectString(x0+off, y0+off, x0+off+size, y0+off+size, "5", fontColor, buttonColor); + lcdDrawRectString(x0+off+off, y0+off, x0+off+off+size, y0+off+size, "6", fontColor, buttonColor); + lcdDrawRectString(x0, y0+off+off, x0+size, y0+off+off+size, "1", fontColor, buttonColor); + lcdDrawRectString(x0+off, y0+off+off, x0+off+size, y0+off+off+size, "2", fontColor, buttonColor); + lcdDrawRectString(x0+off+off, y0+off+off, x0+off+off+size, y0+off+off+size, "3", fontColor, buttonColor); + lcdDrawRectString(x0, y0+off+off+off, x0+size, y0+off+off+off+size, "*", fontColor, buttonColor); + lcdDrawRectString(x0+off, y0+off+off+off, x0+off+size, y0+off+off+off+size, "0", fontColor, buttonColor); + lcdDrawRectString(x0+off+off, y0+off+off+off, x0+off+off+size, y0+off+off+off+size, "#", fontColor, buttonColor); + + tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, keymatrixThread, keymatrix); return tp; } diff --git a/gui.h b/gui.h index 21b9e5b4..8589edca 100644 --- a/gui.h +++ b/gui.h @@ -1,12 +1,23 @@ #ifndef GUI_H #define GUI_H -struct buttonStruct_t { +struct button_t { uint16_t x0; uint16_t y0; uint16_t x1; uint16_t y1; - uint8_t *state; + uint32_t *state; + uint16_t interval; +}; + +struct keymatrix_t { + uint16_t x0; + uint16_t y0; + uint16_t off; + uint16_t size; + uint16_t digits; + uint32_t *number; + uint16_t interval; }; /* @@ -31,7 +42,16 @@ void guiInit(uint16_t updateIntervl); * * return: pointer to created thread */ -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); +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 inverval, uint8_t *state); + +/* + * Description: draws keymatrix + * + * param: + * + * return: pointer to created thread + */ +Thread *guiDrawKeymatrix(uint16_t x0, uint16_t y0, uint16_t size, uint16_t space, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint16_t digits, uint32_t *number); #endif