|
|
|
#include <wiringPi.h>
|
|
|
|
#include "cmd_line_args.h"
|
|
|
|
#include "easylogging++.h"
|
|
|
|
#include "easylogging++.cc"
|
|
|
|
#include "task_manager.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
|
|
INITIALIZE_EASYLOGGINGPP
|
|
|
|
|
|
|
|
#define PIN 0
|
|
|
|
|
|
|
|
static std::stringstream schedule = std::stringstream(
|
|
|
|
"0 0 10 ? * MON-SAT HIGH(0)\n"
|
|
|
|
"0 0 13 ? * MON-SAT LOW(0)\n"
|
|
|
|
"0 0 15 ? * MON-SAT HIGH(0)\n"
|
|
|
|
"0 0 19 ? * MON-SAT LOW(0)\n"
|
|
|
|
"* * * * * SUN LOW(0)\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
inline std::ostream& operator<< (std::ostream &out, const app_options &opts) {
|
|
|
|
return out << "Options: { "
|
|
|
|
<< "config-file: " << opts.config_file << ", "
|
|
|
|
<< "initial-pin-state: " << opts.initial_pin_state << " }";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Filename, APP_NAME ".log");
|
|
|
|
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::ToStandardOutput, "true");
|
|
|
|
el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput);
|
|
|
|
|
|
|
|
app_options opts = parse_opts(argc, argv);
|
|
|
|
if(opts.config_file.empty()) {
|
|
|
|
LOG(WARNING) << "Config file is not set! So we use hardcoded configuration:" << std::endl
|
|
|
|
<< schedule.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(INFO) << opts;
|
|
|
|
TaskManager manager{schedule, digitalWrite};
|
|
|
|
|
|
|
|
wiringPiSetup ();
|
|
|
|
pinMode (PIN, OUTPUT);
|
|
|
|
digitalWrite(PIN, opts.initial_pin_state);
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
if(manager.doWork() == 0) {
|
|
|
|
std::this_thread::sleep_for(1s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|