46 lines
1004 B
C++
46 lines
1004 B
C++
#include "Led.h"
|
|
#include "stringex.hpp"
|
|
|
|
#define LEDPATH "%s/%s/%s"
|
|
|
|
std::string Led::timer = "timer";
|
|
std::string Led::none = "none";
|
|
|
|
Led::Led(std::string name)
|
|
{
|
|
path_brightness = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_brightness.c_str());
|
|
path_trigger = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_trigger.c_str());
|
|
path_delay_off = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_delay_off.c_str());
|
|
path_delay_on = string_format(LEDPATH, path_base.c_str(), name.c_str(), path_delay_on.c_str());
|
|
}
|
|
|
|
Led::~Led()
|
|
{
|
|
}
|
|
|
|
void Led::on(int time_ms)
|
|
{
|
|
if (time_ms != 0)
|
|
{
|
|
write_dev(path_trigger, timer);
|
|
write_dev(path_delay_off, time_ms);
|
|
write_dev(path_delay_on, time_ms);
|
|
}
|
|
else
|
|
{
|
|
// if (read_dev_s(path_trigger).find(none) == std::string::npos)
|
|
write_dev(path_trigger, none);
|
|
}
|
|
write_dev(path_brightness, 1);
|
|
}
|
|
|
|
void Led::off()
|
|
{
|
|
write_dev(path_brightness, 0);
|
|
}
|
|
|
|
bool Led::isOn()
|
|
{
|
|
return (bool)read_dev_i(path_brightness);
|
|
}
|