From df3c0e6c987726753f2dd421876c8e6130091335 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 11 Jul 2022 09:39:33 -0700 Subject: [PATCH] Added libmpdclient and basic fifo sync code --- .gitmodules | 3 +++ Makefile | 25 ++++++++++++++++--------- libs/libmpdclient | 1 + src/main.cpp | 20 ++++++++++++++++++-- 4 files changed, 38 insertions(+), 11 deletions(-) create mode 160000 libs/libmpdclient diff --git a/.gitmodules b/.gitmodules index a9e37c2..d9b5f5a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "libs/spdlog"] path = libs/spdlog 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 diff --git a/Makefile b/Makefile index d0f80d5..dbd90b5 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ clean: @echo "" -libs: $(BUILD_DIR)/hid.o +libs: $(BUILD_DIR)/hid.o $(BUILD_DIR)/libmpdclient.o .PHONY: clean all run libs @@ -26,7 +26,9 @@ CPPFLAGS := -MMD -MP \ -Wall \ -I src \ -I libs/hidapi/hidapi \ - -I libs/spdlog/include + -I libs/spdlog/include \ + -I libs/libmpdclient/include \ + -I libs/libmpdclient/output # udev: required by hidapi LDFLAGS := -l fftw3 -l udev @@ -35,7 +37,7 @@ LDFLAGS := -l fftw3 -l udev SRCS := $(shell find $(SRC_DIRS) -name '*.cpp') # Turns src/a.cpp into build/src/a.cpp.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) # Turns build/a.cpp.o into build/a.cpp.d DEPS := $(OBJS:.o=.d) @@ -47,19 +49,26 @@ DEPS := $(OBJS:.o=.d) ### Libraries # Build hidapi -HIDAPI_PATH := libs/hidapi $(BUILD_DIR)/hid.o: @mkdir -p $(BUILD_DIR) @echo "Compiling hid.o" @gcc -Wall -g -fpic -c \ - -I $(HIDAPI_PATH)/hidapi \ + -I libs/hidapi/hidapi \ `pkg-config libusb-1.0 --cflags` \ - \ - $(HIDAPI_PATH)/linux/hid.c \ + libs/hidapi/linux/hid.c \ -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 # C++ build step @@ -72,7 +81,5 @@ $(BUILD_DIR)/%.cpp.o: %.cpp $(TARGET_EXEC) : $(OBJS) g++ $(OBJS) -o $@ $(LDFLAGS) - - # Include generated makefiles -include $(DEPS) \ No newline at end of file diff --git a/libs/libmpdclient b/libs/libmpdclient new file mode 160000 index 0000000..7124a0a --- /dev/null +++ b/libs/libmpdclient @@ -0,0 +1 @@ +Subproject commit 7124a0ad4841a44db084bb785a6e7120bc8f0139 diff --git a/src/main.cpp b/src/main.cpp index 211621a..95ebd32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,8 @@ // For sleep #include #include +// MPD client +#include "mpd/client.h" // Local files #include "utility/bitmap.hpp" @@ -50,6 +52,8 @@ const size_t width = 10; const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP; + + int main(int argc, char *argv[]) { spdlog::set_level(spdlog::level::info); @@ -90,15 +94,26 @@ int main(int argc, char *argv[]) { std::chrono::steady_clock, std::chrono::nanoseconds > 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) { if (Dox.is_connected()) { if (std::chrono::steady_clock::now() > t + std::chrono::milliseconds(30)) { 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(); fft.update(buf); @@ -140,5 +155,6 @@ int main(int argc, char *argv[]) { } } + mpd_connection_free(conn); return 0; } \ No newline at end of file