From de0ac733c03798dd8555f5931052b83cdb6c79b9 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Wed, 3 Oct 2018 20:20:35 +0000 Subject: [PATCH] Progress with animations --- drivers/fbani_starhopper.c | 21 ++++++++++++++++ drivers/fbani_starhopper.h | 1 + drivers/fbticker.c | 51 ++++++++++++++++++++++++++++++++++++++ drivers/fbticker.h | 1 + drivers/framebuffer.c | 29 ++++++++++++++++++++++ pingpong.c | 25 +++++++++++++------ 6 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 drivers/fbani_starhopper.c create mode 100644 drivers/fbani_starhopper.h create mode 100644 drivers/fbticker.c create mode 100644 drivers/fbticker.h diff --git a/drivers/fbani_starhopper.c b/drivers/fbani_starhopper.c new file mode 100644 index 0000000..460d4c0 --- /dev/null +++ b/drivers/fbani_starhopper.c @@ -0,0 +1,21 @@ +#include +#include "framebuffer.h" + +#define HALFW (FB_WIDTH/2) +#define HALFH (FB_HEIGHT/2) + +void fbani_starhopper_print_rectangles(uint8_t v) { + fb_area(0 ,0 ,HALFW ,HALFH , (v >> 3) & 1); + fb_area(HALFW,0 ,2*HALFW,HALFH , (v >> 2) & 1); + fb_area(0 ,HALFH,HALFW ,2*HALFH, (v >> 1) & 1); + fb_area(HALFW,HALFH,2*HALFW,2*HALFH, (v ) & 1); +} + +void fbani_starhopper(uint16_t count) { + while(count--) { + fbani_starhopper_print_rectangles(0x0e); + _delay_ms(600); + fbani_starhopper_print_rectangles(0x0b); + _delay_ms(150); + }; +} diff --git a/drivers/fbani_starhopper.h b/drivers/fbani_starhopper.h new file mode 100644 index 0000000..1d35d91 --- /dev/null +++ b/drivers/fbani_starhopper.h @@ -0,0 +1 @@ +void fbani_starhopper(uint16_t count); diff --git a/drivers/fbticker.c b/drivers/fbticker.c new file mode 100644 index 0000000..578cb78 --- /dev/null +++ b/drivers/fbticker.c @@ -0,0 +1,51 @@ +#include "framebuffer.h" +#include + +void fbticker_pushcol(uint8_t col) { + fb_shift(col << 1); + _delay_ms(60); +} + +void fbticker_putc(unsigned char c) { + switch(c) { + case 'A': + fbticker_pushcol(0x7e); + fbticker_pushcol(0x09); + fbticker_pushcol(0x09); + fbticker_pushcol(0x09); + fbticker_pushcol(0x7e); + break; + case 'B': + fbticker_pushcol(0x7f); + fbticker_pushcol(0x49); + fbticker_pushcol(0x49); + fbticker_pushcol(0x36); + break; + case 'C': + fbticker_pushcol(0x3e); + fbticker_pushcol(0x41); + fbticker_pushcol(0x41); + fbticker_pushcol(0x22); + break; + case 'D': + fbticker_pushcol(0x7f); + fbticker_pushcol(0x41); + fbticker_pushcol(0x41); + fbticker_pushcol(0x3e); + break; + case 'E': + fbticker_pushcol(0x7f); + fbticker_pushcol(0x49); + fbticker_pushcol(0x49); + fbticker_pushcol(0x49); + break; + case 'F': + fbticker_pushcol(0x7f); + fbticker_pushcol(0x09); + fbticker_pushcol(0x09); + fbticker_pushcol(0x09); + break; + } + + fbticker_pushcol(0); +} diff --git a/drivers/fbticker.h b/drivers/fbticker.h new file mode 100644 index 0000000..440fc47 --- /dev/null +++ b/drivers/fbticker.h @@ -0,0 +1 @@ +void fbticker_putc(unsigned char c); diff --git a/drivers/framebuffer.c b/drivers/framebuffer.c index 3859211..a3a1c24 100644 --- a/drivers/framebuffer.c +++ b/drivers/framebuffer.c @@ -31,3 +31,32 @@ void fb_fill(uint8_t c) { } #endif + + +void fb_hline(uint8_t y, uint8_t x1, uint8_t x2, uint8_t c) { + uint8_t i; + for (i = x1; i <= x2; i++) { + FB_SET(i, y, c); + } +} + +void fb_vline(uint8_t x, uint8_t y1, uint8_t y2, uint8_t c) { + uint8_t i; + for (i = y1; i <= y2; i++) { + FB_SET(x, i, c); + } +} + +void fb_box(uint8_t ax, uint8_t ay, uint8_t bx, uint8_t by, uint8_t c) { + fb_hline(ay, ax, bx, c); + fb_hline(by, ax, bx, c); + fb_vline(ax, ay, by, c); + fb_vline(bx, ay, by, c); +} + +void fb_area(uint8_t ax, uint8_t ay, uint8_t bx, uint8_t by, uint8_t c) { + uint8_t i; + for (i = ay; i <= by; i++) { + fb_hline(i, ax, bx, c); + } +} diff --git a/pingpong.c b/pingpong.c index 3259648..5329c5a 100644 --- a/pingpong.c +++ b/pingpong.c @@ -1,14 +1,25 @@ #include #include "drivers/framebuffer.h" +#include "drivers/fbticker.h" +#include "drivers/fbani_starhopper.h" #include "drivers/fbani_recorder.h" -int main() { +void fbani_binary(uint16_t max) { uint16_t i = 0; - while(1) { - fbani_recorder(4); - for (i = 0; i < 256; i++) { - _delay_ms(50); - fb_shift(i); - } + for (i = 0; i < max; i++) { + _delay_ms(50); + fb_shift(i); } } + +int main() { + unsigned char c; + while(1) { + fbani_starhopper(40); + fbani_binary(256); + fbani_recorder(50); + for (c = 'A'; c <= 'Z'; c++) { + fbticker_putc(c); + } + }; +}