WasabiFan / ev3dev-lang-js

JavaScript language bindings for ev3dev
56 stars 8 forks source link

ev3dev.Ev3Leds.redLeft.flash repeorts error :EACCES, permission denied '/sys/class/leds/ev3:left:red:ev3dev/delay_on' #26

Open aifer2007 opened 6 years ago

aifer2007 commented 6 years ago

Hi,

I install ev3dev on my LEGO EV3.

My code:

var ev3dev = require("ev3dev-lang");
if(!ev3dev.Ev3Leds.isConnected) {
    console.error("This sample can only run on the EV3 brick. Other platforms are not supported by this script.");
    process.exit(1);
  }
ev3dev.Ev3Leds.redLeft.flash(1,1);

Error reported:

There was an error while writing to the property file "/sys/class/leds/ev3:left:red:ev3dev/delay_on".
Inner error:
  Error: EACCES, permission denied '/sys/class/leds/ev3:left:red:ev3dev/delay_on'

The I check /sys/class/leds/ev3:left:red:ev3dev for delay_on :

robot@ev3dev:~/app$ cd /sys/class/leds/ev3:left:red:ev3dev
robot@ev3dev:/sys/class/leds/ev3:left:red:ev3dev$ ls
brightness  device  max_brightness  power  subsystem  trigger  uevent

There is no delay_on file.

What should I do?

aifer2007 commented 6 years ago

I try the code and get the same error

var redLeft = new ev3dev.LED("ev3:left:red:ev3dev");
var redRight = new ev3dev.LED("ev3:right:red:ev3dev");
redLeft.flash(1,1);
redRight.flash(1,1);

But the code below works well.

var redLeft = new ev3dev.LED("ev3:left:red:ev3dev");
var redRight = new ev3dev.LED("ev3:right:red:ev3dev");
redLeft.on();
redRight.on();
WasabiFan commented 6 years ago

I think there are two problems here. First, there is a known issue with the LED drivers where the delay_* properties are only created once trigger is set, and there is a small delay between those two events occurring (https://github.com/ev3dev/ev3dev/issues/225). Second, I think the ordering is wrong here:

https://github.com/WasabiFan/ev3dev-lang-js/blob/d4dd1af840978b82c309a0acbebe1fa87e9a9466/src/extras.ts#L235-L239

So, as a stopgap, I'd suggest adding ev3dev.Ev3Leds.redLeft.trigger = "timer" (and likewise for other LEDs) to the top of your program.