Question

So you can see in this link that you have a pwm /sys/class/pwm/.

So I am currently putting the right data into the appropriate files and things are working well.

That is not the issue. The issue is that you need to do a "cat" on the /sys/class/pwm/{port}/request file before it becomes active. So if you reboot it will not work and you have to re-initiate it.

I have tried to just fopen("~request","r") hoping it would work but it doesn't. Opening it for "w" either. I also tried doing an exec() but that didn't work and is clunky anyhow. I don't want to have to make the assumptions required.

Here is my execv() code anyhow.

char *request[1];
request[0] = pwmbus;
execv("/bin/cat",request);

What is the most elegant way to cat the file? I din't need the information it outputs. It just initializes the sysfs. Otherwise I will be stuck having to manually do this or scripting it all the time.

cat /sys/class/pwm/gpio_pwm.0:0/request
sysfs 719
Was it helpful?

Solution

You can read one byte from the file:

int fd = open("/sys/class/pwm", O_RDONLY);
char buf[1];
read(fd, buf, 1);
close(fd);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top