aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTectu <joel@unormal.org>2012-07-18 03:42:05 +0200
committerTectu <joel@unormal.org>2012-07-18 03:42:05 +0200
commit096701a6ad8f2ba5512aff4ee430ca0d626fff7a (patch)
tree647c32fb1ffbcc895b4b1ffa119c8c3ee88f9948
parent24692be747aa4d94e264219d6f18bcc6beec76ff (diff)
downloaduGFX-096701a6ad8f2ba5512aff4ee430ca0d626fff7a.tar.gz
uGFX-096701a6ad8f2ba5512aff4ee430ca0d626fff7a.tar.bz2
uGFX-096701a6ad8f2ba5512aff4ee430ca0d626fff7a.zip
restructorizing
-rw-r--r--glcd/console.c (renamed from console.c)0
-rw-r--r--glcd/console.h (renamed from console.h)0
-rw-r--r--glcd/fastMath.c (renamed from fastMath.c)0
-rw-r--r--glcd/fastMath.h (renamed from fastMath.h)0
-rw-r--r--glcd/fonts.c (renamed from fonts.c)0
-rw-r--r--glcd/fonts.h (renamed from fonts.h)0
-rw-r--r--glcd/glcd.c (renamed from glcd.c)0
-rw-r--r--glcd/glcd.h (renamed from glcd.h)0
-rw-r--r--glcd/glcd.mk6
-rw-r--r--glcd/worker.h (renamed from worker.h)0
-rw-r--r--graph/graph.c (renamed from graph.c)0
-rw-r--r--graph/graph.h (renamed from graph.h)0
-rw-r--r--graph/graph.mk3
-rw-r--r--gui/gui.c311
-rw-r--r--gui/gui.h95
-rw-r--r--gui/gui.mk3
-rw-r--r--lcd.mk17
-rw-r--r--touchpad/touchpad.c (renamed from touchpad.c)0
-rw-r--r--touchpad/touchpad.h (renamed from touchpad.h)0
-rw-r--r--touchpad/touchpad.mk3
20 files changed, 431 insertions, 7 deletions
diff --git a/console.c b/glcd/console.c
index acfae978..acfae978 100644
--- a/console.c
+++ b/glcd/console.c
diff --git a/console.h b/glcd/console.h
index 73704b2a..73704b2a 100644
--- a/console.h
+++ b/glcd/console.h
diff --git a/fastMath.c b/glcd/fastMath.c
index 26ae0d3f..26ae0d3f 100644
--- a/fastMath.c
+++ b/glcd/fastMath.c
diff --git a/fastMath.h b/glcd/fastMath.h
index 674f2394..674f2394 100644
--- a/fastMath.h
+++ b/glcd/fastMath.h
diff --git a/fonts.c b/glcd/fonts.c
index 18c8b5fd..18c8b5fd 100644
--- a/fonts.c
+++ b/glcd/fonts.c
diff --git a/fonts.h b/glcd/fonts.h
index 245aa059..245aa059 100644
--- a/fonts.h
+++ b/glcd/fonts.h
diff --git a/glcd.c b/glcd/glcd.c
index af502532..af502532 100644
--- a/glcd.c
+++ b/glcd/glcd.c
diff --git a/glcd.h b/glcd/glcd.h
index a80dc1b8..a80dc1b8 100644
--- a/glcd.h
+++ b/glcd/glcd.h
diff --git a/glcd/glcd.mk b/glcd/glcd.mk
new file mode 100644
index 00000000..47d2cf09
--- /dev/null
+++ b/glcd/glcd.mk
@@ -0,0 +1,6 @@
+LCD_GLCD_SRC = $(LCDLIB)/glcd/glcd.c \
+ $(LCDLIB)/glcd/fonts.c \
+ $(LCDLIB)/glcd/fastMath.c \
+ $(LCDLIB)/glcd/console.c
+
+LCD_GLCD_INC = $(LCDLIB)/glcd
diff --git a/worker.h b/glcd/worker.h
index d08cae9d..d08cae9d 100644
--- a/worker.h
+++ b/glcd/worker.h
diff --git a/graph.c b/graph/graph.c
index b9ce8739..b9ce8739 100644
--- a/graph.c
+++ b/graph/graph.c
diff --git a/graph.h b/graph/graph.h
index d0ebd2c2..d0ebd2c2 100644
--- a/graph.h
+++ b/graph/graph.h
diff --git a/graph/graph.mk b/graph/graph.mk
new file mode 100644
index 00000000..706a9412
--- /dev/null
+++ b/graph/graph.mk
@@ -0,0 +1,3 @@
+LCD_GRAPH_SRC = $(LCDLIB)/graph/graph.c
+
+LCD_GRAPH_INC = $(LCDLIB)/graph
diff --git a/gui/gui.c b/gui/gui.c
new file mode 100644
index 00000000..3190a885
--- /dev/null
+++ b/gui/gui.c
@@ -0,0 +1,311 @@
+#include "gui.h"
+
+static struct guiNode_t *firstGUI = NULL;
+uint16_t x, y; // global touchpad coordinates
+
+static uint8_t addElement(struct guiNode_t *newNode) {
+ struct guiNode_t *new;
+
+ 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;
+
+ new->next = chHeapAlloc(NULL, sizeof(struct guiNode_t));
+ if(new->next == NULL)
+ return 0;
+
+ new = new->next;
+ *new = *newNode;
+ new->next = NULL;
+ }
+
+ return 1;
+}
+
+static uint8_t deleteElement(char *label) {
+ struct guiNode_t *pointer, *pointer1;
+
+ if(firstGUI != NULL) {
+ if(strcmp(firstGUI->label, label) == 0) {
+ pointer = firstGUI->next;
+ chHeapFree(firstGUI);
+ firstGUI = pointer;
+ } else {
+ pointer = firstGUI;
+
+ while(pointer->next != NULL) {
+ pointer1 = pointer->next;
+
+ if(strcmp(firstGUI->label, label) == 0) {
+ pointer->next = pointer1->next;
+ chHeapFree(pointer1);
+ break;
+ }
+
+ pointer = pointer1;
+
+ }
+ }
+
+ return 1; // successful
+ }
+
+ return 0; // not successful
+}
+
+void guiPrintElements(BaseSequentialStream *chp) {
+ 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);
+ chprintf(chp, "label: %s\r\n", pointer->label);
+ chprintf(chp, "active: %d\r\n", *(pointer->active));
+ chprintf(chp, "state: %d\r\n", *(pointer->state));
+ chprintf(chp, "*next: 0x%x\r\n", pointer->next);
+ chprintf(chp, "\r\n\n");
+ pointer = pointer->next;
+ }
+}
+
+static inline void buttonUpdate(struct guiNode_t *node) {
+ if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1) {
+ *(node->state) = 1;
+ } else {
+ *(node->state) = 0;
+ }
+}
+
+static inline void sliderUpdate(struct guiNode_t *node) {
+ uint16_t length;
+
+ if(node->orientation == horizontal)
+ length = node->x1 - node->x0;
+ else if(node->orientation == vertical)
+ length = node->y1 - node->y0;
+
+ if(node->mode == modePassive) {
+ node->percentage = *(node->state);
+ } else if(node->mode == modeActive) {
+ if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1) {
+ if(node->orientation == horizontal) {
+ node->percentage = (((x - node->x0) * 100) / length);
+ } else if(node->orientation == vertical) {
+ node->percentage = (((y - node->y0) * 100) / length);
+ }
+ }
+
+ *(node->state) = node->percentage;
+ }
+
+ // a bit of safety here
+ if(node->percentage > 100)
+ node->percentage = 100;
+ if(node->percentage < 0)
+ node->percentage = 0;
+
+ if(node->orientation == horizontal) {
+ node->value = ((((node->x1)-(node->x0)) * node->percentage) / 100);
+ if(node->oldValue > node->value || node->value == 0)
+ lcdFillArea(node->x0+1, node->y0+1, node->x1, node->y1, node->bkColor);
+ else
+ lcdDrawRect(node->x0+1, node->y0+1, node->x0+node->value, node->y1, filled, node->valueColor);
+ } else if(node->orientation == vertical) {
+ node->value = ((((node->y1)-(node->y0)) * node->percentage) / 100);
+ if(node->oldValue > node->value || node->value == 0)
+ lcdFillArea(node->x0+1, node->y0+1, node->x1, node->y1, node->bkColor);
+ else
+ lcdDrawRect(node->x0+1, node->y0+1, node->x1, node->y0+node->value, filled, node->valueColor);
+ }
+
+ node->oldValue = node->value;
+}
+
+static inline void wheelUpdate(struct guiNode_t *node) {
+ (void)node;
+}
+
+static inline void keymatrixUpdate(struct guiNode_t *node) {
+ (void)node;
+}
+
+static void guiThread(const uint16_t interval) {
+ struct guiNode_t *node;
+
+ chRegSetThreadName("GUI");
+
+ while(TRUE) {
+ for(node = firstGUI; node; node = node->next) {
+ // check if GUI element is set active
+ if(*(node->active) == active) {
+ x = tpReadX();
+ y = tpReadY();
+
+ switch(node->type) {
+ case button:
+ buttonUpdate(node);
+ break;
+ case slider:
+ sliderUpdate(node);
+ break;
+ case wheel:
+ wheelUpdate(node);
+ break;
+ case keymatrix:
+ keymatrixUpdate(node);
+ break;
+ }
+ }
+ }
+
+ chThdSleepMilliseconds(interval);
+ }
+}
+
+Thread *guiInit(uint16_t interval, tprio_t priority) {
+ Thread *tp = NULL;
+
+ tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), priority, guiThread, interval);
+
+ return tp;
+}
+
+uint8_t guiDeleteElement(char *label) {
+ return deleteElement(label);
+}
+
+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) {
+ struct guiNode_t *newNode;
+ uint16_t i;
+
+ newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
+ if(newNode == NULL)
+ return 0;
+
+ newNode->type = button;
+ newNode->label = label;
+ newNode->x0 = x0;
+ newNode->y0 = y0;
+ newNode->x1 = x1;
+ newNode->y1 = y1;
+ newNode->shadow = shadow;
+ newNode->active = active;
+ newNode->state = state;
+
+ if(addElement(newNode) != 1)
+ return 0;
+
+ lcdDrawRectString(x0, y0, x1, y1, str, font, fontColor, buttonColor);
+
+ if(shadow != 0) {
+ for(i = 0; i < shadow; i++) {
+ lcdDrawLine(x0+shadow, y1+i, x1+shadow-1, y1+i, Black);
+ lcdDrawLine(x1+i, y0+shadow, x1+i, y1+shadow-1, Black);
+ }
+ }
+
+ chHeapFree(newNode);
+
+ return 1;
+}
+
+uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint8_t mode, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
+ struct guiNode_t *newNode;
+
+ newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
+ if(newNode == NULL)
+ return 0;
+
+ newNode->type = slider;
+ newNode->label = label;
+ newNode->x0 = x0;
+ newNode->y0 = y0;
+ newNode->x1 = x1;
+ newNode->y1 = y1;
+ newNode->mode = mode;
+ newNode->bkColor = bkColor;
+ newNode->valueColor = valueColor;
+ newNode->state = value;
+ newNode->active = active;
+ newNode->orientation = orientation;
+ newNode->percentage = 0;
+
+ if(addElement(newNode) != 1)
+ return 0;
+
+ (void)bkColor;
+ (void)valueColor;
+
+ // lcdDraw functions
+ lcdDrawRect(x0, y0, x1, y1, frame, frameColor);
+
+ chHeapFree(newNode);
+
+ return 1;
+}
+
+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) {
+ struct guiNode_t *newNode;
+
+ newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
+ if(newNode == NULL)
+ return 0;
+
+ newNode->type = wheel;
+ newNode->label = label;
+ newNode->x0 = x0;
+ newNode->y0 = y0;
+ newNode->r1 = radius1;
+ newNode->r2 = radius2;
+ newNode->active = active;
+ newNode->state = value;
+
+ if(addElement(newNode) != 1)
+ return 0;
+
+ (void)bkColor;
+ (void)valueColor;
+ // lcdDraw functions
+
+ chHeapFree(newNode);
+
+ return 1;
+}
+
+uint8_t guiDrawKeymatrix(uint16_t x0, uint16_t y0, uint16_t size, uint16_t space, uint16_t shadow, uint16_t buttonColor, uint16_t fontColor, font_t font, char *label, uint8_t *active, uint8_t *value) {
+ struct guiNode_t *newNode;
+
+ newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
+ if(newNode == NULL)
+ return 0;
+
+ newNode->type = keymatrix;
+ newNode->label = label;
+ newNode->x0 = x0;
+ newNode->y0 = y0;
+ newNode->shadow = shadow;
+ newNode->active = active;
+ newNode->state = value;
+
+ if(addElement(newNode) != 1)
+ return 0;
+
+ // lcdDraw functions
+
+ chHeapFree(newNode);
+
+ return 1;
+}
+
diff --git a/gui/gui.h b/gui/gui.h
new file mode 100644
index 00000000..1e3b0a6c
--- /dev/null
+++ b/gui/gui.h
@@ -0,0 +1,95 @@
+#ifndef GUI_H
+#define GUI_H
+
+#include "ch.h"
+#include "hal.h"
+#include "glcd.h"
+#include "chprintf.h"
+#include "touchpad.h"
+#include <string.h>
+
+struct guiNode_t {
+ uint8_t type;
+ uint16_t x0;
+ uint16_t y0;
+ uint16_t x1;
+ uint16_t y1;
+ uint16_t r1;
+ uint16_t r2;
+ uint16_t shadow;
+ uint16_t bkColor;
+ uint16_t valueColor;
+ uint16_t value;
+ uint16_t oldValue;
+ uint16_t percentage;
+ uint8_t orientation;
+ uint8_t mode;
+ uint8_t *active;
+ uint8_t *state;
+ char *label;
+ struct guiNode_t *next;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum {button, slider, wheel, keymatrix};
+enum {horizontal, vertical};
+enum {inactive, active};
+enum {modePassive, modeActive};
+
+/*
+ * Description: creates the GUI thread
+ *
+ * param: - interval: thread sleep in milliseconds after each GUI element update
+ * - priority: priority of the thread
+ *
+ * return: pointer to created thread
+ */
+Thread *guiInit(uint16_t interval, tprio_t priority);
+
+/*
+ * Description: prints all GUI elements structs (linked list)
+ *
+ * param: - chp: pointer to output stream
+ *
+ * return: none
+ */
+void guiPrintElements(BaseSequentialStream *chp);
+
+/*
+ * Description: deletes a GUI element from the linked list
+ *
+ * param: - label: label of the element (parameter of each guiDrawXXX function)
+ *
+ * return: 1 if successful, 0 otherwise
+ */
+uint8_t guiDeleteElement(char *label);
+
+/*
+ * Description: draws a button on the screen and keeps it's state up to date
+ *
+ * param: - x0, y0, x1, y1: start and end coordinates of the button's rectangle
+ * - str: string that gets drawn into the rectangle - button's lable
+ * - fontColor: color of the lable
+ * - buttonColor: color of the rectangle
+ * - shadow: draws a black shadow with N pixels size if != 0
+ * - active: pass pointer to variable which holds the state 'active' or 'inactive'
+ * - state: pass pointer to variable whcih will keep the state of the button (pressed / unpressed)'
+ *
+ * return: 1 if button successfully created
+ */
+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);
+
+uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint8_t mode, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
+
+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);
+
+uint8_t guiDrawKeymatrix(uint16_t x0, uint16_t y0, uint16_t buttonSize, uint16_t space, uint16_t shadow, uint16_t buttonColor, uint16_t fontColor, font_t font, char *label, uint8_t *active, uint8_t *value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/gui/gui.mk b/gui/gui.mk
new file mode 100644
index 00000000..e25cbd73
--- /dev/null
+++ b/gui/gui.mk
@@ -0,0 +1,3 @@
+LCD_GUI_SRC = $(LCDLIB)/gui/gui.c
+
+LCD_GUI_INC = $(LCDLIB)/gui
diff --git a/lcd.mk b/lcd.mk
index 882bb64d..3354330d 100644
--- a/lcd.mk
+++ b/lcd.mk
@@ -1,17 +1,20 @@
LCDLIB = $(CHIBIOS)/ext/lcd
include $(LCDLIB)/drivers/drivers.mk
+include $(LCDLIB)/glcd/glcd.mk
+include $(LCDLIB)/touchpad/touchpad.mk
+include $(LCDLIB)/graph/graph.mk
include $(LCDLIB)/gui/gui.mk
-LCDSRC = $(LCDLIB)/glcd.c \
- $(LCDLIB)/fonts.c \
- $(LCDLIB)/touchpad.c \
- $(LCDLIB)/graph.c \
- $(LCDLIB)/console.c \
- $(LCDLIB)/fastMath.c \
- $(LCD_DRIVERS_SRC) \
+LCDSRC = $(LCD_DRIVERS_SRC) \
+ $(LCD_GLCD_SRC) \
+ $(LCD_TOUCHPAD_SRC) \
+ $(LCD_GRAPH_SRC) \
$(LCD_GUI_SRC)
LCDINC = $(LCDLIB) \
$(LCD_DRIVERS_INC) \
+ $(LCD_GLCD_INC) \
+ $(LCD_TOUCHPAD_INC) \
+ $(LCD_GRAPH_INC) \
$(LCD_GUI_INC)
diff --git a/touchpad.c b/touchpad/touchpad.c
index d44e03a1..d44e03a1 100644
--- a/touchpad.c
+++ b/touchpad/touchpad.c
diff --git a/touchpad.h b/touchpad/touchpad.h
index c401415e..c401415e 100644
--- a/touchpad.h
+++ b/touchpad/touchpad.h
diff --git a/touchpad/touchpad.mk b/touchpad/touchpad.mk
new file mode 100644
index 00000000..de27ae0d
--- /dev/null
+++ b/touchpad/touchpad.mk
@@ -0,0 +1,3 @@
+LCD_TOUCHPAD_SRC = $(LCDLIB)/touchpad/touchpad.c
+
+LCD_TOUCHPAD_INC = $(LCDLIB)/touchpad