GUI threads do now take active/inactive state

This commit is contained in:
Tectu 2012-06-25 10:40:05 +02:00
parent e543f15633
commit 7401ade97d
2 changed files with 36 additions and 24 deletions

51
gui.c
View File

@ -27,10 +27,14 @@ static void buttonThread(struct button_t *a) {
y1 = a->y1;
while(TRUE) {
if(x >= x0 && x <= x1 && y >= y0 && y <= y1)
*(a->state) = 1;
else
if(*(a->active) == active) {
if(x >= x0 && x <= x1 && y >= y0 && y <= y1)
*(a->state) = 1;
else
*(a->state) = 0;
} else {
*(a->state) = 0;
}
chThdSleepMilliseconds(a->interval);
}
@ -40,25 +44,28 @@ static void barThread(struct bar_t *a) {
uint16_t percent = 0, value = 0, value_old = 0;
while(TRUE) {
percent = *(a->percent);
if(percent > 100)
percent = 100;
if(*(a->active) == active) {
percent = *(a->percent);
if(percent > 100)
percent = 100;
if(a->orientation == horizontal) {
value = ((((a->x1)-(a->x0)) * percent) / 100);
if(value_old > value || value == 0)
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
else
lcdDrawRect(a->x0+1, a->y0+1, a->x0+value, a->y1, filled, a->valueColor);
} else if(a->orientation == vertical) {
value = ((((a->y1)-(a->y0)) * percent) / 100);
if(value_old > value || value == 0)
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
else
lcdDrawRect(a->x0+1, a->y0+1, a->x1, a->y0+value, filled, a->valueColor);
if(a->orientation == horizontal) {
value = ((((a->x1)-(a->x0)) * percent) / 100);
if(value_old > value || value == 0)
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
else
lcdDrawRect(a->x0+1, a->y0+1, a->x0+value, a->y1, filled, a->valueColor);
} else if(a->orientation == vertical) {
value = ((((a->y1)-(a->y0)) * percent) / 100);
if(value_old > value || value == 0)
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
else
lcdDrawRect(a->x0+1, a->y0+1, a->x1, a->y0+value, filled, a->valueColor);
}
value_old = value;
}
value_old = value;
chThdSleepMilliseconds(a->interval);
}
}
@ -68,7 +75,7 @@ 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, uint16_t interval, 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 interval, uint8_t *active, uint8_t *state) {
struct button_t *button;
Thread *tp = NULL;
@ -78,6 +85,7 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign
button->x1 = x1;
button->y1 = y1;
button->state = state;
button->active = active;
button->interval = interval;
lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor);
@ -86,7 +94,7 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign
return tp;
}
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint16_t *percent) {
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint8_t *active, uint16_t *percent) {
struct bar_t *bar;
Thread *tp = NULL;
@ -101,6 +109,7 @@ Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint
bar->valueColor = valueColor;
bar->percent = percent;
bar->interval = interval;
bar->active = active;
lcdDrawRect(x0, y0, x1, y1, frame, frameColor);
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, barThread, bar);

9
gui.h
View File

@ -6,7 +6,8 @@ struct button_t {
uint16_t y0;
uint16_t x1;
uint16_t y1;
uint32_t *state;
uint8_t *state;
uint8_t *active;
uint16_t interval;
};
@ -21,9 +22,11 @@ struct bar_t {
uint16_t valueColor;
uint16_t interval;
uint8_t *percent;
uint8_t *active;
};
enum {horizontal, vertical};
enum {inactive, active};
#ifdef __cplusplus
extern "C" {
@ -53,7 +56,7 @@ 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, uint16_t inverval, 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 *active, uint8_t *state);
/*
* Description: draws a bar graph and updates it's value
@ -69,7 +72,7 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign
*
* return : pointer to created thread
*/
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint16_t *percent);
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint8_t *active, uint16_t *percent);
#ifdef __cplusplus
}