Files
CYD-HomeBoard/include/kdeconnect.h
T

58 lines
2.3 KiB
C

// Minimal KDE Connect client: pairing + MPRIS (what is playing where, album art, control).
// Runs in its own FreeRTOS task; the functions below are safe to call from the UI loop.
#pragma once
#include <stdint.h>
#include <stddef.h>
static constexpr int KDE_ART_SIZE = 120; // album art is scaled/cropped to this square (RGB565)
struct NowPlaying {
bool valid = false; // something is known (playing or paused)
bool playing = false;
bool canSeek = false;
bool pinned = false; // the user picked this source manually
int volume = -1; // 0..100, -1 = unknown
char device[33] = "";
char player[33] = "";
char title[97] = "";
char artist[65] = "";
char album[65] = "";
int32_t posMs = 0, lenMs = 0; // position at atMs (millis())
uint32_t atMs = 0;
uint32_t seq = 0; // changes whenever title/artist/state/device/volume change
uint32_t artSeq = 0; // changes whenever the album art buffer changes
bool hasArt = false;
char artInfo[48] = ""; // why there is no album art (shown instead of the picture)
};
struct PlayerEntry {
char key[72];
char device[33];
char player[33];
char title[49];
bool playing;
bool selected;
};
void kdeStart(const char* deviceName);
void kdeGetNowPlaying(NowPlaying& out);
// Album art of the current track, KDE_ART_SIZE x KDE_ART_SIZE RGB565 (nullptr if none yet).
const uint16_t* kdeArt();
// Returns a non-zero id while a pairing request waits for an answer and copies the device name.
uint32_t kdePairRequest(char* name, size_t n);
void kdeAnswerPair(bool accept);
// "PlayPause", "Next", "Previous" for the player shown in kdeGetNowPlaying.
void kdeMediaAction(const char* action);
void kdeSetVolume(int volume);
void kdeSeek(int32_t posMs);
// All known players of connected, paired devices.
int kdeListPlayers(PlayerEntry* out, int max);
// Show this player instead of picking automatically (nullptr = automatic again).
void kdeSelectPlayer(const char* key);
// The UI tells whether the cover is needed (music view open); otherwise its memory is released.
void kdeSetArtWanted(bool wanted);
// Status text for the display: connections, SD card, free memory, last error.
void kdeStatus(char* out, size_t n);
// Number of paired devices currently connected.
int kdeConnectedCount();