Commits

Trammell Hudson  committed ad2f608 Draft

counter drawing of hershey fonts almost works

  • Participants
  • Parent commits f4369a9

Comments (0)

Files changed (4)

 SRC =	$(TARGET).c \
 	usb_serial.c \
 	bits.c \
+	hershey.c \
 
 
 # MCU name, you MUST set this to match the board you are using
+/** \file
+ * Hershey fonts for the numbers 0-9
+ * From:
+ * http://paulbourke.net/dataformats/hershey/
+ *
+ * Point x,y == -1 => pen up
+ * Otherwise draw in a continuous path
+ */
+
+#include "hershey.h"
+
+#define POINT(x,y) { x, y }
+
+const path_t digits[][32] = {
+	[0] = {
+		POINT( 9,21),
+		POINT( 6,20),
+		POINT( 4,17),
+		POINT( 3,12),
+		POINT( 3, 9),
+		POINT( 4, 4),
+		POINT( 6, 1),
+		POINT( 9, 0),
+		POINT(11, 0),
+		POINT(14, 1),
+		POINT(16, 4),
+		POINT(17, 9),
+		POINT(17,12),
+		POINT(16,17),
+		POINT(14,20),
+		POINT(11,21),
+		POINT( 9,21),
+	},
+	[1] = {
+		POINT( 6,17),
+		POINT( 8,18),
+		POINT(11,21),
+		POINT(11, 0),
+	},
+	[2] = {
+		POINT( 4,16),
+		POINT( 4,17),
+		POINT( 5,19),
+		POINT( 6,20),
+		POINT( 8,21),
+		POINT(12,21),
+		POINT(14,20),
+		POINT(15,19),
+		POINT(16,17),
+		POINT(16,15),
+		POINT(15,13),
+		POINT(13,10),
+		POINT( 3, 0),
+		POINT(17, 0),
+	},
+	[3] = {
+		POINT( 5,21),
+		POINT(16,21),
+		POINT(10,13),
+		POINT(13,13),
+		POINT(15,12),
+		POINT(16,11),
+		POINT(17, 8),
+		POINT(17, 6),
+		POINT(16, 3),
+		POINT(14, 1),
+		POINT(11, 0),
+		POINT( 8, 0),
+		POINT( 5, 1),
+		POINT( 4, 2),
+		POINT( 3, 4),
+	},
+	[4] = {
+		POINT(13,21),
+		POINT( 3, 7),
+		POINT(18, 7),
+		POINT(-1,-1),
+		POINT(13,21),
+		POINT(13, 0),
+	},
+	[5] = {
+		POINT(15,21),
+		POINT( 5,21),
+		POINT( 4,12),
+		POINT( 5,13),
+		POINT( 8,14),
+		POINT(11,14),
+		POINT(14,13),
+		POINT(16,11),
+		POINT(17, 8),
+		POINT(17, 6),
+		POINT(16, 3),
+		POINT(14, 1),
+		POINT(11, 0),
+		POINT( 8, 0),
+		POINT( 5, 1),
+		POINT( 4, 2),
+		POINT( 3, 4),
+	},
+	[6] = {
+		POINT(16,18),
+		POINT(15,20),
+		POINT(12,21),
+		POINT(10,21),
+		POINT( 7,20),
+		POINT( 5,17),
+		POINT( 4,12),
+		POINT( 4, 7),
+		POINT( 5, 3),
+		POINT( 7, 1),
+		POINT(10, 0),
+		POINT(11, 0),
+		POINT(14, 1),
+		POINT(16, 3),
+		POINT(17, 6),
+		POINT(17, 7),
+		POINT(16,10),
+		POINT(14,12),
+		POINT(11,13),
+		POINT(10,13),
+		POINT( 7,12),
+		POINT( 5,10),
+		POINT( 4, 7),
+	},
+	[7] = {
+		POINT(17,21),
+		POINT( 7, 0),
+		POINT(-1,-1),
+		POINT( 3,21),
+		POINT(17,21),
+	},
+	[8] = {
+		POINT( 8,21),
+		POINT( 5,20),
+		POINT( 4,18),
+		POINT( 4,16),
+		POINT( 5,14),
+		POINT( 7,13),
+		POINT(11,12),
+		POINT(14,11),
+		POINT(16, 9),
+		POINT(17, 7),
+		POINT(17, 4),
+		POINT(16, 2),
+		POINT(15, 1),
+		POINT(12, 0),
+		POINT( 8, 0),
+		POINT( 5, 1),
+		POINT( 4, 2),
+		POINT( 3, 4),
+		POINT( 3, 7),
+		POINT( 4, 9),
+		POINT( 6,11),
+		POINT( 9,12),
+		POINT(13,13),
+		POINT(15,14),
+		POINT(16,16),
+		POINT(16,18),
+		POINT(15,20),
+		POINT(12,21),
+		POINT( 8,21),
+	},
+	[9] = {
+		POINT(16,14),
+		POINT(15,11),
+		POINT(13, 9),
+		POINT(10, 8),
+		POINT( 9, 8),
+		POINT( 6, 9),
+		POINT( 4,11),
+		POINT( 3,14),
+		POINT( 3,15),
+		POINT( 4,18),
+		POINT( 6,20),
+		POINT( 9,21),
+		POINT(10,21),
+		POINT(13,20),
+		POINT(15,18),
+		POINT(16,14),
+		POINT(16, 9),
+		POINT(15, 4),
+		POINT(13, 1),
+		POINT(10, 0),
+		POINT( 8, 0),
+		POINT( 5, 1),
+		POINT( 4, 3),
+	},
+};
+#ifndef _hershey_h_
+#define _hershey_h_
+
+#include <stdint.h>
+
+typedef struct
+{
+	int8_t x;
+	int8_t y;
+} __attribute__((__packed__))
+path_t;
+
+extern const path_t digits[][32];
+
+#endif

