1
0
Fork 0

Use AnimationDef

This commit is contained in:
Pedro de Oliveira 2017-03-28 22:33:26 +01:00
parent e7c7c88f8a
commit 3516804e8c
4 changed files with 29 additions and 45 deletions

View File

@ -7,12 +7,10 @@ typedef struct {
} SpriteDef; } SpriteDef;
typedef struct { typedef struct {
uint8_t width;
uint8_t height;
uint8_t frames; uint8_t frames;
SpriteDef sprite[]; uint8_t *buffer[5];
} AnimationDef; } AnimationDef;
extern SpriteDef sprite_0; extern AnimationDef animation;
extern SpriteDef sprite_1;
extern SpriteDef sprite_2;
extern SpriteDef sprite_3;
extern SpriteDef sprite_4;

View File

@ -98,8 +98,8 @@ int main(void)
//drawLine(0,2, 150, 2); //drawLine(0,2, 150, 2);
//drawLine(0,4, 150, 4); //drawLine(0,4, 150, 4);
ssd1306_LoadImage(); //ssd1306_LoadImage();
ssd1306_UpdateScreen(); //ssd1306_UpdateScreen();
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
@ -110,7 +110,7 @@ int main(void)
//ssd1306_ScrollUp(64, 0); //ssd1306_ScrollUp(64, 0);
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
//ssd1306_Fill(Black); ssd1306_Fill(Black);
/* /*
int x, msg; int x, msg;
@ -126,7 +126,7 @@ int main(void)
//cube_Update(60); //cube_Update(60);
*/ */
//ssd1306_Anim(); ssd1306_Anim();
ssd1306_UpdateScreen(); ssd1306_UpdateScreen();
//HAL_Delay(100); //HAL_Delay(100);
} }

View File

