diff --git a/RELENTLESS/include/asset.h b/RELENTLESS/include/asset.h index 4cc6dbb..682e510 100644 --- a/RELENTLESS/include/asset.h +++ b/RELENTLESS/include/asset.h @@ -85,4 +85,4 @@ static void draw_image(lv_obj_t *canvas, int x, int y, v5_image *image) { } } -#endif // _ASSET_H_ \ No newline at end of file +#endif // _ASSET_H_ diff --git a/RELENTLESS/include/gif-pros/gifclass.hpp b/RELENTLESS/include/gif-pros/gifclass.hpp new file mode 100644 index 0000000..fd45aa7 --- /dev/null +++ b/RELENTLESS/include/gif-pros/gifclass.hpp @@ -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); + +}; \ No newline at end of file diff --git a/RELENTLESS/include/gif-pros/gifdec.h b/RELENTLESS/include/gif-pros/gifdec.h new file mode 100644 index 0000000..293801e --- /dev/null +++ b/RELENTLESS/include/gif-pros/gifdec.h @@ -0,0 +1,58 @@ +#ifndef GIFDEC_H +#define GIFDEC_H + +#include +#include +#include + +#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 */ diff --git a/RELENTLESS/include/main.h b/RELENTLESS/include/main.h index 57a8447..7dd0d88 100644 --- a/RELENTLESS/include/main.h +++ b/RELENTLESS/include/main.h @@ -47,6 +47,8 @@ #include "autons.hpp" #include "superstructure.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 diff --git a/RELENTLESS/project.pros b/RELENTLESS/project.pros index acd6567..c035ba6 100644 --- a/RELENTLESS/project.pros +++ b/RELENTLESS/project.pros @@ -27,6 +27,142 @@ "user_files": [], "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": { "location": "C:\\Users\\cjans\\AppData\\Roaming\\PROS\\templates\\kernel@3.8.0", "metadata": {