File scopeclock.c

 #include <util/delay.h>
 #include "usb_serial.h"
 #include "bits.h"
+#include "hershey.h"
 
 void send_str(const char *s);
 uint8_t recv_str(char *buf, uint8_t size);
 
 	while (1)
 	{
-		PORTD = x0;
-		PORTB = y0;
+		PORTB = x0;
+		PORTD = y0;
 
 		if (x0 == x1 && y0 == y1)
 			break;
 }
 
 
+static void
+draw_digit(
+	uint8_t x,
+	uint8_t y,
+	uint8_t val
+)
+{
+	path_t * p = digits[val];
+	uint8_t ox = x;
+	uint8_t oy = y;
+
+	while (1)
+	{
+		int8_t px = p->x;
+		int8_t py = p->y;
+		if (px == 0 && py == 0)
+			break;
+
+		uint8_t nx = x + px;
+		uint8_t ny = y + py;
+
+		if (px != -1 && py != -1)
+			line(ox, oy, nx, ny);
+		ox = nx;
+		oy = ny;
+		p++;
+	}
+}
+
+
+
 int main(void)
 {
 	// set for 16 MHz clock
 	uint8_t off = 0;
 	char buf[32];
 
-	uint8_t x = 1;
-	uint8_t dir = 0;
+	uint16_t x = 1;
 
 	while (1)
 	{
-		if (dir)
-			line(0,0,200,x);
-		else
-			line(255,255,x,0);
+		draw_digit(0*32, 64, (x >> 15) & 0x7);
+		draw_digit(1*32, 64, (x >> 12) & 0x7);
+		draw_digit(2*32, 64, (x >> 9) & 0x7);
+		draw_digit(3*32, 64, (x >> 6) & 0x7);
+		draw_digit(4*32, 64, (x >> 3) & 0x7);
+		draw_digit(5*32, 64, (x >> 0) & 0x7);
 
-		if (++x == 0)
-			dir = !dir;
+		x++;
 
 		line_horiz(0,0,255);
 		line_vert(0,0,255);
-
 	}
 }