#include #include "cmd_line_args.h" #include "easylogging++.h" #include "easylogging++.cc" #include "task_manager.hpp" #include #include #include #include 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 << " }"; } inline std::ostream& operator<< (std::ostream &out, const std::ifstream &input) { std::string line; while (std::getline(const_cast(input), line).good()) { out << line << std::endl; } return out; } 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); LOG(INFO) << opts; if(opts.config_file.empty()) { LOG(WARNING) << "Config file is not set! So we use hardcoded configuration:" << std::endl << schedule.str(); } else { std::ifstream input{opts.config_file}; LOG(INFO) << "Config file:" << std::endl << input; } std::ifstream input{opts.config_file}; std::istream &stream = !opts.config_file.empty() && input.is_open() ? static_cast(input) : static_cast(schedule); TaskManager manager{stream, 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; }