/* * @brief Unregister all the sensors */ void unregisterSensors() { for (int type=1; type<=SENSOR_TYPES; type++) { maSensorStop(type); } }
void PhoneGapSensors::sendCompassData(MASensor sensorData) { if (true == mCompassWatchStarted) { // We are sending the event continuously. sendCompassData(mCompassWatchCallBack, sensorData); } else { sendCompassData(mCompassWatchCallBack, sensorData); // Stop the sensor since it was a one time call. maSensorStop(SENSOR_TYPE_COMPASS); } }
void PhoneGapSensors::sendAccelerometerData(MASensor sensorData) { if (true == mAccelerometerWatchStarted) { // We are sending the event continuously. sendAccelerometerData(mAccelerometerWatchCallBack, sensorData); } else { sendAccelerometerData(mAccelerometerWatchCallBack, sensorData); // Stop the sensor since it was a one time call. maSensorStop(SENSOR_TYPE_ACCELEROMETER); } }
/** * Implementation of sensor API:s exposed to JavaScript. * @return true if message was handled, false if not. */ void PhoneGapSensors::handleMessage(JSONMessage& message) { // Accelerometer request from PhoneGap if ((message.getParam("service") == "Accelerometer")) { if (message.getParam("action") == "getAcceleration") { processAcelerometerRequest( message.getParam("PhoneGapCallBackId"), false); //stop Accelerometer after the first run } else if (message.getParam("action") == "start") { processAcelerometerRequest( message.getParam("PhoneGapCallBackId"), true); // Keep the Accelerometer running } else if (message.getParam("action") == "stop") { maSensorStop(SENSOR_TYPE_ACCELEROMETER); mAccelerometerWatchStarted = false; } } // GeoLocation request from PhoneGap else if (message.getParam("service") == "GeoLocation") { if (message.getParam("action") == "addWatch") { processLocationRequest( message.getParam("PhoneGapCallBackId"), true); } else if (message.getParam("action") == "getLocation") { processLocationRequest( message.getParam("PhoneGapCallBackId"), false); //stop GPS after the first run } else if (message.getParam("action") == "clearWatch") { maLocationStop(); mLocationWatchStarted = false; } } // Compass request from PhoneGap else if (message.getParam("service") == "Compass") { if(message.getParam("action") == "getHeading") { processCompassRequest( message.getParam("PhoneGapCallBackId"), false); //stop Sensor after the first run } // Cordova 2.3.0 doesn't use Compass.startWatch /* else if (message.getParam("action") == "startWatch") { processCompassRequest( message.getParam("PhoneGapCallBackId"), true); // Keep the Compass running } */ else if (message.getParam("action") == "stopHeading") { maSensorStop(SENSOR_TYPE_COMPASS); mAccelerometerWatchStarted = false; } } }