3#include <SFML/Window/Joystick.hpp>
4#include <SFML/Window/Keyboard.hpp>
10#include <boost/asio/read.hpp>
11#include <boost/asio/write.hpp>
12#include <boost/program_options.hpp>
18 const std::map<std::string, std::string> &ffmpegOptions) {
19 spdlog::info(
"initializing");
22 sf::Joystick::update();
23 auto joystick_connected = sf::Joystick::isConnected(0);
24 if (!joystick_connected) {
25 spdlog::error(
"no joystick connected");
28 spdlog::info(
"joystick connected");
30 spdlog::info(
"intializing ffmpeg");
32 std::vector<std::unique_ptr<FFmpegFrameSink>> sinks{};
33 sinks.push_back(std::make_unique<VideoFrameSink>());
34 AVChannelLayout channel_layout = AV_CHANNEL_LAYOUT_MONO;
35 sinks.push_back(std::make_unique<AudioFrameSink>(
36 channel_layout, AV_SAMPLE_FMT_S16, 48000,
true, 48000));
38 std::unique_ptr<FFmpegRecorder> recorder{std::make_unique<FFmpegRecorder>(
39 vm[
"inputFormat"].as<std::string>(), vm[
"deviceName"].as<std::string>(),
40 ffmpegOptions, sinks)};
42 spdlog::info(
"ffmpeg intialized");
43 spdlog::info(
"loading input config");
46 static_cast<unsigned int>(vm[
"controls.modifier"].as<
int>());
47 auto stopMacros = [modifierButton,
48 stopButton =
static_cast<unsigned int>(
49 vm[
"controls.stopMacros"].as<
int>())] {
50 return sf::Joystick::isButtonPressed(0, stopButton) &&
51 sf::Joystick::isButtonPressed(0, modifierButton);
54 [modifierButton, recordBtn =
static_cast<unsigned int>(
55 vm[
"controls.record"].as<
int>())] {
56 return sf::Joystick::isButtonPressed(0, recordBtn) &&
57 sf::Joystick::isButtonPressed(0, modifierButton);
59 [modifierButton, playBtn =
static_cast<unsigned int>(
60 vm[
"controls.playLastRecorded"].as<
int>())] {
61 return sf::Joystick::isButtonPressed(0, playBtn) &&
62 sf::Joystick::isButtonPressed(0, modifierButton);
64 spdlog::info(
"input config loaded");
65 spdlog::info(
"loading macros");
69 {macroRecorder.getLastRecordedMacro()});
70 spdlog::info(
"macros loaded");
72 std::unique_ptr<boost::asio::serial_port> port;
73 boost::asio::io_service io;
77 std::array<uint8_t, 8> send;
78 unsigned char recieve[1];
80 spdlog::info(
"Ready");
83 sf::Joystick::update();
89 macroRecorder.update(send);
96 constexpr auto mergeFunction =
97 []([[maybe_unused]] std::array<uint8_t, 8> action1,
98 std::array<uint8_t, 8> action2) {
return action2; };
99 send = macroCollection.
getData(send, mergeFunction);
102 boost::asio::write(*port, boost::asio::buffer(send, 8));
103 boost::asio::read(*port, boost::asio::buffer(recieve, 1));
MacroCollection getMacroConfig(VideoFrameSink *videoFrameSink, AudioFrameSink *audioFrameSink, std::vector< std::shared_ptr< Macro > > macros)
Definition: MacroConfig.h:15
void testSerialPort(std::unique_ptr< boost::asio::serial_port > &serialPort, boost::asio::io_service &io)
Definition: SerialPort.h:37
std::unique_ptr< boost::asio::serial_port > initializeSerialPort(std::string serialPort, unsigned int baud, boost::asio::io_service &io)
Definition: SerialPort.h:12
void StartController(boost::program_options::variables_map vm, const std::map< std::string, std::string > &ffmpegOptions)
Definition: StartController.h:17
Definition: AudioFrameSink.h:14
Definition: Controller.h:11
std::array< uint8_t, 8 > getData() const
Definition: Controller.h:163
Definition: MacroCollection.h:7
bool isMacroActive() const
Definition: MacroCollection.h:61
void deactivateMacros()
Definition: MacroCollection.h:62
std::array< uint8_t, 8 > getData(std::array< uint8_t, 8 > intitial, const std::function< std::array< uint8_t, 8 >(std::array< uint8_t, 8 >, std::array< uint8_t, 8 >)> mergeFunction)
Definition: MacroCollection.h:21
void activateMacros()
Definition: MacroCollection.h:54
Definition: MacroRecorder.h:7
Definition: VideoFrameSink.h:17