Example usage for android.hardware Sensor getType

List of usage examples for android.hardware Sensor getType

Introduction

In this page you can find the example usage for android.hardware Sensor getType.

Prototype

public int getType() 

Source Link

Usage

From source file:com.bsafe.sensors.motion.BSMotionSensorsPlugin.java

/**
 * Called when the accuracy of the sensor has changed.
 *
 * @param sensor/*  w  w w. j  a v  a  2 s .  com*/
 * @param accuracy
 */
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Only look at accelerometer events
    if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == BSMotionSensorsPlugin.STOPPED) {
        return;
    }
    this.accuracy = accuracy;
}

From source file:com.tritop.androsense2.fragments.SensorsList.java

private List<Map<String, String>> parseAvailableSensors(List<Sensor> sList) {
    List<Map<String, String>> mList = new Vector<Map<String, String>>();
    HashMap<String, String> mSensorInfo;
    for (Sensor sensor : sList) {
        mSensorInfo = new HashMap<String, String>();
        mSensorInfo.put(SENSOR_KEY_NAME, sensor.getName());
        mSensorInfo.put(SENSOR_KEY_VENDOR, sensor.getVendor());
        mSensorInfo.put(SENSOR_KEY_VERSION, SensorInfo.getStringType(getActivity(), sensor.getType()) + " v"
                + String.valueOf(sensor.getVersion()));
        mSensorInfo.put(SENSOR_KEY_POWER, SensorInfo.formatSensorfloat(sensor.getPower(), 4) + " mA");
        mSensorInfo.put(SENSOR_KEY_MAXRANGE,
                SensorInfo.formatSensorfloat(sensor.getMaximumRange(), 3) + " max");
        mSensorInfo.put(SENSOR_KEY_RESOLUTION,
                SensorInfo.formatSensorfloat(sensor.getResolution(), 4) + " res");
        mList.add(mSensorInfo);//  ww w  . j  av  a2 s .  co  m
    }
    return mList;

}

From source file:com.microsoft.band.sdksample.SensorsFragment.java

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    Sensor mySensor = sensorEvent.sensor;

    if (mySensor.getType() == Sensor.TYPE_GYROSCOPE) {
        temp_list[3] = (double) sensorEvent.values[0] * 180 / Math.PI;
        temp_list[4] = (double) sensorEvent.values[1] * 180 / Math.PI;
        temp_list[5] = (double) sensorEvent.values[2] * 180 / Math.PI;
        mTextAngX.setText(String.format("%.2f", temp_list[3]));
        mTextAngY.setText(String.format("%.2f", temp_list[4]));
        mTextAngZ.setText(String.format("%.2f", temp_list[5]));
    } else if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        temp_list[0] = (double) sensorEvent.values[0];
        temp_list[1] = (double) sensorEvent.values[1];
        temp_list[2] = (double) sensorEvent.values[2];
        mTextAccX.setText(String.format("%.3f", temp_list[0]));
        mTextAccY.setText(String.format("%.3f", temp_list[1]));
        mTextAccZ.setText(String.format("%.3f", temp_list[2]));
    }/*ww w.j a v  a 2  s.  c  o m*/
}

From source file:com.grumpysailor.cordova.magnetsensor.MagnetSensor.java

/**
 * Called when the accuracy of the sensor has changed.
 *
 * @param sensor/*from  w  w w . j  ava  2  s  .c  om*/
 * @param accuracy
 */
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Only look at accelerometer events
    if (sensor.getType() != Sensor.TYPE_MAGNETIC_FIELD) {
        return;
    }

    // If not running, then just return
    if (this.status == MagnetSensor.STOPPED) {
        return;
    }
    this.accuracy = accuracy;
}

From source file:com.tritop.androsense2.fragments.SensorsListFragment.java

