Hello !
I am currently trying to write a value in a /sys file of my mangOH Yellow.
i would like to be able to configure the accelerometer sampling frequency from my Legato application, thus I have to write into this file:
/sys/bus/i2c/devices/6-0068/iio:device0/in_accel_sampling_frequency
To change the sampling frequency from the console, you could do
echo 100 > /sys/bus/i2c/devices/6-0068/iio:device0/in_accel_sampling_frequency
But I want to do this from my Legato application.
This is why I added this file in my .adef:
requires:
{
file:
{
/sys/bus/i2c/devices/6-0068/iio:device0/in_accel_sampling_frequency /driver/
}
}
And in my source code, I can read into the file with:
#include "interfaces.h"
#include "legato.h"
#include <stdio.h>
COMPONENT_INIT
{
FILE * fp;
int accel_sampling;
fp = fopen ("/driver/in_accel_sampling_frequency","r");
fscanf(fp, "%d", &accel_sampling);
LE_INFO("Accel sampling frequency : %d", accel_sampling);
fclose(fp);
}
But now when I try to write into the same file with:
#include "interfaces.h"
#include "legato.h"
#include <stdio.h>
#include <errno.h>
COMPONENT_INIT
{
FILE * fp;
int rc;
fp = fopen ("/driver/in_accel_sampling_frequency","rw");
rc = fprintf(fp, "%d", 100);
if (rc < 0)
{
LE_INFO("errno=%d, err_msg=\"%s\"\n", errno,strerror(errno));
return;
}
fclose(fp);
}
When I run my app, I get this error:
errno=9, err_msg="Bad file descriptor
it looks like the file is read-only, but I can’t specify [rw]
in the .cdef and changing the permissions of in_accel_sampling_frequency
does not change the output…
Is it possible to do such thing ? And if it is, what am I doing wrong ?
Thanks for your help,
BR