#pragma once #include "esphome/core/component.h" #include "esphome/components/display/display.h" #include #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" class JPEGDEC; namespace esphome { namespace fast_jpeg { class FastJpeg : public PollingComponent { public: void set_url(const std::string &url) { this->url_ = url; } void set_display(display::Display *display) { this->display_ = display; } void set_x(int x) { this->x_ = x; } void set_y(int y) { this->y_ = y; } void set_big_endian(bool big_endian) { this->big_endian_ = big_endian; } void setup() override; void loop() override; void update() override; void dump_config() override; float get_setup_priority() const override { return setup_priority::AFTER_CONNECTION; } uint8_t *jpeg_buf() { return this->jpeg_buf_; } size_t jpeg_cap() const { return this->jpeg_cap_; } size_t *http_rx_len() { return &this->http_rx_len_; } char *etag() { return this->etag_; } uint8_t *back_buffer() { return this->back_; } int pending_width() const { return this->pending_w_; } int pending_height() const { return this->pending_h_; } int pending_stride() const { return this->pending_stride_; } protected: static void task_fn_(void *param); void fetch_once_(); bool decode_jpeg_(size_t len); bool ensure_framebuffers_(int width, int height); void paint_(); void clear_bars_once_(); std::string url_; display::Display *display_{nullptr}; int x_{0}; int y_{-1}; bool big_endian_{true}; uint8_t *front_{nullptr}; uint8_t *back_{nullptr}; uint8_t *jpeg_buf_{nullptr}; ::JPEGDEC *decoder_{nullptr}; size_t fb_cap_{0}; size_t jpeg_cap_{0}; int pending_w_{0}; int pending_h_{0}; int pending_stride_{0}; int w_{0}; int h_{0}; int stride_{0}; TaskHandle_t task_{nullptr}; void *http_{nullptr}; size_t http_rx_len_{0}; std::atomic busy_{false}; std::atomic decoded_ready_{false}; bool bars_cleared_{false}; char etag_[80]{}; uint32_t frames_{0}; uint32_t last_fps_log_{0}; }; } // namespace fast_jpeg } // namespace esphome