Skip to content

Commit df97389

Browse files
committed
[cpp] Sync led::delay_{on,off} properties with sysfs attributes
Fixed naming; added readers; allow chaining of writers
1 parent 2ace929 commit df97389

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: ev3dev.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,8 @@ void led::flash(unsigned interval_ms)
839839
for (int i = 0; ; ++i) {
840840
std::this_thread::sleep_for(std::chrono::milliseconds(100));
841841
try {
842-
set_on_delay (interval_ms);
843-
set_off_delay(interval_ms);
842+
set_delay_on (interval_ms);
843+
set_delay_off(interval_ms);
844844
break;
845845
} catch(...) {
846846
if (i >= 5) throw;

Diff for: ev3dev.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,18 @@ class led : protected device
12391239
void off() { set_brightness(0); }
12401240

12411241
void flash(unsigned interval_ms);
1242-
void set_on_delay (unsigned ms) { set_attr_int("delay_on", ms); }
1243-
void set_off_delay(unsigned ms) { set_attr_int("delay_off", ms); }
1242+
1243+
int delay_on() const { return get_attr_int("delay_on"); }
1244+
auto set_delay_on (int ms) -> decltype(*this) {
1245+
set_attr_int("delay_on", ms);
1246+
return *this;
1247+
}
1248+
1249+
int delay_off() const { return get_attr_int("delay_off"); }
1250+
auto set_delay_off(unsigned ms) -> decltype(*this) {
1251+
set_attr_int("delay_off", ms);
1252+
return *this;
1253+
}
12441254

12451255
static led red_right;
12461256
static led red_left;

0 commit comments

Comments
 (0)