Files
MTGcompanion/main/scryfall_client.h
Rasmus e6760e4866
All checks were successful
ESP32 Build & Release / build (push) Successful in 1m16s
faster image processing
2026-09-13 23:31:36 +02:00

80 lines
1.8 KiB
C

/*
* MTG RFID Companion - Scryfall API client (Core 0)
*
* Phase 5: HTTPS card lookups with cJSON parsing and LittleFS caching of
* metadata + card art. Runs on the dedicated net_task.
*/
#pragma once
#include "esp_err.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SCRYFALL_API "https://api.scryfall.com"
#define SCRYFALL_CARD_ARTS_URL "/cards/named?exact="
/**
* @brief Start the net_task (waits for Wi-Fi, prefetches mapping cache,
* then serves fetch requests). Must be called after wifi start.
*/
esp_err_t scryfall_client_start(void);
/**
* @brief Queue an async fetch by exact card name (net_task performs it).
* @param card_name Exact card name, e.g. "Sol Ring"
* @param uid Uppercase hex UID used for cache filenames
*/
esp_err_t scryfall_fetch_request(const char *card_name, const char *uid);
/**
* @brief True if net_task finished a fetch attempt since last consumption.
*/
bool scryfall_has_pending_result(void);
/**
* @brief True if the last fetch succeeded, false if it failed.
*/
bool scryfall_last_result_success(void);
/**
* @brief UID of the most recently fetched card.
*/
const char *scryfall_last_result_uid(void);
/**
* @brief Clear the pending-result flag.
*/
void scryfall_consume_result(void);
/**
* @brief True if net_task finished an image fetch attempt.
*/
bool scryfall_has_pending_image(void);
/**
* @brief True if the last image fetch succeeded.
*/
bool scryfall_last_image_success(void);
/**
* @brief UID of the most recently fetched card image.
*/
const char *scryfall_last_image_uid(void);
/**
* @brief Clear the pending image result flag.
*/
void scryfall_consume_image(void);
/**
* @brief True if an image download is actively in progress for this UID.
*/
bool scryfall_is_fetching_image(const char *uid);
#ifdef __cplusplus
}
#endif