added guiDrawBarGraph()
This commit is contained in:
parent
4cccbb1711
commit
ab38112ed9
2 changed files with 84 additions and 4 deletions
56
gui.c
56
gui.c
|
@ -4,9 +4,10 @@
|
||||||
#include "glcd.h"
|
#include "glcd.h"
|
||||||
#include "touchpad.h"
|
#include "touchpad.h"
|
||||||
|
|
||||||
volatile uint16_t x, y;
|
uint16_t x, y;
|
||||||
|
unsigned char buffer[32];
|
||||||
|
|
||||||
static msg_t buttonThread(struct button_t *a) {
|
static void buttonThread(struct button_t *a) {
|
||||||
uint16_t x0, y0, x1, y1;
|
uint16_t x0, y0, x1, y1;
|
||||||
|
|
||||||
x0 = a->x0;
|
x0 = a->x0;
|
||||||
|
@ -24,7 +25,7 @@ static msg_t buttonThread(struct button_t *a) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static msg_t TouchPadThread(uint16_t updateInterval) {
|
static void TouchPadThread(uint16_t updateInterval) {
|
||||||
chRegSetThreadName("GUI");
|
chRegSetThreadName("GUI");
|
||||||
|
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
|
@ -35,6 +36,32 @@ static msg_t TouchPadThread(uint16_t updateInterval) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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->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;
|
||||||
|
chThdSleepMilliseconds(a->interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void guiInit(uint16_t updateInterval) {
|
void guiInit(uint16_t updateInterval) {
|
||||||
Thread *tp = NULL;
|
Thread *tp = NULL;
|
||||||
|
@ -54,8 +81,29 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign
|
||||||
button->interval = interval;
|
button->interval = interval;
|
||||||
|
|
||||||
lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor);
|
lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor);
|
||||||
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), NORMALPRIO, buttonThread, button);
|
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, buttonThread, button);
|
||||||
|
|
||||||
return tp;
|
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) {
|
||||||
|
struct bar_t *bar;
|
||||||
|
Thread *tp = NULL;
|
||||||
|
|
||||||
|
bar = chHeapAlloc(NULL, sizeof(struct bar_t));
|
||||||
|
bar->x0 = x0;
|
||||||
|
bar->y0 = y0;
|
||||||
|
bar->x1 = x1;
|
||||||
|
bar->y1 = y1;
|
||||||
|
bar->orientation = orientation;
|
||||||
|
bar->frameColor = frameColor;
|
||||||
|
bar->bkColor = bkColor;
|
||||||
|
bar->valueColor = valueColor;
|
||||||
|
bar->percent = percent;
|
||||||
|
bar->interval = interval;
|
||||||
|
|
||||||
|
lcdDrawRect(x0, y0, x1, y1, frame, frameColor);
|
||||||
|
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, barThread, bar);
|
||||||
|
|
||||||
|
return tp;
|
||||||
|
}
|
||||||
|
|
32
gui.h
32
gui.h
|
@ -10,6 +10,21 @@ struct button_t {
|
||||||
uint16_t interval;
|
uint16_t interval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct bar_t {
|
||||||
|
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 *percent;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {horizontal, vertical};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description: starts main GUI thread which keeps X and Y coordinates of touchpad updated for guiDraw() threads
|
* Description: starts main GUI thread which keeps X and Y coordinates of touchpad updated for guiDraw() threads
|
||||||
*
|
*
|
||||||
|
@ -28,11 +43,28 @@ void guiInit(uint16_t updateIntervl);
|
||||||
* - str: string written centered into button
|
* - str: string written centered into button
|
||||||
* - fontColor: color of string
|
* - fontColor: color of string
|
||||||
* - buttonColor: color of button
|
* - buttonColor: color of button
|
||||||
|
* - interval: interval in ms which updates state
|
||||||
* - state: pointer to variable which keeps state (1 = pressed, 0 = unpressed)
|
* - state: pointer to variable which keeps state (1 = pressed, 0 = unpressed)
|
||||||
*
|
*
|
||||||
* return: pointer to created thread
|
* 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 *state);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Description: draws a bar graph and updates it's value
|
||||||
|
*
|
||||||
|
* param:
|
||||||
|
* - x0, y0, x1, y1: coordinates where bar graph gets drawn
|
||||||
|
* - orientation: horizontal or vertical
|
||||||
|
* - frameColor: color of the frame
|
||||||
|
* - bkColor: color of piece inside bar with is not set
|
||||||
|
* - valueColor: color of value that will be drawn into bar
|
||||||
|
* - interval: interval in ms which updates percentage
|
||||||
|
* - percent: pointer value from 0 to 100 percent
|
||||||
|
*
|
||||||
|
* 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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue