summaryrefslogtreecommitdiffstats
path: root/chars
diff options
context:
space:
mode:
Diffstat (limited to 'chars')
-rw-r--r--chars/0.xbm4
-rw-r--r--chars/0.xcfbin0 -> 873 bytes
-rw-r--r--chars/1.xbm4
-rw-r--r--chars/1.xcfbin0 -> 867 bytes
-rw-r--r--chars/2.xbm4
-rw-r--r--chars/2.xcfbin0 -> 831 bytes
-rw-r--r--chars/3.xbm4
-rw-r--r--chars/3.xcfbin0 -> 831 bytes
-rw-r--r--chars/4.xbm4
-rw-r--r--chars/4.xcfbin0 -> 855 bytes
-rw-r--r--chars/5.xbm4
-rw-r--r--chars/5.xcfbin0 -> 831 bytes
-rw-r--r--chars/6.xbm4
-rw-r--r--chars/6.xcfbin0 -> 831 bytes
-rw-r--r--chars/7.xbm4
-rw-r--r--chars/7.xcfbin0 -> 855 bytes
-rw-r--r--chars/8.xbm4
-rw-r--r--chars/8.xcfbin0 -> 831 bytes
-rw-r--r--chars/9.xbm4
-rw-r--r--chars/9.xcfbin0 -> 831 bytes
-rw-r--r--chars/chars.c118
-rw-r--r--chars/chars.h10
-rw-r--r--chars/space.xbm4
-rw-r--r--chars/space.xcfbin0 -> 771 bytes
24 files changed, 172 insertions, 0 deletions
diff --git a/chars/0.xbm b/chars/0.xbm
new file mode 100644
index 0000000..420af7e
--- /dev/null
+++ b/chars/0.xbm
@@ -0,0 +1,4 @@
+#define c0_width 5
+#define c0_height 8
+static unsigned char c0_bits[] = {
+ 0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e };
diff --git a/chars/0.xcf b/chars/0.xcf
new file mode 100644
index 0000000..a3ab875
--- /dev/null
+++ b/chars/0.xcf
Binary files differ
diff --git a/chars/1.xbm b/chars/1.xbm
new file mode 100644
index 0000000..0e3b28c
--- /dev/null
+++ b/chars/1.xbm
@@ -0,0 +1,4 @@
+#define c1_width 5
+#define c1_height 8
+static unsigned char c1_bits[] = {
+ 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 };
diff --git a/chars/1.xcf b/chars/1.xcf
new file mode 100644
index 0000000..9ca02a3
--- /dev/null
+++ b/chars/1.xcf
Binary files differ
diff --git a/chars/2.xbm b/chars/2.xbm
new file mode 100644
index 0000000..b88cc50
--- /dev/null
+++ b/chars/2.xbm
@@ -0,0 +1,4 @@
+#define c2_width 5
+#define c2_height 8
+static unsigned char c2_bits[] = {
+ 0x1f, 0x10, 0x10, 0x1f, 0x01, 0x01, 0x01, 0x1f };
diff --git a/chars/2.xcf b/chars/2.xcf
new file mode 100644
index 0000000..05d2415
--- /dev/null
+++ b/chars/2.xcf
Binary files differ
diff --git a/chars/3.xbm b/chars/3.xbm
new file mode 100644
index 0000000..5723c18
--- /dev/null
+++ b/chars/3.xbm
@@ -0,0 +1,4 @@
+#define c3_width 5
+#define c3_height 8
+static unsigned char c3_bits[] = {
+ 0x1f, 0x10, 0x10, 0x1f, 0x10, 0x10, 0x10, 0x1f };
diff --git a/chars/3.xcf b/chars/3.xcf
new file mode 100644
index 0000000..f1796d3
--- /dev/null
+++ b/chars/3.xcf
Binary files differ
diff --git a/chars/4.xbm b/chars/4.xbm
new file mode 100644
index 0000000..419d375
--- /dev/null
+++ b/chars/4.xbm
@@ -0,0 +1,4 @@
+#define c4_width 5
+#define c4_height 8
+static unsigned char c4_bits[] = {
+ 0x11, 0x11, 0x11, 0x1f, 0x10, 0x10, 0x10, 0x10 };
diff --git a/chars/4.xcf b/chars/4.xcf
new file mode 100644
index 0000000..6eb8a27
--- /dev/null
+++ b/chars/4.xcf
Binary files differ
diff --git a/chars/5.xbm b/chars/5.xbm
new file mode 100644
index 0000000..00eb4bc
--- /dev/null
+++ b/chars/5.xbm
@@ -0,0 +1,4 @@
+#define c5_width 5
+#define c5_height 8
+static unsigned char c5_bits[] = {
+ 0x1f, 0x01, 0x01, 0x1f, 0x10, 0x10, 0x10, 0x1f };
diff --git a/chars/5.xcf b/chars/5.xcf
new file mode 100644
index 0000000..48b178e
--- /dev/null
+++ b/chars/5.xcf
Binary files differ
diff --git a/chars/6.xbm b/chars/6.xbm
new file mode 100644
index 0000000..4b307c3
--- /dev/null
+++ b/chars/6.xbm
@@ -0,0 +1,4 @@
+#define c6_width 5
+#define c6_height 8
+static unsigned char c6_bits[] = {
+ 0x1f, 0x01, 0x01, 0x1f, 0x11, 0x11, 0x11, 0x1f };
diff --git a/chars/6.xcf b/chars/6.xcf
new file mode 100644
index 0000000..402e31c
--- /dev/null
+++ b/chars/6.xcf
Binary files differ
diff --git a/chars/7.xbm b/chars/7.xbm
new file mode 100644
index 0000000..345352e
--- /dev/null
+++ b/chars/7.xbm
@@ -0,0 +1,4 @@
+#define c7_width 5
+#define c7_height 8
+static unsigned char c7_bits[] = {
+ 0x1f, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };
diff --git a/chars/7.xcf b/chars/7.xcf
new file mode 100644
index 0000000..49ad0eb
--- /dev/null
+++ b/chars/7.xcf
Binary files differ
diff --git a/chars/8.xbm b/chars/8.xbm
new file mode 100644
index 0000000..0b1b1ca
--- /dev/null
+++ b/chars/8.xbm
@@ -0,0 +1,4 @@
+#define c8_width 5
+#define c8_height 8
+static unsigned char c8_bits[] = {
+ 0x1f, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11, 0x1f };
diff --git a/chars/8.xcf b/chars/8.xcf
new file mode 100644
index 0000000..879b641
--- /dev/null
+++ b/chars/8.xcf
Binary files differ
diff --git a/chars/9.xbm b/chars/9.xbm
new file mode 100644
index 0000000..2e6c2cd
--- /dev/null
+++ b/chars/9.xbm
@@ -0,0 +1,4 @@
+#define c9_width 5
+#define c9_height 8
+static unsigned char c9_bits[] = {
+ 0x1f, 0x11, 0x11, 0x1f, 0x10, 0x10, 0x10, 0x1f };
diff --git a/chars/9.xcf b/chars/9.xcf
new file mode 100644
index 0000000..8c7c6fd
--- /dev/null
+++ b/chars/9.xcf
Binary files differ
diff --git a/chars/chars.c b/chars/chars.c
new file mode 100644
index 0000000..de72a10
--- /dev/null
+++ b/chars/chars.c
@@ -0,0 +1,118 @@
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "../libleds.h"
+#include "chars.h"
+
+#include "space.xbm"
+#include "0.xbm"
+#include "1.xbm"
+#include "2.xbm"
+#include "3.xbm"
+#include "4.xbm"
+#include "5.xbm"
+#include "6.xbm"
+#include "7.xbm"
+#include "8.xbm"
+#include "9.xbm"
+
+static unsigned char *get_char_bits(char c) {
+ switch (c) {
+ case ' ':
+ return cspace_bits;
+ case '0':
+ return c0_bits;
+ case '1':
+ return c1_bits;
+ case '2':
+ return c2_bits;
+ case '3':
+ return c3_bits;
+ case '4':
+ return c4_bits;
+ case '5':
+ return c5_bits;
+ case '6':
+ return c6_bits;
+ case '7':
+ return c7_bits;
+ case '8':
+ return c8_bits;
+ case '9':
+ return c9_bits;
+ default:
+ return NULL;
+ }
+}
+
+static char is_active(unsigned char const *bits, unsigned int const i)
+{
+ /*
+ * The first led is in the top left corner.
+ * After that it goes down the column, then up the next and so on.
+ *
+ * This means all columns with an even index count down.
+ * Those with an odd index count up.
+ *
+ *
+ * With a height of 8 the led numbers would look like this:
+ *
+ * 00 0F 10 1F 20 ...
+ * 01 0E 11 1E 21 ...
+ * 02 0D 12 1D ...
+ * 03 0C 13 1C ...
+ * 04 0B 14 1B ...
+ * 05 0A 15 1A ...
+ * 06 09 16 19 ...
+ * 07 08 17 18 ...
+ */
+
+ unsigned int const bytes_per_row = ceil(char_width / 8.0);
+ unsigned int col = i / char_height;
+ unsigned int row = i % char_height;
+ if (col % 2)
+ row = char_height - 1 - row;
+
+ // calculate byte to access
+ unsigned int byte = row * bytes_per_row;
+ byte += col / 8;
+
+ unsigned char data = bits[byte];
+ unsigned char mask = 1<<(col % 8);
+ return data & mask;
+}
+
+static char leds_write_char(const struct led_color color, char c, struct led_color *buf)
+{
+ unsigned char *bits = get_char_bits(c);
+ if (bits == NULL)
+ return 0;
+
+ for (unsigned int i = 0; i < char_length; i++) {
+ if (is_active(bits, i))
+ buf[i] = color;
+ else
+ buf[i] = (struct led_color){0, 0, 0};
+ }
+
+ return 1;
+}
+
+struct led_color *leds_text(struct led_color const color, const char *text)
+{
+ unsigned int const len = strlen(text);
+ struct led_color *buf = calloc(
+ sizeof(struct led_color), len * char_length
+ );
+
+ for (unsigned int i = 0; i < len; i++) {
+ if (!leds_write_char(color, text[i], buf + i*char_length)) {
+ // Invalid char
+ free(buf);
+ return NULL;
+ }
+ }
+
+ return buf;
+}
diff --git a/chars/chars.h b/chars/chars.h
new file mode 100644
index 0000000..91c7ea7
--- /dev/null
+++ b/chars/chars.h
@@ -0,0 +1,10 @@
+#ifndef CHARS_CHARS_H
+#define CHARS_CHARS_H
+
+#define char_width (5+1)
+#define char_height 8
+#define char_length (char_width * char_height)
+
+struct led_color *leds_text(struct led_color const color, const char *text);
+
+#endif /* !CHARS_CHARS_H */
diff --git a/chars/space.xbm b/chars/space.xbm
new file mode 100644
index 0000000..7b4791b
--- /dev/null
+++ b/chars/space.xbm
@@ -0,0 +1,4 @@
+#define cspace_width 5
+#define cspace_height 8
+static unsigned char cspace_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
diff --git a/chars/space.xcf b/chars/space.xcf
new file mode 100644
index 0000000..c32a481
--- /dev/null
+++ b/chars/space.xcf
Binary files differ