diff options
Diffstat (limited to 'old')
| -rw-r--r-- | old/console.c | 171 | ||||
| -rw-r--r-- | old/console.h | 84 | ||||
| -rw-r--r-- | old/graph/graph.c | 75 | ||||
| -rw-r--r-- | old/graph/graph.h | 72 | ||||
| -rw-r--r-- | old/graph/graph.mk | 3 | ||||
| -rw-r--r-- | old/gui/gui.c | 334 | ||||
| -rw-r--r-- | old/gui/gui.h | 115 | ||||
| -rw-r--r-- | old/gui/gui.mk | 3 | 
8 files changed, 857 insertions, 0 deletions
| diff --git a/old/console.c b/old/console.c new file mode 100644 index 00000000..caddfce2 --- /dev/null +++ b/old/console.c @@ -0,0 +1,171 @@ +/*
 +    ChibiOS/RT - Copyright (C) 2012
 +                 Joel Bodenmann aka Tectu <joel@unormal.org>
 +
 +    This file is part of ChibiOS-LCD-Driver.
 +
 +    ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
 +    it under the terms of the GNU General Public License as published by
 +    the Free Software Foundation; either version 3 of the License, or
 +    (at your option) any later version.
 +
 +    ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +    GNU General Public License for more details.
 +
 +    You should have received a copy of the GNU General Public License
 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +*/
 +
 +#include "ch.h"
 +
 +#include "glcd.h"
 +#include "console.h"
 +
 +/*
 + * Interface implementation. The interface is write only
 + */
 +
 +static size_t writes(void *ip, const uint8_t *bp, size_t n) {
 +	return lcdConsoleWrite((GLCDConsole *)ip, bp, n);
 +}
 +
 +static size_t reads(void *ip, uint8_t *bp, size_t n) {
 +	(void)ip;
 +	(void)bp;
 +	(void)n;
 +
 +	return 0;
 +}
 +
 +static msg_t put(void *ip, uint8_t b) {
 +	return lcdConsolePut((GLCDConsole *)ip, (char)b);
 +}
 +
 +static msg_t get(void *ip) {
 +	(void)ip;
 +
 +	return RDY_OK;
 +}
 +
 +static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
 +	(void)timeout;
 +
 +	/* TODO: handle timeout */
 +
 +	return lcdConsolePut((GLCDConsole *)ip, (char)b);
 +}
 +
 +static msg_t gett(void *ip, systime_t timeout) {
 +	(void)ip;
 +	(void)timeout;
 +
 +	return RDY_OK;
 +}
 +
 +static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
 +	(void)time;
 +
 +	return lcdConsoleWrite((GLCDConsole *)ip, bp, n);
 +}
 +
 +static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
 +	(void)ip;
 +	(void)bp;
 +	(void)n;
 +	(void)time;
 +
 +	return 0;
 +}
 +
 +static uint16_t getflags(void *ip) {
 +	_chn_get_and_clear_flags_impl(ip);
 +}
 +
 +static const struct GLCDConsoleVMT vmt = {
 +	writes, reads, put, get,
 +	putt, gett, writet, readt,
 +	getflags
 +};
 +
 +
 +msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, font_t font, uint16_t bkcolor, uint16_t color) {
 +	const uint8_t* ptr;
 +	uint16_t chi;
 +	uint16_t x,y;
 +
 +	console->vmt = &vmt;
 +	/* read font, get height */
 +	console->fy = lcdGetFontHeight(font);
 +
 +	/* calculate the size of the console as an integer multiple of characters height*/
 +	console->sx = width;
 +	console->sy = (((int16_t)(height/console->fy))-1)*console->fy;
 +
 +	console->cx = 0;
 +	console->cy = 0;
 +	console->x0 = x0;
 +	console->y0 = y0;
 +
 +	console->bkcolor = bkcolor;
 +	console->color = color;
 +
 +	console->font = font;
 +
 +	lcdFillArea(x0, y0, x0+width, y0+height, console->bkcolor);
 +	return RDY_OK;
 +}
 +
 +msg_t lcdConsolePut(GLCDConsole *console, char c) {
 +	uint8_t width;
 +
 +	if(c == '\n') {
 +		/* clear the text at the end of the line */
 +		if(console->cx < console->sx)
 +			lcdFillArea(console->x0 + console->cx, console->y0 + console->cy,
 +						console->x0 + console->sx, console->y0 + console->cy + console->fy,
 +						console->bkcolor);
 +		console->cx = 0;
 +		console->cy += console->fy;
 +	} else if(c == '\r') {
 +		/* TODO: work backwards through the buffer to the start of the current line */
 +		//console->cx = 0;
 +	} else {
 +		width = lcdMeasureChar(c, console->font);
 +		if((console->cx + width) >= console->sx) {
 +			/* clear the text at the end of the line */
 +			lcdFillArea(console->x0 + console->cx, console->y0 + console->cy,
 +						console->x0 + console->cx + width, console->y0 + console->cy + console->fy,
 +						console->bkcolor);
 +			console->cx = 0;
 +			console->cy += console->fy;
 +		}
 +
 +		if((console->cy > console->sy)) {
 +
 +			lcdVerticalScroll(console->x0, console->y0, console->x0 + console->sx,
 +					console->y0 + console->sy + console->fy, console->fy);
 +			/* reset the cursor */
 +			console->cx = 0;
 +			console->cy = console->sy;
 +		}
 +
 +		lcdDrawChar(console->x0 + console->cx, console->y0 + console->cy, c,
 +				console->font, console->color, console->bkcolor, solid);
 +
 +		/* update cursor */
 +		console->cx += width;
 +	}
 +	return RDY_OK;
 +}
 +
 +msg_t lcdConsoleWrite(GLCDConsole *console, uint8_t *bp, size_t n) {
 +	size_t i;
 +	for(i = 0; i < n; i++)
 +		lcdConsolePut(console, bp[i]);
 +
 +	return RDY_OK;
 +}
 +
 +
 diff --git a/old/console.h b/old/console.h new file mode 100644 index 00000000..f76c5adf --- /dev/null +++ b/old/console.h @@ -0,0 +1,84 @@ +/* +    ChibiOS/RT - Copyright (C) 2012 +                 Joel Bodenmann aka Tectu <joel@unormal.org> + +    This file is part of ChibiOS-LCD-Driver. + +    ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation; either version 3 of the License, or +    (at your option) any later version. + +    ChibiOS-LCD-Driver is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef CONSOLE_H +#define CONSOLE_H + +#include "glcd.h" + +/** + * @brief   Structure representing a GLCD driver. + */ +typedef struct GLCDConsole GLCDConsole; + +/** + * @brief   @p GLCDConsole specific methods. + */ +#define _glcd_driver_methods                                              \ +	_base_asynchronous_channel_methods + +/** + * @extends BaseAsynchronousChannelVMT + * + * @brief   @p GLCDConsole virtual methods table. + */ +struct GLCDConsoleVMT { +	_glcd_driver_methods +}; + +/** + * @extends BaseAsynchronousChannel + * + * @brief   GLCD Console class. + * @details This class extends @p BaseAsynchronousChannel by adding physical + *          I/O queues. + */ +struct GLCDConsole { +	/** @brief Virtual Methods Table.*/ +	const struct GLCDConsoleVMT *vmt; +	_base_asynchronous_channel_data +	/* WARNING: Do not add any data to this struct above this comment, only below */ +	/* font */ +	font_t font; +	/* lcd area to use */ +	uint16_t x0,y0; +	/* current cursor position, in pixels */ +	uint16_t cx,cy; +	/* console size in pixels */ +	uint16_t sx,sy; +	/* foreground and background colour */ +	uint16_t bkcolor, color; +	/* font size in pixels */ +	uint8_t fy; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +msg_t lcdConsoleInit(GLCDConsole *console, uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, font_t font, uint16_t bkcolor, uint16_t color); +msg_t lcdConsolePut(GLCDConsole *console, char c); +msg_t lcdConsoleWrite(GLCDConsole *console, uint8_t *bp, size_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* CONSOLE_H */ diff --git a/old/graph/graph.c b/old/graph/graph.c new file mode 100644 index 00000000..853ab738 --- /dev/null +++ b/old/graph/graph.c @@ -0,0 +1,75 @@ +/* +    ChibiOS/RT - Copyright (C) 2012 +                 Joel Bodenmann aka Tectu <joel@unormal.org> + +    This file is part of ChibiOS-LCD-Driver. + +    ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation; either version 3 of the License, or +    (at your option) any later version. + +    ChibiOS-LCD-Driver is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "glcd.h" + +#define MARKSIZE	5 	// half + +static uint16_t x, y;			// origins in graph +static uint16_t grid_X, grid_Y;	//grids + +void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t gridX, uint16_t gridY, uint16_t color) { +	uint16_t i, length; +	volatile uint16_t off; + +	x = x0; +	y = y0; +	grid_X = gridX; +	grid_Y = gridY; + +	// X-Axis +	length = x1 - x0; +	lcdDrawLine(x0, y0, x1, y0, color); +	lcdDrawLine(x1, y0, x1-5, y0+5, color); +	lcdDrawLine(x1, y0, x1-5, y0-5, color);	 +	for(i=1; i<(length / grid_X); i++) { +		off = x0 + i * grid_X; +		lcdDrawLine(off, y0-MARKSIZE, off, y0+MARKSIZE, color); +	} + +	// Y-Axis +	length = y0 - y1; +	lcdDrawLine(x0, y0, x0, y1, color); +	lcdDrawLine(x0, y1, x0-5, y1+5, color); +	lcdDrawLine(x0, y1, x0+5, y1+5, color); +	for(i=1; i<(length / grid_Y); i++) { +		off = y0 + i * grid_Y; +		lcdDrawLine(x0-MARKSIZE, off, x0+MARKSIZE, off, color);	 +	} +} + +void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color) { +	uint16_t i; + +	for(i = 0; i < entries; i++) +		lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, color); +} + +void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor) { +	uint16_t i; + +	for(i = 0; i < entries; ++i) +		lcdDrawLine(coord[i-1][0]+x, y-coord[i-1][1], coord[i][0]+x, y-coord[i][1], lineColor);  +	for(i = 0; i < entries; ++i) +		if(radius != 0) +			lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, dotColor); +} + + diff --git a/old/graph/graph.h b/old/graph/graph.h new file mode 100644 index 00000000..f4286fc2 --- /dev/null +++ b/old/graph/graph.h @@ -0,0 +1,72 @@ +/* +    ChibiOS/RT - Copyright (C) 2012 +                 Joel Bodenmann aka Tectu <joel@unormal.org> + +    This file is part of ChibiOS-LCD-Driver. + +    ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation; either version 3 of the License, or +    (at your option) any later version. + +    ChibiOS-LCD-Driver is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRAPH_H +#define GRAPH_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * Description: does draw axis arrows and grid + * + * param: + *		- x0, y0, x1, y1:	location of arrows + *		- gridX, gridY:		grid size in X and Y direction + *		- color:			color of arrows + * + * return: none + */ +void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t gridX, uint16_t gridY, uint16_t color); + +/* + * Description: does draw coordinates into graph as dots + * + * param: + *		- coord:		two dimensionl array containing X and Y coordinates + *		- entries:		amount of coordinates passed (sizeof(coord)/sizeof(coord[0]) + *		- radius:		size of the dots + *		- color:		color of the dots + * + * return: none + */ +void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color); + +/* + * Description: does draw coordinates into graph connected by lines + * + * param: + *		- coord:		two dimensional array containing X and Y coordinates + *		- entries:		amount of coordinates passed (sizeof(coord)/sizeof(coord[0]) + *		- radius:		if not 0, graphDrawDots() gets invoked + *		- lineColor:	color of the lines + *		- dotColor:		color of dots, if radius != 0 + * + * return: none + */	 +void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/old/graph/graph.mk b/old/graph/graph.mk new file mode 100644 index 00000000..706a9412 --- /dev/null +++ b/old/graph/graph.mk @@ -0,0 +1,3 @@ +LCD_GRAPH_SRC =		$(LCDLIB)/graph/graph.c  + +LCD_GRAPH_INC =		$(LCDLIB)/graph diff --git a/old/gui/gui.c b/old/gui/gui.c new file mode 100644 index 00000000..40553d86 --- /dev/null +++ b/old/gui/gui.c @@ -0,0 +1,334 @@ +/* +    ChibiOS/RT - Copyright (C) 2012 +                 Joel Bodenmann aka Tectu <joel@unormal.org> + +    This file is part of ChibiOS-LCD-Driver. + +    ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation; either version 3 of the License, or +    (at your option) any later version. + +    ChibiOS-LCD-Driver is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +#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 = 1; + +	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->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 +	(void)size; +	(void)space; +	(void)buttonColor; +	(void)fontColor; +	(void)font; + +	chHeapFree(newNode); + +	return 1; +} + diff --git a/old/gui/gui.h b/old/gui/gui.h new file mode 100644 index 00000000..04d9a8b1 --- /dev/null +++ b/old/gui/gui.h @@ -0,0 +1,115 @@ +/* +    ChibiOS/RT - Copyright (C) 2012 +                 Joel Bodenmann aka Tectu <joel@unormal.org> + +    This file is part of ChibiOS-LCD-Driver. + +    ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation; either version 3 of the License, or +    (at your option) any later version. + +    ChibiOS-LCD-Driver is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +#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/old/gui/gui.mk b/old/gui/gui.mk new file mode 100644 index 00000000..e25cbd73 --- /dev/null +++ b/old/gui/gui.mk @@ -0,0 +1,3 @@ +LCD_GUI_SRC	=		$(LCDLIB)/gui/gui.c  + +LCD_GUI_INC =		$(LCDLIB)/gui | 