@ -1,6 +1,6 @@
#include "sprites.h" #include "sprites.h"
static const uint8_t sprite_0_Buf[185] = { uint8_t sprite_0_Buf[185] = {
0x78, 0x9c, 0x8d, 0xd0, 0xbb, 0x0d, 0x83, 0x30, 0x10, 0x00, 0x78, 0x9c, 0x8d, 0xd0, 0xbb, 0x0d, 0x83, 0x30, 0x10, 0x00,
0xd0, 0xb3, 0x4e, 0x22, 0x8d, 0x85, 0xdb, 0x74, 0x59, 0x81, 0xd0, 0xb3, 0x4e, 0x22, 0x8d, 0x85, 0xdb, 0x74, 0x59, 0x81,
0x0d, 0x58, 0x85, 0x11, 0x28, 0xe9, 0x4c, 0x14, 0x89, 0x19, 0x0d, 0x58, 0x85, 0x11, 0x28, 0xe9, 0x4c, 0x14, 0x89, 0x19,
@ -22,7 +22,7 @@ static const uint8_t sprite_0_Buf[185] = {
0x6f, 0x90, 0x66, 0x8d, 0xa6, 0x6f, 0x90, 0x66, 0x8d, 0xa6,
}; };
static const uint8_t sprite_1_Buf[152] = { uint8_t sprite_1_Buf[152] = {
0x78, 0x9c, 0xb5, 0xd0, 0x31, 0x0e, 0x84, 0x20, 0x10, 0x05, 0x78, 0x9c, 0xb5, 0xd0, 0x31, 0x0e, 0x84, 0x20, 0x10, 0x05,
0x50, 0x27, 0x26, 0xd0, 0x6c, 0xa4, 0xb5, 0xe3, 0x0a, 0x78, 0x50, 0x27, 0x26, 0xd0, 0x6c, 0xa4, 0xb5, 0xe3, 0x0a, 0x78,
0x01, 0xce, 0x02, 0x37, 0xf0, 0x00, 0x26, 0x83, 0x37, 0xe3, 0x01, 0xce, 0x02, 0x37, 0xf0, 0x00, 0x26, 0x83, 0x37, 0xe3,
@ -41,7 +41,7 @@ static const uint8_t sprite_1_Buf[152] = {
0x6a, 0x70, 0x6a, 0x70,
}; };
static const uint8_t sprite_2_Buf[156] = { uint8_t sprite_2_Buf[156] = {
0x78, 0x9c, 0x8d, 0xd0, 0xb1, 0x09, 0xc5, 0x20, 0x10, 0x06, 0x78, 0x9c, 0x8d, 0xd0, 0xb1, 0x09, 0xc5, 0x20, 0x10, 0x06,
0xe0, 0x48, 0xc0, 0xd7, 0x48, 0x6c, 0x5f, 0xe7, 0x0a, 0xd9, 0xe0, 0x48, 0xc0, 0xd7, 0x48, 0x6c, 0x5f, 0xe7, 0x0a, 0xd9,
0xc0, 0x59, 0xb2, 0x41, 0x20, 0x4d, 0xba, 0x73, 0x12, 0x67, 0xc0, 0x59, 0xb2, 0x41, 0x20, 0x4d, 0xba, 0x73, 0x12, 0x67,
@ -60,7 +60,7 @@ static const uint8_t sprite_2_Buf[156] = {
0xf8, 0x01, 0x4a, 0xd2, 0x77, 0x8c, 0xf8, 0x01, 0x4a, 0xd2, 0x77, 0x8c,
}; };
static const uint8_t sprite_3_Buf[171] = { uint8_t sprite_3_Buf[171] = {
0x78, 0x9c, 0xb5, 0xd0, 0xd1, 0x09, 0x83, 0x30, 0x10, 0x06, 0x78, 0x9c, 0xb5, 0xd0, 0xd1, 0x09, 0x83, 0x30, 0x10, 0x06,
0x60, 0x43, 0x20, 0x7d, 0x39, 0x74, 0x01, 0xc1, 0x15, 0x6e, 0x60, 0x43, 0x20, 0x7d, 0x39, 0x74, 0x01, 0xc1, 0x15, 0x6e,
0x80, 0x82, 0xab, 0x54, 0x5c, 0x40, 0xf0, 0x55, 0xb8, 0x40, 0x80, 0x82, 0xab, 0x54, 0x5c, 0x40, 0xf0, 0x55, 0xb8, 0x40,
@ -81,7 +81,7 @@ static const uint8_t sprite_3_Buf[171] = {
0xd5, 0xd5,
}; };
static const uint8_t sprite_4_Buf[143] = { uint8_t sprite_4_Buf[143] = {
0x78, 0x9c, 0x8d, 0xd0, 0xc1, 0x0d, 0xc3, 0x20, 0x0c, 0x05, 0x78, 0x9c, 0x8d, 0xd0, 0xc1, 0x0d, 0xc3, 0x20, 0x0c, 0x05,
0xd0, 0x58, 0x48, 0xf4, 0x82, 0xd2, 0x11, 0x98, 0x21, 0x77, 0xd0, 0x58, 0x48, 0xf4, 0x82, 0xd2, 0x11, 0x98, 0x21, 0x77,
0x44, 0x56, 0x29, 0x62, 0x10, 0x37, 0x8b, 0x64, 0x16, 0x8f, 0x44, 0x56, 0x29, 0x62, 0x10, 0x37, 0x8b, 0x64, 0x16, 0x8f,
@ -99,8 +99,15 @@ static const uint8_t sprite_4_Buf[143] = {
0x13, 0x61, 0x67, 0x13, 0x61, 0x67,
}; };
SpriteDef sprite_0 = {64, 64, sprite_0_Buf}; AnimationDef animation = {
SpriteDef sprite_1 = {64, 64, sprite_1_Buf}; .width = 64,
SpriteDef sprite_2 = {64, 64, sprite_2_Buf}; .height = 64,
SpriteDef sprite_3 = {64, 64, sprite_3_Buf}; .frames = 5,
SpriteDef sprite_4 = {64, 64, sprite_4_Buf}; .buffer = {
sprite_0_Buf,
sprite_1_Buf,
sprite_2_Buf,
sprite_3_Buf,
sprite_4_Buf,
}
};

View File

@ -119,35 +119,14 @@ void ssd1306_DrawSprite(SpriteDef sprite, int16_t x, int16_t y) {
} }
void ssd1306_Anim(void) { void ssd1306_Anim(void) {
SpriteDef *srcSprite;
SpriteDef dstSprite; SpriteDef dstSprite;
uint16_t dstSize; uint16_t dstSize;
switch(anim) { dstSize = animation.height * animation.width / 8;
case 0: dstSprite.width = animation.width;
srcSprite = &sprite_0; dstSprite.height = animation.height;
break;
case 1:
srcSprite = &sprite_1;
break;
case 2:
srcSprite = &sprite_2;
break;
case 3:
srcSprite = &sprite_3;
break;
case 4:
srcSprite = &sprite_4;
break;
}
dstSize = srcSprite->height * srcSprite->width / 8;
dstSprite.width = srcSprite->width;
dstSprite.height = srcSprite->height;
dstSprite.buffer = malloc(sizeof(uint8_t) * (dstSize)); dstSprite.buffer = malloc(sizeof(uint8_t) * (dstSize));
ssd1306_Decompress(animation.buffer[anim], dstSprite.buffer, dstSize);
ssd1306_Decompress(srcSprite->buffer, dstSprite.buffer, dstSize);
ssd1306_DrawSprite(dstSprite, x, 0); ssd1306_DrawSprite(dstSprite, x, 0);