Added libmpdclient and basic fifo sync code

master
Mark 2022-07-11 09:39:33 -07:00
parent 928dc8d820
commit df3c0e6c98
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
4 changed files with 38 additions and 11 deletions

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "libs/spdlog"] [submodule "libs/spdlog"]
path = libs/spdlog path = libs/spdlog
url = ssh://git@git.betalupi.com:33/mirrors-libs/spdlog.git url = ssh://git@git.betalupi.com:33/mirrors-libs/spdlog.git
[submodule "libs/libmpdclient"]
path = libs/libmpdclient
url = ssh://git@git.betalupi.com:33/mirrors-libs/libmpdclient.git

View File

@ -14,7 +14,7 @@ clean:
@echo "" @echo ""
libs: $(BUILD_DIR)/hid.o libs: $(BUILD_DIR)/hid.o $(BUILD_DIR)/libmpdclient.o
.PHONY: clean all run libs .PHONY: clean all run libs
@ -26,7 +26,9 @@ CPPFLAGS := -MMD -MP \
-Wall \ -Wall \
-I src \ -I src \
-I libs/hidapi/hidapi \ -I libs/hidapi/hidapi \
-I libs/spdlog/include -I libs/spdlog/include \
-I libs/libmpdclient/include \
-I libs/libmpdclient/output
# udev: required by hidapi # udev: required by hidapi
LDFLAGS := -l fftw3 -l udev LDFLAGS := -l fftw3 -l udev
@ -35,7 +37,7 @@ LDFLAGS := -l fftw3 -l udev
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp') SRCS := $(shell find $(SRC_DIRS) -name '*.cpp')
# Turns src/a.cpp into build/src/a.cpp.o # Turns src/a.cpp into build/src/a.cpp.o
SRC_OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) SRC_OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
LIB_OBJS := $(BUILD_DIR)/hid.o LIB_OBJS := $(BUILD_DIR)/hid.o $(BUILD_DIR)/libmpdclient.o
OBJS = $(SRC_OBJS) $(LIB_OBJS) OBJS = $(SRC_OBJS) $(LIB_OBJS)
# Turns build/a.cpp.o into build/a.cpp.d # Turns build/a.cpp.o into build/a.cpp.d
DEPS := $(OBJS:.o=.d) DEPS := $(OBJS:.o=.d)
@ -47,19 +49,26 @@ DEPS := $(OBJS:.o=.d)
### Libraries ### Libraries
# Build hidapi # Build hidapi
HIDAPI_PATH := libs/hidapi
$(BUILD_DIR)/hid.o: $(BUILD_DIR)/hid.o:
@mkdir -p $(BUILD_DIR) @mkdir -p $(BUILD_DIR)
@echo "Compiling hid.o" @echo "Compiling hid.o"
@gcc -Wall -g -fpic -c \ @gcc -Wall -g -fpic -c \
-I $(HIDAPI_PATH)/hidapi \ -I libs/hidapi/hidapi \
`pkg-config libusb-1.0 --cflags` \ `pkg-config libusb-1.0 --cflags` \
\ libs/hidapi/linux/hid.c \
$(HIDAPI_PATH)/linux/hid.c \
-o $(BUILD_DIR)/hid.o -o $(BUILD_DIR)/hid.o
# Build libmpdclient
$(BUILD_DIR)/libmpdclient.o:
@cd libs/libmpdclient && \
meson . output && \
ninja -C output
ln -s ../libs/libmpdclient/output/libmpdclient.so $(BUILD_DIR)/libmpdclient.o
### Source ### Source
# C++ build step # C++ build step
@ -72,7 +81,5 @@ $(BUILD_DIR)/%.cpp.o: %.cpp
$(TARGET_EXEC) : $(OBJS) $(TARGET_EXEC) : $(OBJS)
g++ $(OBJS) -o $@ $(LDFLAGS) g++ $(OBJS) -o $@ $(LDFLAGS)
# Include generated makefiles # Include generated makefiles
-include $(DEPS) -include $(DEPS)

1
libs/libmpdclient Submodule

@ -0,0 +1 @@
Subproject commit 7124a0ad4841a44db084bb785a6e7120bc8f0139

View File

@ -8,6 +8,8 @@
// For sleep // For sleep
#include <chrono> #include <chrono>
#include <thread> #include <thread>
// MPD client
#include "mpd/client.h"
// Local files // Local files
#include "utility/bitmap.hpp" #include "utility/bitmap.hpp"
@ -50,6 +52,8 @@ const size_t width = 10;
const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP; const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::level::info);
@ -90,15 +94,26 @@ int main(int argc, char *argv[]) {
std::chrono::steady_clock, std::chrono::steady_clock,
std::chrono::nanoseconds std::chrono::nanoseconds
> t = std::chrono::steady_clock::now(); > t = std::chrono::steady_clock::now();
//t += std::chrono::milliseconds(30);
//this_thread::sleep_until(t);
std::chrono::time_point<
std::chrono::steady_clock,
std::chrono::nanoseconds
> last_fifo_sync = std::chrono::steady_clock::now();
struct mpd_connection *conn = mpd_connection_new(NULL, 0, 0);
while (1) { while (1) {
if (Dox.is_connected()) { if (Dox.is_connected()) {
if (std::chrono::steady_clock::now() > t + std::chrono::milliseconds(30)) { if (std::chrono::steady_clock::now() > t + std::chrono::milliseconds(30)) {
if (Dox.get_animation_mode() == 0x02) { if (Dox.get_animation_mode() == 0x02) {
if (std::chrono::steady_clock::now() > last_fifo_sync + std::chrono::seconds(10)) {
mpd_run_disable_output(conn, 1);
mpd_run_enable_output(conn, 1);
last_fifo_sync = std::chrono::steady_clock::now();
spdlog::info("Synchronized fifo");
}
buf.update(); buf.update();
fft.update(buf); fft.update(buf);
@ -140,5 +155,6 @@ int main(int argc, char *argv[]) {
} }
} }
mpd_connection_free(conn);
return 0; return 0;
} }