VulcanoLE/main.cpp

71 lines
2.1 KiB
C++
Raw Normal View History

2021-02-20 18:13:51 +01:00
#include <unistd.h>
#include <iostream>
#include <VulcanoLE/API/HIDHelper.h>
#include <VUtils/Logging.h>
#include <csignal>
#include <VulcanoLE/Audio/VisAudioRunner.h>
#include <VUtils/Environment.h>
bool shouldRun = true;
void my_handler(int s) {
printf("Caught signal %d\n", s);
shouldRun = false;
}
int main(int argc, char **argv) {
// signal handler!
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = my_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, nullptr);
// Load Config...
VUtils::Environment config{VUtils::FileHandler::getFromHomeDir("/.config/VulcanoLE/state.env").c_str()};
config.loadFile();
LOG(R"(
[===============================================]
_ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \
( V | U | L | C | A | N | O ) ( L | E )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
[===============================================]
)")
HIDHelper helper{};
if (helper.openDevices() < 0) {
ERR("Unable to find Keyboard!")
exit(0);
};
usleep(10000);
auto runner = VisAudioRunner::create();
runner->env = &config;
runner->plugins->init(&helper, runner->grabber);
runner->init();
runner->plugins->setCurrentMode(config.getAsInt("visual_mode", 1));
while (shouldRun) {
int mode;
LOGWN("Enter Visual Mode: %d-%d < 0 = EXIT:\t", 1, VIZSIZE)
2021-02-20 18:13:51 +01:00
std::cin >> mode;
if (std::cin.fail()) {
ERR("ERROR -- You did not enter an integer")
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
continue;
}
if (mode < 0) {
shouldRun = false;
continue;
}
runner->plugins->setCurrentMode(mode);
}
DBG("Shutdown... Waiting for Thread to Finish!")
runner->isActive = false;
if (runner->thread.joinable()) {
runner->thread.join();
}
DBG("Exit!")
usleep(1000);
config.saveFile();
return 0;
}