Did anyone finally manage to resolve sensor access from a pure native Linux application.

53 views
Skip to first unread message

mojint...@gmail.com

unread,
Mar 17, 2015, 3:37:21 AM3/17/15
to andro...@googlegroups.com
It works great using SensorPlatforms method or Google one if you are in an Android application (native or not) :
http://developer.android.com/reference/android/app/NativeActivity.html
http://www.sensorplatforms.com/native-sampling/

But what I want to do is (like Claudio I think) access sensor from my pure native Linux application.
It compiles, links and runs without any error or warning but never receive any event in callback (see SensorPlatform method)
nor from 'ALooper_pollAll' (see Google Android doc).

I checked twice but did not commit any coding error listed in this forum about 'ALooper' nor 'createEventQueue'
(see 'ALooper_forThread', 'ALooper_prepare' and 'ASensorManager_createEventQueue').
I also checked NDK function return values but none was 'NULL'.

In short, it's weird the same code works in my Android NDK application but not in my native Linux one...


Does anyone have a clue about how to make it works ? Is it possible at all or sensor access is limited to Android apps ?


ASensorEventQueue* sensorEventQueue;

int SensorSamplingRate;

const ASensor* accSensor;

static int get_sensor_events(int fd, int events, void* data) {

  ASensorEvent event;

  printf("Hello\n");

  LOGW("Hi0!");

  while (ASensorEventQueue_getEvents(sensorEventQueue, &event, 1) > 0){

    if(event.type == ASENSOR_TYPE_ACCELEROMETER) {


LOGW("Hi!");


    }

    LOGW("Hi2!");

  }

  return 1;

}

void MySensorValue(){

ASensorEvent event;

int events, ident;

ASensorManager* sensorManager;


void* sensor_data = malloc(1000);


ALooper* looper = ALooper_forThread();


if(looper == NULL)

{

looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);

}


sensorManager = ASensorManager_getInstance();


accSensor = ASensorManager_getDefaultSensor(sensorManager,ASENSOR_TYPE_ACCELEROMETER);


sensorEventQueue = ASensorManager_createEventQueue(sensorManager,looper, 3, get_sensor_events, sensor_data);


ASensorEventQueue_enableSensor(sensorEventQueue, accSensor);


    //ASensorEventQueue_setEventRate(sensorEventQueue, accSensor, (1000L/200)*1000);


LOGI("sensor() - START   ");

}

int main(){

MySensorValue();

int c=0;

while(1){

sleep(1);

LOGI("c=%d",++c);

};

}

Reply all
Reply to author
Forward
0 new messages