sensor calibration file

107 views
Skip to first unread message

namaRyo

unread,
Jun 14, 2010, 11:29:42 PM6/14/10
to android-porting
Hi, this is nama.

I made "sensors.default.so" for arm9 dev.board - Armadillo440 (http://
www.atmark-techno.com/products/armadillo/a440)
use I2C accelerometer and magnetic filed sensors. and calculate to
orientation.

I want to save sensor calibration data to internal file at
"sensors.c". and try, but, permission error occurred.

How can I write to internal file system from "sensors.default.so" ?

thanks,

Deva R

unread,
Jun 15, 2010, 2:51:18 PM6/15/10
to r.ik...@gmail.com, android-porting
There might be better ways, but to start with you can refer our sample debug code, where we dump video frame data to files in filesystem.
http://git.omapzoom.org/?p=platform/hardware/ti/omap3.git;a=blob;f=liboverlay/v4l2_utils.c;h=cdedf1bb9af61eb0b2aa831840fd611993603e7f;hb=refs/heads/eclair#l719

from native libraries, you can do file operations with below calls..
fopen(filepath)
fwrite()
fclose()

Also, you might want to make sure the filepath have write access for the process (a simple `chmod 777 <filepath>` will suffice)

-Deva


RYO IKUYAMA

unread,
Jun 15, 2010, 10:27:10 PM6/15/10
to Deva R, android-porting
Hi, Deva

Thanks advice and sample code.
Before, I used fputs() and fgets(). then, fputs() was not able to be
done though fgets() was able to be done. filepath permission is set to
777 beforehand.
Is the place of the folder path(.data/misc/cal/) bad? or should I
use fwrite() ?
I try by using fwrite.

sensors.c (file write test)
------------
#define CALIBRATION_FILE "/data/misc/cal/sensors.cal"

static native_handle_t* control__open_data_source(struct
sensors_control_context_t *dev)
{
LOGD("control__open_data_source()");
native_handle_t* handle;
int fd = open_input(O_RDONLY);
if (fd < 0) {
return NULL;
}

handle = native_handle_create(1, 0);
handle->data[0] = fd;

LOGD("open calibration file '%s'",CALIBRATION_FILE);
if ((fp = fopen(CALIBRATION_FILE, "rw")) == NULL) {
LOGE("Couldn't open '%s'",CALIBRATION_FILE);
} else {
fputs("ABCDEFGHIJKLMN", fp);
fclose(fp);
}

return handle;
}


--
nama

Akash Choudhari

unread,
Jun 16, 2010, 8:41:32 AM6/16/10
to r.ik...@gmail.com, Deva R, android-porting
FWRITE should work in your case

- Akash

Deva R

unread,
Jun 16, 2010, 4:01:04 PM6/16/10
to Akash Choudhari, r.ik...@gmail.com, android-porting
is fopen() successful or does it return errorcode?


>if ((fp = fopen(CALIBRATION_FILE, "rw")) == NULL) {
can you try fopen(CALIBRATION_FILE, "w+")?
i dont feel "rw" is right mode to pass..

-Deva

RYO IKUYAMA

unread,
Jun 16, 2010, 9:54:15 PM6/16/10
to Akash Choudhari, Deva R, android-porting
thanks Akash,

I have not tried it yet you off the schedule. I'll try today or tomorrow.

--
nama

RYO IKUYAMA

unread,
Jun 16, 2010, 10:09:49 PM6/16/10
to Deva R, Akash Choudhari, android-porting
Thank you Deva,

I'll try to fix it soon and report results again.

--
nama

RYO IKUYAMA

unread,
Jun 17, 2010, 12:11:51 AM6/17/10
to Deva R, Akash Choudhari, android-porting
hi Deva,

I fixed fopen(filename, "rw") to fopen(filename, "w+").
then I can write to file.
simple mistake!! I am shame..

Thanks a lot.

--
nama

Reply all
Reply to author
Forward
0 new messages