make the gif thing a template

This commit is contained in:
ary 2023-11-03 08:33:48 -04:00
parent 8f9207d6c6
commit aaef039932
5 changed files with 266 additions and 1 deletions

View File

@ -0,0 +1,69 @@
#pragma once
#include "main.h"
#include "gifdec.h"
/**
* MIT License
* Copyright (c) 2019 Theo Lemay
* https://github.com/theol0403/gif-pros
*/
class Gif {
public:
/**
* Construct the Gif class
* @param fname the gif filename on the SD card (prefixed with /usd/)
* @param parent the LVGL parent object
*/
Gif(const asset file, lv_obj_t* parent);
/**
* Destructs and cleans the Gif class
*/
~Gif();
/**
* Pauses the GIF task
*/
void pause();
/**
* Resumes the GIF task
*/
void resume();
/**
* Deletes GIF and frees all allocated memory
*/
void clean();
private:
gd_GIF* _gif = nullptr; // gif decoder object
void* _gifmem = nullptr; // gif file loaded from SD into memory
uint8_t* _buffer = nullptr; // decoder frame buffer
lv_color_t* _cbuf = nullptr; // canvas buffer
lv_obj_t* _canvas = nullptr; // canvas object
pros::task_t _task = nullptr; // render task
/**
* Cleans and frees all allocated memory
*/
void _cleanup();
/**
* Render cycle, blocks until loop count exceeds gif loop count flag (if any)
*/
void _render();
/**
* Calls _render()
* @param arg Gif*
*/
static void _render_task(void* arg);
};

View File

@ -0,0 +1,58 @@
#ifndef GIFDEC_H
#define GIFDEC_H
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define BYTES_PER_PIXEL 4
typedef struct gd_Palette {
int size;
uint8_t colors[0x100 * 3];
} gd_Palette;
typedef struct gd_GCE {
uint16_t delay;
uint8_t tindex;
uint8_t disposal;
int input;
int transparency;
} gd_GCE;
typedef struct gd_GIF {
FILE *fp;
off_t anim_start;
uint16_t width, height;
uint16_t depth;
uint16_t loop_count;
gd_GCE gce;
gd_Palette *palette;
gd_Palette lct, gct;
void (*plain_text)(
struct gd_GIF *gif, uint16_t tx, uint16_t ty,
uint16_t tw, uint16_t th, uint8_t cw, uint8_t ch,
uint8_t fg, uint8_t bg
);
void (*comment)(struct gd_GIF *gif);
void (*application)(struct gd_GIF *gif, char id[8], char auth[3]);
uint16_t fx, fy, fw, fh;
uint8_t bgindex;
uint8_t *canvas, *frame;
} gd_GIF;
gd_GIF *gd_open_gif(FILE *fp);
int gd_get_frame(gd_GIF *gif);
void gd_render_frame(gd_GIF *gif, uint8_t *buffer);
void gd_rewind(gd_GIF *gif);
void gd_close_gif(gd_GIF *gif);
#ifdef __cplusplus
}
#endif
#endif /* GIFDEC_H */

View File

