You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

73 lines
2.1 KiB

#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 << " }";
}
inline std::ostream& operator<< (std::ostream &out, const std::ifstream &input) {
std::string line;
while (std::getline(const_cast<std::ifstream &>(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<std::istream&>(input) : static_cast<std::istream&>(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;
}