private List<Map<String, String>> parseAvailableSensors(List<Sensor> sList) {
    List<Map<String, String>> mList = new Vector<Map<String, String>>();
    HashMap<String, String> mSensorInfo;
    for (Sensor sensor : sList) {
        Log.d("SENSORLIST", sensor.getName());
        mSensorInfo = new HashMap<String, String>();
        mSensorInfo.put(SENSOR_KEY_NAME, sensor.getName());
        mSensorInfo.put(SENSOR_KEY_VENDOR, sensor.getVendor());
        mSensorInfo.put(SENSOR_KEY_VERSION, SensorInfo.getStringType(getActivity(), sensor.getType()) + " v"
                + String.valueOf(sensor.getVersion()));
        mSensorInfo.put(SENSOR_KEY_POWER, SensorInfo.formatSensorfloat(sensor.getPower(), 4) + " mA");
        mSensorInfo.put(SENSOR_KEY_MAXRANGE,
                SensorInfo.formatSensorfloat(sensor.getMaximumRange(), 3) + " max");
        mSensorInfo.put(SENSOR_KEY_RESOLUTION,
                SensorInfo.formatSensorfloat(sensor.getResolution(), 4) + " res");
        mList.add(mSensorInfo);/*from w w w  .j a v  a  2  s . co m*/
    }
    return mList;

}

From source file:de.da_sense.moses.client.abstraction.HardwareAbstraction.java

/**
 * This method reads the sensors currently chosen by the user
 * @return the actual Hardwareinfo// w  w w .ja v  a 2 s  .  co  m
 */
private HardwareInfo retrieveHardwareParameters() {
    // *** SENDING SET_HARDWARE_PARAMETERS REQUEST TO SERVER ***//
    LinkedList<Integer> sensors = new LinkedList<Integer>();
    SensorManager s = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    for (Sensor sen : s.getSensorList(Sensor.TYPE_ALL)) {
        sensors.add(sen.getType());
    }
    return new HardwareInfo(extractDeviceIdFromSharedPreferences(), extractDeviceNameFromSharedPreferences(),
            Build.MANUFACTURER, Build.MODEL, Build.VERSION.SDK_INT, sensors);
}

From source file:com.example.zoeoeh.ETuner.OpenGLClass.java

@Override
public void onSensorChanged(SensorEvent event) {

    // this detects the gesture
    Sensor mySensor = event.sensor;

    // increment for strings, changes with direction
    int increment = 0;

    if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        float x = event.values[0]; // values for each axis
        float y = event.values[1];
        float z = event.values[2];

        long curTime = System.currentTimeMillis();

        if ((curTime - lastUpdate) > 200) {
            long diffTime = (curTime - lastUpdate);
            lastUpdate = curTime;/*from w  w  w .ja v  a  2 s .com*/

            boolean right;
            String direction;

            float speed = (x - last_x);

            if (speed > 0) {
                right = true;
                direction = "Right";
                increment = 1;
            } else {
                right = false;
                direction = "left";
                increment = -1;
            }

            speed = Math.abs(speed + y + z - last_y - last_z) / diffTime * 10000;

            if (speed > SHAKE_THRESHOLD) {
                // either positive or negative depending on the direction.
                currentSoundIndex += increment;

                if (currentSoundIndex < 0) {
                    currentSoundIndex = myStrings.length - 1;
                } else if (currentSoundIndex > myStrings.length - 1) {
                    currentSoundIndex = 0;
                }

                // display toast
                Toast.makeText(TabSwitcher.getmContext(),
                        "You shook me " + direction + ". Now Playing " + guitarStrings[currentSoundIndex],
                        Toast.LENGTH_SHORT).show();

                // change flag
                shakeDirty = true;

                // if play is checked, update the string
                if (playChecked) {
                    updatePlay();
                }
            }

            last_x = x;
            last_y = y;
            last_z = z;

        }

    }
}

From source file:org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedDataReader.java