@ -47,6 +47,8 @@
#include "autons.hpp" #include "autons.hpp"
#include "superstructure.hpp" #include "superstructure.hpp"
#include "globals.hpp" #include "globals.hpp"
#include "asset.h"
#include "gif-pros/gifclass.hpp"
/** /**
* If you find doing pros::Motor() to be tedious and you'd prefer just to do * If you find doing pros::Motor() to be tedious and you'd prefer just to do

View File

@ -27,6 +27,142 @@
"user_files": [], "user_files": [],
"version": "0.4.7" "version": "0.4.7"
}, },
"gif-pros-asset": {
"location": "C:\\Users\\cjans\\AppData\\Roaming\\PROS\\templates\\gif-pros-asset@1.0.1",
"metadata": {
"origin": "local"
},
"name": "gif-pros-asset",
"py/object": "pros.conductor.templates.local_template.LocalTemplate",
"supported_kernels": "^3.8.0",
"system_files": [
"include\\display\\lv_core\\lv_style.h",
"include\\pros\\optical.h",
"include\\pros\\llemu.hpp",
"include\\display\\lv_conf.h",
"include\\display\\lv_misc\\lv_templ.h",
"include\\display\\lv_objx\\lv_canvas.h",
"include\\display\\lvgl.h",
"include\\display\\lv_objx\\lv_lmeter.h",
"include\\display\\lv_misc\\lv_font.h",
"include\\display\\lv_objx\\lv_slider.h",
"include\\pros\\serial.hpp",
"include\\display\\lv_draw\\lv_draw_vbasic.h",
"include\\api.h",
"include\\display\\lv_core\\lv_group.h",
"include\\display\\lv_objx\\lv_spinbox.h",
"include\\display\\lv_draw\\lv_draw_triangle.h",
"include\\display\\lv_hal\\lv_hal_tick.h",
"include\\display\\lv_objx\\lv_calendar.h",
"include\\pros\\ext_adi.h",
"include\\display\\lv_draw\\lv_draw_rbasic.h",
"include\\display\\lv_draw\\lv_draw_arc.h",
"include\\display\\lv_objx\\lv_mbox.h",
"include\\display\\lv_objx\\lv_btn.h",
"include\\pros\\rtos.hpp",
"include\\display\\lv_version.h",
"include\\pros\\rtos.h",
"include\\gif-pros\\gifclass.hpp",
"include\\pros\\gps.hpp",
"include\\display\\lv_draw\\lv_draw_rect.h",
"include\\display\\lv_objx\\lv_label.h",
"include\\display\\lv_objx\\lv_preload.h",
"include\\display\\lv_themes\\lv_theme_default.h",
"include\\display\\lv_misc\\lv_ufs.h",
"include\\pros\\colors.h",
"include\\display\\lv_objx\\lv_win.h",
"include\\display\\lv_objx\\lv_gauge.h",
"include\\pros\\rotation.h",
"include\\display\\lv_themes\\lv_theme_zen.h",
"include\\display\\lv_themes\\lv_theme.h",
"include\\display\\lv_draw\\lv_draw_label.h",
"include\\display\\lv_objx\\lv_kb.h",
"include\\display\\lv_core\\lv_obj.h",
"include\\display\\lv_objx\\lv_line.h",
"include\\pros\\vision.h",
"include\\pros\\screen.hpp",
"include\\display\\lv_themes\\lv_theme_nemo.h",
"include\\display\\lv_core\\lv_refr.h",
"include\\display\\lv_objx\\lv_btnm.h",
"include\\display\\lv_objx\\lv_led.h",
"include\\display\\lv_draw\\lv_draw.h",
"include\\pros\\distance.h",
"include\\display\\lv_objx\\lv_arc.h",
"include\\display\\lv_misc\\lv_color.h",
"include\\display\\lv_misc\\lv_math.h",
"include\\display\\lv_objx\\lv_cont.h",
"include\\display\\lv_objx\\lv_objx_templ.h",
"include\\display\\lv_objx\\lv_imgbtn.h",
"include\\display\\lv_misc\\lv_mem.h",
"include\\gif-pros\\gifdec.h",
"include\\display\\lv_objx\\lv_bar.h",
"include\\display\\lv_fonts\\lv_font_builtin.h",
"include\\pros\\misc.h",
"include\\pros\\gps.h",
"include\\display\\lv_objx\\lv_roller.h",
"include\\pros\\apix.h",
"include\\display\\lv_themes\\lv_theme_templ.h",
"include\\pros\\imu.hpp",
"include\\display\\lv_misc\\lv_gc.h",
"include\\display\\lv_misc\\lv_txt.h",
"include\\display\\lv_core\\lv_lang.h",
"include\\display\\lv_objx\\lv_ddlist.h",
"include\\display\\lv_objx\\lv_table.h",
"include\\display\\lv_themes\\lv_theme_mono.h",
"include\\display\\lv_objx\\lv_list.h",
"include\\display\\lv_themes\\lv_theme_material.h",
"include\\pros\\rotation.hpp",
"include\\asset.h",
"include\\pros\\colors.hpp",
"include\\display\\lv_objx\\lv_cb.h",
"include\\display\\lv_misc\\lv_symbol_def.h",
"include\\display\\lv_objx\\lv_page.h",
"include\\display\\lv_core\\lv_indev.h",
"include\\pros\\vision.hpp",
"include\\pros\\api_legacy.h",
"include\\main.h",
"include\\pros\\adi.h",
"include\\display\\lv_misc\\lv_anim.h",
"firmware\\gif-pros-asset.a",
"include\\pros\\screen.h",
"include\\display\\lv_hal\\lv_hal_indev.h",
"include\\display\\lv_themes\\lv_theme_night.h",
"include\\display\\lv_draw\\lv_draw_img.h",
"include\\display\\lv_misc\\lv_log.h",
"include\\pros\\optical.hpp",
"include\\pros\\imu.h",
"include\\pros\\distance.hpp",
"include\\display\\lv_conf_checker.h",
"include\\pros\\motors.h",
"include\\pros\\llemu.h",
"include\\display\\lv_misc\\lv_area.h",
"include\\display\\lv_objx\\lv_sw.h",
"include\\pros\\link.h",
"include\\display\\lv_misc\\lv_task.h",
"include\\display\\lv_draw\\lv_draw_line.h",
"include\\pros\\link.hpp",
"include\\display\\lv_hal\\lv_hal_disp.h",
"include\\pros\\adi.hpp",
"include\\display\\lv_core\\lv_vdb.h",
"include\\pros\\serial.h",
"include\\display\\lv_objx\\lv_chart.h",
"include\\display\\lv_hal\\lv_hal.h",
"include\\display\\lv_objx\\lv_tileview.h",
"include\\display\\lv_themes\\lv_theme_alien.h",
"include\\pros\\error.h",
"include\\display\\lv_misc\\lv_ll.h",
"include\\display\\lv_objx\\lv_img.h",
"include\\display\\lv_objx\\lv_tabview.h",
"include\\pros\\misc.hpp",
"include\\display\\lv_objx\\lv_ta.h",
"include\\pros\\motors.hpp",
"include\\display\\lv_misc\\lv_circ.h",
"include\\display\\lv_misc\\lv_fs.h"
],
"target": "v5",
"user_files": [],
"version": "1.0.1"
},
"kernel": { "kernel": {
"location": "C:\\Users\\cjans\\AppData\\Roaming\\PROS\\templates\\kernel@3.8.0", "location": "C:\\Users\\cjans\\AppData\\Roaming\\PROS\\templates\\kernel@3.8.0",
"metadata": { "metadata": {