Play with Phidget USB 3-axis accelerometer under Sensor Framework
Thanks to pulgin system of sensor framework, various devices could be easliy supported. I'd like to cite Phidget USB 3-axis accelerometer as an example. Here is the offical link of the product:
http://www.phidgets.com/products.php?product_id=1059
Steps of installaztion:
1. Plug the accelerometer into your device
2. Launch sensor framework by:
sensord -c /etc/sensorframework/module-phidget.conf -d /usr/lib/sensorframework/modules/
You are also allowed to start framework first and then plug into the device, it's ok, what's a beauty of hot-plug :)
Here is a simple testing application uses acceleromter. It simply receives data and prints on screen
/*accel-test.c*/
#include <libsensor/sfcustomer-object.h>
#include <libsensor/accel-object.h>
static rec_count;
static void receive_cb (SFAccel* self, SFAccelVector* vec, gpointer userdata) {
AccelVector* v;
v = ACCEL_VECTOR (vec);
sf_log_debug("(fx,fy,fz,x,y,z,timestamp) = (%f,%f,%f,%f,%f,%f,%d)\n",
v->x, v->y, v->z, vec->raw_x, vec->raw_y, vec->raw_z, vec->timestamp);
}
#define DEFAULT_PERIOD (600)
gint main(gint argc, gchar* argv[]) {
SFCustomer* ctm;
SFAccel* acc;
GError* err = NULL;
SFSensorID id;
gint idcount = 0;
gulong hander_id;
guint period = 0;
if ( argc < 2 ) {
g_print ("Usage:\n"
"./accel-receive-test period_in_second\n"
"Example: ./accel-receive-test 600\n");
g_print ("Run with default period=600\n");
} else
period = atoi (argv[1]);
if ( period == 0 )
period = DEFAULT_PERIOD;
ctm = sf_customer_new (&err);
if ( !ctm ) {
g_print ("%s, Cannot create SFCustomer\n", err->message);
exit (-1);
}
acc = sf_accel_new (ctm, -1, &err);
if ( !acc ) {
g_print ("%s, Cannot create SFAccel\n", err->message);
exit (-1);
}
hander_id = sf_sensor_connect_receive_func (SF_SENSOR (acc), G_CALLBACK (receive_cb), NULL);
sf_sensor_set_active (SF_SENSOR(acc), TRUE);
sleep (period);
sf_sensor_set_active (SF_SENSOR(acc), FALSE);
sf_accel_destroy (acc);
sf_destroy (ctm);
return 0;
}Before compiling, make sure the development pakcage is rightly installed. If not, follow this:
yum install sensorframework-devel
then generate execution through:
gcc `pkg-config --libs --cflags sensorframework` accel-test.c -o accel-test
For API reference, find at here:
http://moblin.org/documentation/api-sensor-framework-accelerometer-als-t...
- Printer-friendly version
- Login or register to post comments
Comments (6 total)
MID
I compile my sensorframework.,but sensord daemon not start,how to use new sensord daemon?thanks
see "build and run" in
see "build and run" in documentations
Noe that you need to install
Noe that you need to install Phidget software before running configure, otherwise the Phidget module will not be built.
You also need to create your own module-phidget.conf as it is not in the source.
Thanks Henry!
Thanks Henry! module-phidget.conf has been included in source now.
I will try to write a script to intall phidget library also.
Welcome comments if you feel inconvenient when using framework
I tried to install
I tried to install sensorframework-devel, but it told me that no such thing exists.
Why is that?
[root@box]# yum install sensorframework-devel
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
No package sensorframework-devel available.
Nothing to do
Hi, what destribution you
Hi, what destribution you use?
RPM of sensorframework only available in Moblin destribution. If you are using Fedora or ubuntu, you have to download the source and build it by youself.
If you are using moblin, pls check if your yum repo points to right place. or you could paste your yum repo here and i will check whether the repo is correct