diff options
| author | Tobias Wiese <tobias@tobiaswiese.com> | 2021-05-03 23:58:30 +0200 |
|---|---|---|
| committer | Tobias Wiese <tobias@tobiaswiese.com> | 2021-07-22 02:26:29 +0200 |
| commit | 68b5f182af145fdd9e62c9dde3eedcb9108f5ba4 (patch) | |
| tree | 67c0011276b30f8f785b934be44044935f78bd73 /img_mono.c | |
Signed-off-by: Tobias Wiese <tobias@tobiaswiese.com>
Diffstat (limited to 'img_mono.c')
| -rw-r--r-- | img_mono.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/img_mono.c b/img_mono.c new file mode 100644 index 0000000..b711a6b --- /dev/null +++ b/img_mono.c @@ -0,0 +1,58 @@ +#include <math.h> +#include "libleds.h" +#include "img_mono.xbm" + +static char const PORT = 0; +static char const PINS = 1<<7; + +char const is_active(unsigned int const n) +{ + /* + * 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(img_width / 8.0); + unsigned int col = n / img_height; + unsigned int row = n % img_height; + if (col % 2) + row = img_height - 1 - row; + + // calculate byte to access + unsigned int byte = row * bytes_per_row; + byte += col / 8; + + unsigned char data = img_bits[byte]; + unsigned char mask = 1<<(col % 8); + return data & mask; +} + +void led_main() +{ + const int length = img_width * img_height; + + struct led_color pixel[length]; + + for (unsigned int i = 0; i < length; i++) { + unsigned char out = is_active(i) ? 0xFF : 0x00; + pixel[i] = (struct led_color){out, out, out}; + } + + for (unsigned int i = 0; i < length; i++) + led_write_rgb(PORT, PINS, pixel[i]); +} |
