2012-06-07 12:37:29 +00:00
|
|
|
#include "gui.h"
|
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
static struct guiNode_t *firstGUI = NULL;
|
2012-06-07 12:37:29 +00:00
|
|
|
|
2012-06-27 08:11:42 +00:00
|
|
|
static uint8_t addElement(struct guiNode_t *newNode) {
|
2012-06-26 10:47:25 +00:00
|
|
|
struct guiNode_t *new;
|
2012-06-09 17:29:56 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
if(firstGUI == NULL) {
|
|
|
|
firstGUI = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
|
|
|
if(firstGUI == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*firstGUI = *newNode;
|
|
|
|
firstGUI->next = NULL;
|
|
|
|
} else {
|
|
|
|
new = firstGUI;
|
|
|
|
while(new->next != NULL)
|
|
|
|
new = new->next;
|
2012-06-09 17:29:56 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
new->next = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
|
|
|
if(new->next == NULL)
|
|
|
|
return 0;
|
2012-06-09 17:29:56 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
new = new->next;
|
|
|
|
*new = *newNode;
|
|
|
|
new->next = NULL;
|
2012-06-09 17:29:56 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
return 1;
|
2012-06-09 17:29:56 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 08:23:42 +00:00
|
|
|
static uint8_t deleteElement(char *label) {
|
2012-06-26 10:47:25 +00:00
|
|
|
struct guiNode_t *pointer, *pointer1;
|
2012-06-09 13:41:28 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
if(firstGUI != NULL) {
|
2012-06-27 08:23:42 +00:00
|
|
|
if(strcmp(firstGUI->label, label) == 0) {
|
2012-06-26 10:47:25 +00:00
|
|
|
pointer = firstGUI->next;
|
2012-06-26 14:22:08 +00:00
|
|
|
chHeapFree(firstGUI);
|
2012-06-26 10:47:25 +00:00
|
|
|
firstGUI = pointer;
|
2012-06-25 08:40:05 +00:00
|
|
|
} else {
|
2012-06-26 10:47:25 +00:00
|
|
|
pointer = firstGUI;
|
2012-06-09 13:41:28 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
while(pointer->next != NULL) {
|
|
|
|
pointer1 = pointer->next;
|
2012-06-09 13:41:28 +00:00
|
|
|
|
2012-06-27 08:23:42 +00:00
|
|
|
if(strcmp(firstGUI->label, label) == 0) {
|
2012-06-26 10:47:25 +00:00
|
|
|
pointer->next = pointer1->next;
|
2012-06-26 14:22:08 +00:00
|
|
|
chHeapFree(pointer1);
|
2012-06-26 10:47:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-06-09 13:41:28 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
pointer = pointer1;
|
2012-06-25 08:40:05 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
}
|
2012-06-09 17:29:35 +00:00
|
|
|
}
|
2012-06-27 08:10:45 +00:00
|
|
|
|
|
|
|
return 1; // successful
|
2012-06-09 13:41:28 +00:00
|
|
|
}
|
2012-06-27 08:10:45 +00:00
|
|
|
|
|
|
|
return 0; // not successful
|
2012-06-09 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 08:11:42 +00:00
|
|
|
void guiPrintElements(BaseSequentialStream *chp) {
|
2012-06-26 10:47:25 +00:00
|
|
|
struct guiNode_t *pointer = firstGUI;
|
|
|
|
|
|
|
|
chprintf(chp, "\r\n\nguiNodes:\r\n\n");
|
|
|
|
|
|
|
|
while(pointer != NULL) {
|
|
|
|
chprintf(chp, "x0: %d\r\n", pointer->x0);
|
|
|
|
chprintf(chp, "y0: %d\r\n", pointer->y0);
|
|
|
|
chprintf(chp, "x1: %d\r\n", pointer->x1);
|
|
|
|
chprintf(chp, "y1: %d\r\n", pointer->y1);
|
2012-06-27 08:23:42 +00:00
|
|
|
chprintf(chp, "label: %s\r\n", pointer->label);
|
2012-06-26 11:44:10 +00:00
|
|
|
chprintf(chp, "active: %d\r\n", *(pointer->active));
|
|
|
|
chprintf(chp, "state: %d\r\n", *(pointer->state));
|
2012-06-26 10:47:25 +00:00
|
|
|
chprintf(chp, "*next: 0x%x\r\n", pointer->next);
|
|
|
|
chprintf(chp, "\r\n\n");
|
|
|
|
pointer = pointer->next;
|
|
|
|
}
|
2012-06-07 12:37:29 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
static void guiThread(const uint16_t interval) {
|
|
|
|
uint16_t x, y;
|
|
|
|
struct guiNode_t *node;
|
2012-06-07 17:01:37 +00:00
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
chRegSetThreadName("GUI");
|
2012-06-09 17:29:35 +00:00
|
|
|
|
|
|
|
while(TRUE) {
|
2012-06-26 11:16:36 +00:00
|
|
|
for(node = firstGUI; node; node = node->next) {
|
2012-06-26 19:17:50 +00:00
|
|
|
// check if GUI element is active
|
2012-06-26 11:16:36 +00:00
|
|
|
if(*(node->active) == active) {
|
|
|
|
x = tpReadX();
|
|
|
|
y = tpReadY();
|
2012-06-26 19:17:50 +00:00
|
|
|
|
|
|
|
// we got a button
|
2012-06-26 18:47:35 +00:00
|
|
|
if(node->type == button) {
|
|
|
|
if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1)
|
|
|
|
*(node->state) = 1;
|
|
|
|
else
|
|
|
|
*(node->state) = 0;
|
|
|
|
} else {
|
2012-06-26 11:16:36 +00:00
|
|
|
*(node->state) = 0;
|
2012-06-26 18:47:35 +00:00
|
|
|
}
|
2012-06-26 19:17:50 +00:00
|
|
|
|
|
|
|
// we got a slider
|
|
|
|
if(node->type == slider) {
|
2012-06-09 17:29:35 +00:00
|
|
|
|
2012-06-26 19:17:50 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 19:43:21 +00:00
|
|
|
// we got a wheel
|
|
|
|
if(node->type == wheel) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-26 19:17:50 +00:00
|
|
|
// we got a keymatrix
|
|
|
|
if(node->type == keymatrix) {
|
|
|
|
|
|
|
|
}
|
2012-06-26 11:16:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
chThdSleepMilliseconds(interval);
|
2012-06-09 17:29:35 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-07 12:37:29 +00:00
|
|
|
|
2012-06-26 11:50:12 +00:00
|
|
|
Thread *guiInit(uint16_t interval, tprio_t priority) {
|
2012-06-07 17:01:37 +00:00
|
|
|
Thread *tp = NULL;
|
2012-06-07 12:37:29 +00:00
|
|
|
|
2012-06-26 11:50:49 +00:00
|
|
|
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), priority, guiThread, interval);
|
2012-06-07 17:01:37 +00:00
|
|
|
|
2012-06-09 17:29:35 +00:00
|
|
|
return tp;
|
|
|
|
}
|
2012-06-07 17:01:37 +00:00
|
|
|
|
2012-06-27 08:23:42 +00:00
|
|
|
uint8_t guiDeleteElement(char *label) {
|
|
|
|
return deleteElement(label);
|
2012-06-27 08:10:45 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 16:51:08 +00:00
|
|
|
uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t shadow, char *label, uint8_t *active, uint8_t *state) {
|
2012-06-26 10:47:25 +00:00
|
|
|
struct guiNode_t *newNode;
|
2012-06-27 09:12:45 +00:00
|
|
|
uint16_t i;
|
2012-06-26 10:47:25 +00:00
|
|
|
|
|
|
|
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
|
|
|
if(newNode == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-06-26 19:43:21 +00:00
|
|
|
newNode->type = button;
|
2012-06-27 08:23:42 +00:00
|
|
|
newNode->label = label;
|
2012-06-26 10:47:25 +00:00
|
|
|
newNode->x0 = x0;
|
|
|
|
newNode->y0 = y0;
|
|
|
|
newNode->x1 = x1;
|
|
|
|
newNode->y1 = y1;
|
2012-06-27 08:23:42 +00:00
|
|
|
newNode->label = str;
|
2012-06-26 10:47:25 +00:00
|
|
|
newNode->active = active;
|
|
|
|
newNode->state = state;
|
|
|
|
|
2012-06-27 08:11:42 +00:00
|
|
|
if(addElement(newNode) != 1)
|
2012-06-26 11:46:40 +00:00
|
|
|
return 0;
|
2012-06-26 10:47:25 +00:00
|
|
|
|
2012-06-25 17:51:35 +00:00
|
|
|
lcdDrawRectString(x0, y0, x1, y1, str, font, fontColor, buttonColor);
|
2012-06-09 13:41:28 +00:00
|
|
|
|
2012-06-27 09:12:45 +00:00
|
|
|
if(shadow != 0) {
|
|
|
|
for(i = 0; i < shadow; i++) {
|
2012-06-27 09:41:38 +00:00
|
|
|
lcdDrawLine(x0+shadow, y1+i, x1+shadow-1, y1+i, Black);
|
|
|
|
lcdDrawLine(x1+i, y0+shadow, x1+i, y1+shadow-1, Black);
|
2012-06-27 09:12:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-26 11:58:41 +00:00
|
|
|
chHeapFree(newNode);
|
|
|
|
|
2012-06-26 10:47:25 +00:00
|
|
|
return 1;
|
2012-06-09 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 08:23:42 +00:00
|
|
|
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
|
2012-06-26 19:43:21 +00:00
|
|
|
struct guiNode_t *newNode;
|
2012-06-09 17:29:35 +00:00
|
|
|
|
2012-06-26 19:43:21 +00:00
|
|
|
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
|
|
|
if(newNode == NULL)
|
|
|
|
return 0;
|
2012-06-09 17:29:35 +00:00
|
|
|
|
2012-06-26 19:43:21 +00:00
|
|
|
newNode->type = slider;
|
2012-06-27 08:23:42 +00:00
|
|
|
newNode->type = label;
|
2012-06-26 19:43:21 +00:00
|
|
|
newNode->x0 = x0;
|
|
|
|
newNode->y0 = y0;
|
|
|
|
newNode->x1 = x1;
|
|
|
|
newNode->y1 = y1;
|
|
|
|
newNode->state = value;
|
|
|
|
newNode->active = active;
|
|
|
|
newNode->orientation = orientation;
|
|
|
|
|
2012-06-27 08:11:42 +00:00
|
|
|
if(addElement(newNode) != 1)
|
2012-06-26 19:43:21 +00:00
|
|
|
return 0;
|
|
|
|
|
2012-06-27 13:43:49 +00:00
|
|
|
// lcdDraw functions
|
2012-06-26 19:43:21 +00:00
|
|
|
|
|
|
|
chHeapFree(newNode);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-06-27 08:23:42 +00:00
|
|
|
uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
|
2012-06-26 19:48:12 +00:00
|
|
|
struct guiNode_t *newNode;
|
|
|
|
|
|
|
|
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
|
|
|
if(newNode == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
newNode->type = wheel;
|
2012-06-27 08:23:42 +00:00
|
|
|
newNode->label = label;
|
2012-06-26 19:48:12 +00:00
|
|
|
newNode->x0 = x0;
|
|
|
|
newNode->y0 = y0;
|
|
|
|
newNode->r1 = radius1;
|
|
|
|
newNode->r2 = radius2;
|
|
|
|
newNode->active = active;
|
|
|
|
newNode->state = value;
|
|
|
|
|
2012-06-27 08:11:42 +00:00
|
|
|
if(addElement(newNode) != 1)
|
2012-06-26 19:48:12 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// lcdDraw functions
|
|
|
|
|
|
|
|
chHeapFree(newNode);
|
|
|
|
|
|
|
|
return 1;
|
2012-06-09 17:29:35 +00:00
|
|
|
}
|
2012-06-26 19:48:12 +00:00
|
|
|
|