P
P
pthon2020-04-25 09:49:42
Android
pthon, 2020-04-25 09:49:42

Why is there no data from the gyroscope?

There is a gyroscope on the phone, it works in other applications

package com.pthon.gyrotest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class Gyro extends AppCompatActivity implements SensorEventListener  {

    /** Объект типа сенсор менеджер */
    public SensorManager mSensorManager;
    public Sensor mOrientation;

    private float xy_angle;
    private float xz_angle;
    private float zy_angle;

    private TextView xyView;
    private TextView xzView;
    private TextView zyView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gyro);

        Bundle arguments = getIntent().getExtras();
        TextView sip = findViewById(R.id.ipport);
        sip.setText(arguments.get("ip").toString());

        // присвоили менеджеру работу с серсором
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

        xyView = (TextView) findViewById(R.id.xyValue);  //
        xzView = (TextView) findViewById(R.id.xzValue);  // Наши текстовые поля для вывода показаний
        zyView = (TextView) findViewById(R.id.zyValue);  //
    }

    @Override
    public void onSensorChanged(SensorEvent event) { //Изменение показаний датчиков
        xy_angle = event.values[0]; //Плоскость XY
        xz_angle = event.values[1]; //Плоскость XZ
        zy_angle = event.values[2]; //Плоскость ZY
        Log.e("GYRO", "Is changed");
        xyView.setText(String.valueOf(xy_angle));
        xzView.setText(String.valueOf(xz_angle));
        zyView.setText(String.valueOf(zy_angle));
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) { //Изменение точности показаний датчика
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question