private void collectSensorData() {
    for (Sensor sensor : sensorList) {
        try {/* w  ww .j  a  va2 s  .c o m*/
            if (senseDataStruct.containsKey(sensor.getName())) {
                SensorData sensorInfo = senseDataStruct.get(sensor.getName());
                sensorVector.add(sensorInfo);
                Log.d(TAG, "Sensor Name " + sensor.getName() + ", Type " + sensor.getType() + " "
                        + ", sensorValue :" + sensorInfo.getSensorValues());
            }
        } catch (Throwable e) {
            Log.d(TAG, "error on sensors");
        }
    }
    mSensorManager.unregisterListener(this);
}

From source file:ch.bfh.sensordataprocessor.sensor.SensorDisplayFragment.java

public void displaySensor(Sensor sensor) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "display the sensor");
    }//from   w  ww  .  j  a  va2 s . c o  m

    this.sensor = sensor;

    name.setText(sensor.getName());
    type.setText(String.valueOf(sensor.getType()));
    maxRange.setText(String.valueOf(sensor.getMaximumRange()));
    minDelay.setText(String.valueOf(sensor.getMinDelay()));
    power.setText(String.valueOf(sensor.getPower()));
    resolution.setText(String.valueOf(sensor.getResolution()));
    vendor.setText(String.valueOf(sensor.getVendor()));
    version.setText(String.valueOf(sensor.getVersion()));

    sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}

From source file:org.opendatakit.sensors.manager.ODKSensorManager.java

public void initializeRegisteredSensors() {

    // discover built in sensors
    android.hardware.SensorManager builtInSensorManager = (android.hardware.SensorManager) svcContext
            .getSystemService(Context.SENSOR_SERVICE);
    if (builtInSensorManager != null) {
        List<android.hardware.Sensor> deviceSensors = builtInSensorManager
                .getSensorList(android.hardware.Sensor.TYPE_ALL);
        for (android.hardware.Sensor hwSensor : deviceSensors) {
            BuiltInSensorType sensorType = BuiltInSensorType.convertToBuiltInSensor(hwSensor.getType());
            if (sensorType != null) {
                try {
                    String id = sensorType.name();
                    //Log.d(TAG,"Found sensor "+ id);
                    ODKSensor sensor = new ODKBuiltInSensor(sensorType, builtInSensorManager, id);
                    sensors.put(id, sensor);
                } catch (Exception e) {
                    e.printStackTrace();
                }/*  w w  w  .j ava 2  s .  c o  m*/
            }
        }
    }

    // load sensors from the database      
    for (ChannelManager channelManager : channelManagers.values()) {
        CommunicationChannelType type = channelManager.getCommChannelType();
        Log.d(TAG, "Load from DB:" + type.name());

        List<SensorData> savedSensorList = databaseManager.sensorList(type);

        for (SensorData sensorData : savedSensorList) {
            Log.d(TAG, "Sensor in DB:" + sensorData.id + " Type:" + sensorData.type);
            DriverType driverType = getDriverType(sensorData.type);

            if (driverType != null) {
                Log.d(TAG, "initing sensor from DB: id: " + sensorData.id + " driverType: " + sensorData.type
                        + " state " + sensorData.state);

                if (connectToDriver(sensorData.id, driverType)) {
                    Log.d(TAG, sensorData.id + " connected to driver " + sensorData.type);

                    if (sensorData.state == DetailedSensorState.CONNECTED) {
                        try {
                            channelManager.sensorConnect(sensorData.id);
                            //                        updateSensorState(sensorData.id, DetailedSensorState.CONNECTED);
                            Log.d(TAG, "connected to sensor " + sensorData.id + " over "
                                    + channelManager.getCommChannelType());
                        } catch (SensorNotFoundException snfe) {
                            updateSensorState(sensorData.id, DetailedSensorState.DISCONNECTED);
                            Log.d(TAG, "SensorNotFoundException. unable to connect to sensor " + sensorData.id
                                    + " over " + channelManager.getCommChannelType());
                        }
                    }
                }
            } else {
                Log.e(TAG, "driver NOT FOUND for type : " + sensorData.type);
            }
        }
    }
}