×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    5

    Problem with Sensor API within console application

    Hello,

    I tried to get the Sensor API running within a console application (EXE). Unfortunately the HandleDataEventL of my MRRSensorDataListener never gets called.

    I think the main-loop blocks all the calls to the listener. Could I perform the sensor-init within the MainL-method and use a rescheduling CActive to pull the data out of the "l"-object?

    If you need additional information please let me know.

    Any help would be great.
    Klemens

    Code:
    /*
     ============================================================================
     Name		: AccelerationServer.cpp
     Description : Exe source file
     ============================================================================
     */
    
    //  Include Files  
    
    #include "AccelerationServer.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h>			// Console
    #include <rrsensorapi.h>
    
    //  Constants
    
    _LIT(KTextConsoleTitle, "Console");
    _LIT(KTextFailed, " failed, leave code = %d");
    _LIT(KTextPressAnyKey, " [press any key]\n");
    
    //  Global Variables
    const TInt Kacc = 0x10273024; 
    LOCAL_D CConsoleBase* console; // write all messages to this
    CRRSensorApi* c;
    class Listener : public MRRSensorDataListener {
    
    public:
    	Listener(CConsoleBase* con) {
    		console = con;
    		console->Write(_L("Constructor\n"));
    	}
    
    	void HandleDataEventL(TRRSensorInfo aSensor, TRRSensorEvent aEvent) {
    		if (aSensor.iSensorId == Kacc) {
    			x = aEvent.iSensorData1;
    			y = aEvent.iSensorData2;
    			z = aEvent.iSensorData3;
    	    }
    		
    		User::ResetInactivityTime();
    	}
    	
    	CConsoleBase* console;
    	int x;
    	int y;
    	int z;
    };
    //  Local Functions
    
    static void MainL()	{
    	console->Write(_L("Beginne mit Initialisierung\n"));
    	
    	Listener l(console);
    
    	// Get list of available sensors
    	RArray <TRRSensorInfo> sensorList;
    	CRRSensorApi::FindSensorsL(sensorList);
    
    	//Number of sensors available
    	TInt sensorCount = sensorList.Count();
    
    	for (TInt i = 0; i != sensorCount; i++) {
    	
    		console->Printf(_L("Sensor gefunden: %d\n"), sensorList[i].iSensorId);
    	
    		if (sensorList[i].iSensorId == Kacc) {
    			console->Write(_L("Acc gefunden\n"));
    			c = CRRSensorApi::NewL(sensorList[i]);
    			c->AddDataListener(&l);
    		}
    	}
    	
    	while (true) {
    		console->Printf(_L("%d:%d:%d\n"), l.x, l.y, l.z);
    		User::After(150);
    	}
    }
    
    static void DoStartL() {
    	// Create active scheduler (to run active objects)
    	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    	CleanupStack::PushL(scheduler);
    	CActiveScheduler::Install(scheduler);
    
    	MainL();
    
    	// Delete active scheduler
    	CleanupStack::PopAndDestroy(scheduler);
    }
    
    //  Global Functions
    
    GLDEF_C TInt E32Main() {
    	// Create cleanup stack
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    
    	// Create output console
    	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
    	if (createError)
    	return createError;
    
    	// Run application code inside TRAP harness, wait keypress when terminated
    	TRAPD(mainError, DoStartL());
    	if (mainError)
    	console->Printf(KTextFailed, mainError);
    	console->Printf(KTextPressAnyKey);
    	console->Getch();
    
    	delete console;
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    }
    Last edited by Saxer; 2008-07-16 at 11:04.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: Problem with Sensor API within console application

    "while (true)" is definetely blocking all other code.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    5

    Re: Problem with Sensor API within console application

    I thought User::After(150) could enable the callback. Do I have to use a CActive and reschedule it? I don't know how the callback gets invoked, so I don't know how I could give some cpu time to this.

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: Problem with Sensor API within console application

    Nope, it will hang on that line, so you should propably implement the timer with Active object or use other callbacks.

Similar Threads

  1. Cannot run console application on S60 3rd gen (nokia 6110 navigator)
    By mcbure in forum Series 40 & S60 Platform Feedback Archive
    Replies: 2
    Last Post: 2008-07-14, 19:01
  2. Console Application Exits In Emulator
    By ptilghman in forum Open C/C++
    Replies: 1
    Last Post: 2008-05-19, 20:49
  3. Please help.. regarding simple hellotext console application
    By sajidraheemsheikh in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2008-03-05, 17:02
  4. console application 3rd ed. on target
    By sym_starter in forum Symbian
    Replies: 5
    Last Post: 2006-10-11, 16:13
  5. Replies: 3
    Last Post: 2006-08-17, 10:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×