From 2629e41a547e92367dee895f1d6082b5aed31e42 Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 2 Jun 2025 13:26:40 +0300 Subject: [PATCH] Init --- Inc/AudioPlayerInterface.h | 52 ++++++++++++++++++++++++++++++++++++++ Src/AudioPlayerInterface.c | 34 +++++++++++++++++++++++++ modular.json | 12 +++++++++ 3 files changed, 98 insertions(+) create mode 100644 Inc/AudioPlayerInterface.h create mode 100644 Src/AudioPlayerInterface.c create mode 100644 modular.json diff --git a/Inc/AudioPlayerInterface.h b/Inc/AudioPlayerInterface.h new file mode 100644 index 0000000..050d639 --- /dev/null +++ b/Inc/AudioPlayerInterface.h @@ -0,0 +1,52 @@ +// +// Created by xemon on 17.11.22. +// + +#ifndef UVEOS_ON_NATION_AUDIOPLAYERINTERFACE_H +#define UVEOS_ON_NATION_AUDIOPLAYERINTERFACE_H + +#include "stdint.h" +#include "stddef.h" +#include "stdbool.h" + +typedef bool (*audioPlayerCallStart)(void *env, char *sampleName, uint16_t sampleNameLength, uint32_t timeout); + +typedef bool (*audioPlayerCall)(void *env, uint32_t timeout); + +typedef bool (*audioPlayerTone)(void *env, uint32_t count); + +typedef struct { + void *env; + audioPlayerCallStart start; + audioPlayerCallStart startToEnd; + audioPlayerCall wait; + audioPlayerCall stop; + audioPlayerCall isBusy; + audioPlayerTone startTone; +} tAudioPlayerInterface; + +bool AudioPlayerInterfacePlay(tAudioPlayerInterface *env, char *sampleName, uint16_t snLength, uint32_t timeout); +bool AudioPlayerInterfacePlayToEnd(tAudioPlayerInterface *env, char *sampleName, uint16_t snLength, uint32_t timeout); + +bool AudioPlayerInterfacePlayTone(tAudioPlayerInterface *env, uint16_t count); + +#define AudioPlayer_Start(PLAYER, NAME, LEN, TIMEOUT) PLAYER->start((PLAYER)->env,NAME,LEN,TIMEOUT) +#define AudioPlayer_Wait(PLAYER, TIMEOUT) PLAYER->wait((PLAYER)->env,TIMEOUT) +#define AudioPlayer_IsBusy(PLAYER, TIMEOUT) PLAYER->isBusy((PLAYER)->env,TIMEOUT) +#define AudioPlayer_Stop(PLAYER, TIMEOUT) PLAYER->stop((PLAYER)->env,TIMEOUT) + +#define AudioPlayer_Play(PLAYER, NAME, LEN, TIMEOUT) AudioPlayerInterfacePlay(PLAYER,NAME,LEN,TIMEOUT) +#define AudioPlayer_PlayStatic(PLAYER, NAME, TIMEOUT) AudioPlayer_Play(PLAYER,NAME,sizeof(NAME)-1,TIMEOUT) +#define AudioPlayer_StartToEnd(PLAYER, NAME, LEN, TIMEOUT) PLAYER->startToEnd((PLAYER)->env,NAME,LEN,TIMEOUT) + +#define AudioPlayer_PlayToEnd(PLAYER, NAME, LEN, TIMEOUT) AudioPlayerInterfacePlayToEnd(PLAYER,NAME,LEN,TIMEOUT) +#define AudioPlayer_PlayToWait(PLAYER, NAME, TIMEOUT) AudioPlayer_PlayToEnd(PLAYER,NAME,sizeof(NAME)-1,TIMEOUT) + +#define AudioPlayer_PlayTone(PLAYER, COUNT) PLAYER->startTone((PLAYER)->env,COUNT) + +#define AudioPlayer_StartToEnd(PLAYER, NAME, LEN, TIMEOUT) PLAYER->startToEnd((PLAYER)->env,NAME,LEN,TIMEOUT) +#define AudioPlayer_PlayToTone(PLAYER, COUNT) AudioPlayerInterfacePlayTone(PLAYER,COUNT) +#define AudioPlayer_PlayStaticTone(PLAYER, COUNT) AudioPlayer_PlayToTone(PLAYER,COUNT) + + +#endif //UVEOS_ON_NATION_AUDIOPLAYERINTERFACE_H diff --git a/Src/AudioPlayerInterface.c b/Src/AudioPlayerInterface.c new file mode 100644 index 0000000..1a5526c --- /dev/null +++ b/Src/AudioPlayerInterface.c @@ -0,0 +1,34 @@ +// +// Created by xemon on 17.11.22. +// +#include +#include "AudioPlayerInterface.h" + +bool AudioPlayerInterfacePlay(tAudioPlayerInterface *env, char *sampleName, uint16_t snLength, uint32_t timeout) { + uint32_t end = SystemGetMs() + timeout; + + while (end > SystemGetMs()){ + if (AudioPlayer_Start(env, sampleName, snLength, timeout)) { + return true; + } + SystemDelayMs(500); + } + SystemDelayMs(500); + return false; +} + +bool AudioPlayerInterfacePlayTone(tAudioPlayerInterface *env, uint16_t count) { + if (AudioPlayer_PlayTone(env, count)) { + return true; + } + SystemDelayMs(500); + return false; +} + +bool AudioPlayerInterfacePlayToEnd(tAudioPlayerInterface *env, char *sampleName, uint16_t snLength, uint32_t timeout) { + if (AudioPlayer_StartToEnd(env, sampleName, snLength, timeout)) { + return true; + } + SystemDelayMs(500); + return false; +} \ No newline at end of file diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..d4d574e --- /dev/null +++ b/modular.json @@ -0,0 +1,12 @@ +{ + "dep": [ + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file