aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2012-10-24 02:39:21 +0200
committerJoel Bodenmann <joel@unormal.org>2012-10-24 02:39:21 +0200
commit5ac69126489aaa36182f79ea184fc771d0ac5d27 (patch)
tree76d1d63df5bffcab59fa00a9568aa9ad60f76fa6
parentd1f970217374c5f0363ebbfa6bd6551094a5735d (diff)
downloaduGFX-5ac69126489aaa36182f79ea184fc771d0ac5d27.tar.gz
uGFX-5ac69126489aaa36182f79ea184fc771d0ac5d27.tar.bz2
uGFX-5ac69126489aaa36182f79ea184fc771d0ac5d27.zip
first graph implementation
-rw-r--r--include/graph.h14
-rw-r--r--old/graph/graph.c75
-rw-r--r--old/graph/graph.h72
-rw-r--r--old/graph/graph.mk3
-rw-r--r--src/gdisp.c18
-rw-r--r--src/graph.c99
6 files changed, 126 insertions, 155 deletions
diff --git a/include/graph.h b/include/graph.h
index e0e0622b..3a6cbe03 100644
--- a/include/graph.h
+++ b/include/graph.h
@@ -29,10 +29,24 @@ typedef struct _Graph {
coord_t x1;
coord_t y1;
uint16_t grid_size;
+ uint16_t dot_space;
bool_t full_grid;
color_t color;
} Graph;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void graphDrawOneQuadrat(Graph *g);
+void graphDrawFourQuadrants(Graph *g);
+void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color);
+void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* GFX_USE_GRAPH */
#endif
diff --git a/old/graph/graph.c b/old/graph/graph.c
deleted file mode 100644
index e680f8d5..00000000
--- a/old/graph/graph.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2012
- Joel Bodenmann aka Tectu <joel@unormal.org>
-
- This file is part of ChibiOS/GFX.
-
- ChibiOS/GFX 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/GFX 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
deleted file mode 100644
index 4793099f..00000000
--- a/old/graph/graph.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2012
- Joel Bodenmann aka Tectu <joel@unormal.org>
-
- This file is part of ChibiOS/GFX.
-
- ChibiOS/GFX 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/GFX 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
deleted file mode 100644
index a826cfe0..00000000
--- a/old/graph/graph.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-GDISP_GRAPH_SRC = $(GFXLIB)/graph/graph.c
-
-GDISP_GRAPH_INC = $(GFXLIB)/graph
diff --git a/src/gdisp.c b/src/gdisp.c
index a63b3db5..83ba8972 100644
--- a/src/gdisp.c
+++ b/src/gdisp.c
@@ -258,9 +258,9 @@
* @brief Draw a line.
* @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x0,y0 The start position
- * @param[in] x1,y1 The end position
- * @param[in] color The color to use
+ * @param[in] x0,y0 The start position
+ * @param[in] x1,y1 The end position
+ * @param[in] color The color to use
*
* @api
*/
@@ -280,6 +280,18 @@
chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
}
#endif
+
+ /**
+ * @brief Draw a dashed line.
+ * @pre The GDISP unit must be in powerOn or powerSleep mode.
+ *
+ * @param[in] x0,y0 The start position
+ * @param[in] x1,y1 The end position
+ * @param[in] length The length of the dash
+ * @param[in] color The color of the dashed line
+ *
+ * @api
+ */
#if GDISP_NEED_MULTITHREAD || defined(__DOXYGEN__)
/**
diff --git a/src/graph.c b/src/graph.c
index 9fd3984f..c67fa252 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -25,8 +25,103 @@
#if GFX_USE_GRAPH
-gfxGraphInit(struct graph_t *g) {
- (void)g;
+point_t origin; // origin of graph
+
+static void swapCoordinates(coord_t *a, coord_t *b) {
+ coord_t temp;
+
+ temp = *b;
+ *b = *a;
+ *a = temp;
+}
+
+static void _horizontalDotLine(coord_t x0, coord_t y0, coord_t x1, uint16_t space, color_t color) {
+ uint16_t offset = x0;
+ uint16_t count = ((x1 - x0) / space);
+
+ do {
+ gdispDrawPixel(offset, y0, color);
+ offset += space;
+ } while(count--);
+}
+
+static void _verticalDotLine(coord_t x0, coord_t y0, coord_t y1, uint16_t space, color_t color) {
+ uint16_t offset = y0;
+ uint16_t count = ((y1 - y0) / space);
+
+ do {
+ gdispDrawPixel(x0, offset, color);
+ offset += space;
+ } while(count--);
+}
+
+void graphDrawOneQuadrant(Graph *g) {
+ if(g->x0 > g->x1)
+ swapCoordinates(&g->x0, &g->x1);
+ if(g->y0 > g->y1)
+ swapCoordinates(&g->y0, &g->y1);
+
+ uint16_t i;
+ uint16_t length_x = (g->x1 - g->x0);
+ uint16_t length_y = (g->y1 - g->y0);
+ uint16_t middle_x = (g->x1 - g->x0) / 2;
+ uint16_t middle_y = (g->y1 - g->y0) / 2;
+
+ origin.x = g->x0;
+ origin.y = g->y1;
+
+ /* X Axis */
+ gdispDrawLine(g->x0, g->y1, g->x1, g->y1, g->color);
+ for(i = 0; i <= (length_y / g->grid_size); i++)
+ _horizontalDotLine(g->x0, g->y0 + g->grid_size * i, g->x1, g->dot_space, g->color);
+
+ /* Y Axis */
+ gdispDrawLine(g->x0, g->y0, g->x0, g->y1, g->color);
+ for(i = 0; i <= (length_x / g->grid_size); i++)
+ _verticalDotLine(g->x0 + g->grid_size * i, g->y0, g->y1, g->dot_space, g->color);
+}
+
+void graphDrawFourQuadrants(Graph *g) {
+ if(g->x0 > g->x1)
+ swapCoordinates(&g->x0, &g->x1);
+ if(g->y0 > g->y1)
+ swapCoordinates(&g->y0, &g->y1);
+
+ uint16_t i;
+ uint16_t length_x = (g->x1 - g->x0);
+ uint16_t length_y = (g->y1 - g->y0);
+ uint16_t middle_x = (g->x1 - g->x0) / 2;
+ uint16_t middle_y = (g->y1 - g->y0) / 2;
+
+ origin.x = middle_x;
+ origin.y = middle_y;
+
+ /* X Axis */
+ gdispDrawLine(g->x0, middle_y, g->x1, middle_y, g->color);
+ for(i = 0; i <= (length_y / g->grid_size); i++)
+ _horizontalDotLine(g->x0, g->y0 + g->grid_size * i, g->x1, g->dot_space, g->color);
+
+ /* Y Axis */
+ gdispDrawLine(middle_x, g->y0, middle_x, g->y1, g->color);
+ for(i = 0; i <= (length_x / g->grid_size); i++)
+ _verticalDotLine(g->x0 + g->grid_size * i, g->y0, g->y1, g->dot_space, g->color);
+}
+
+void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color) {
+ uint16_t i;
+
+ for(i = 0; i < entries; i++)
+ gdispFillCircle(coord[i][0] + origin.x, origin.y - coord[i][1], radius, 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)
+ gdispDrawLine(coord[i-1][0] + origin.x, origin.y - coord[i-1][1], coord[i][0] + origin.x, origin.y - coord[i][1], lineColor);
+ for(i = 0; i < entries; ++i)
+ if(radius != 0)
+ lcdFillCircle(coord[i][0] + origin.x, origin.y - coord[i][1], radius, dotColor);
}
#endif /* GFX_USE_GRAPH */