Skip to content

Commit

Permalink
keira: wasting time on fun stuff (closes #82)
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Apr 18, 2024
1 parent 54ae2f2 commit 4e8f080
Show file tree
Hide file tree
Showing 6 changed files with 2,578 additions and 0 deletions.
2 changes: 2 additions & 0 deletions firmware/keira/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lib_deps =
https://github.com/moononournation/arduino-nofrendo.git
bitbank2/PNGenc @ ^1.1.1
bblanchon/ArduinoJson @ ^7.0.4
bitbank2/AnimatedGIF@^2.1.0
lib_extra_dirs = ./lib
build_flags = -D LILKA_VERSION=1
board_build.partitions = ./legacy/v1_partitions.csv
Expand All @@ -30,5 +31,6 @@ lib_deps =
bblanchon/ArduinoJson @ ^7.0.4
lennarthennigs/ESP Telnet @ ^2.2.1
https://github.com/earlephilhower/ESP8266Audio.git
bitbank2/AnimatedGIF@^2.1.0
lib_extra_dirs = ./lib
extra_scripts = targets.py
68 changes: 68 additions & 0 deletions firmware/keira/src/apps/demos/petpet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <AnimatedGIF.h>

#include "petpet.h"
#include "petpet_gif.h"
#include "utils/defer.h"

// Idea by @imbirWIthSugar

PetPetApp::PetPetApp() : App("PetPet") {
}

void GIFDraw(GIFDRAW* pDraw) {
// Called once per line
PetPetApp* app = static_cast<PetPetApp*>(pDraw->pUser);
if (pDraw->y == 0) {
// First line of the frame
app->canvas->fillScreen(lilka::colors::Black);
}
int16_t x = (app->canvas->width() - petpet_gif_width) / 2;
int16_t y = (app->canvas->height() - petpet_gif_height) / 2 + pDraw->y;
uint16_t* pixels = reinterpret_cast<uint16_t*>(pDraw->pPixels);
if (pDraw->ucHasTransparency) {
app->canvas->draw16bitRGBBitmapWithTranColor(
x, y, pixels, pDraw->pPalette[pDraw->ucTransparent], petpet_gif_width, 1
);
} else {
app->canvas->draw16bitRGBBitmap(x, y, pixels, petpet_gif_width, 1);
}
if (pDraw->y == petpet_gif_height - 1) {
// Last line of the frame
app->queueDraw();
}
}

void* GIFAlloc(uint32_t u32Size) {
return ps_malloc(u32Size);
}

void GIFFree(void* p) {
free(p);
}

void PetPetApp::run() {
AnimatedGIF* gif = new AnimatedGIF();
std::unique_ptr<AnimatedGIF> gif_ptr(gif);

gif->begin();
if (!gif->open(const_cast<uint8_t*>(petpet_gif), petpet_gif_size, GIFDraw)) {
lilka::serial_log("Failed to open GIF");
return;
}
Defer closeGif([&gif] { gif->close(); });

if (gif->allocFrameBuf(GIFAlloc) != GIF_SUCCESS) {
lilka::serial_log("Failed to allocate frame buffer");
return;
}
Defer freeFrameBuf([&gif] { gif->freeFrameBuf(GIFFree); });

gif->setDrawType(GIF_DRAW_COOKED);
while (1) {
gif->playFrame(true, NULL, this);
lilka::State state = lilka::controller.getState();
if (state.a.justPressed) {
break;
}
}
}
Binary file added firmware/keira/src/apps/demos/petpet.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions firmware/keira/src/apps/demos/petpet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "app.h"

class PetPetApp : public App {
public:
PetPetApp();

private:
void run() override;
};
Loading

0 comments on commit 4e8f080

Please sign in to comment.