Feature-type objects do not receive any data from SensorTile

Abierto
#6 16 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
android, java
Área
mobile

Línea de trabajo

Start with MainActivity, especially onCreate and the FeatureActivity, FeatureMicLevel, FeatureAudioADPCM, and FeatureAudioADPCMSync listener entry points. Compare how the node and features are obtained after ScanActivity and how NodeContainerFragment is initialized. Done means feature-type objects receive and expose SensorTile data in the described activity, with the relevant behavior verified.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Hello Giovanni,

I'm creating an app to monitor a dog's activities through motion, microphone level, and audio features.
I have created a unique activity and a single layout where I manage the above features plus the battery.

The battery code is commented because I do not need it right now.

This is the code of the only activity that follows the activity of the node search (ScanActivity):
`public class MainActivity extends AppCompatActivity {

/**
 * create an intent for start the activity that will log the information from the node
 *
 * @param c    context used for create the intent
 * @param node note that will be used by the activity
 * @return intent for start this activity
 */
public static Intent getStartIntent(Context c, @NonNull Node node) {
    Intent i = new Intent(c, MainActivity.class);
    i.putExtra(NODE_TAG, node.getTag());
    i.putExtras(NodeContainerFragment.prepareArguments(node));
    return i;
}

private final static String NODE_FRAGMENT = MainActivity.class.getCanonicalName() + "" +
        ".NODE_FRAGMENT";
private final static String NODE_TAG = MainActivity.class.getCanonicalName() + "" +
        ".NODE_TAG";

/** fragment used for keep the connection open */
private NodeContainerFragment mNodeContainer;

/**
 * nodo che mostrerà i dati
 */
private Node mNode;



// Feature on which to apply the listener
private FeatureActivity mfeatureAct;

private FeatureMicLevel mMicLevel;

//private FeatureBattery mBattery;

private FeatureAudioADPCM mAudio;

// feature where we read the audio sync values
private FeatureAudioADPCMSync mAudioSync;

//  Audio track builder
private AudioTrack mAudioTrack;

// The sampling rate
private static final int SAMPLE_RATE = 8000;

//object containing the sync data needed in a ADPCM stream decoding
private BVAudioSyncManager mBVAudioSyncManager = new BVAudioSyncManager();




// audio manager
private static final int AUDIO_STREAM = AudioManager.STREAM_MUSIC;

private boolean mIsRecording;

private AudioBuffer mRecordedAudio;


private static final int MAX_RECORDING_TIME_S = 30;



/**
 * listner FeatureActivity and FeatureMicLevel
 */
FeatureActivity.ActivityType event;
public final Feature.FeatureListener mfeatureRecognListner = new Feature.FeatureListener(){
    @Override
    public void onUpdate(Feature f, Feature.Sample sample) {
        if (f.getName().equals("Activity Recognition")) {
            event = FeatureActivity.getActivityStatus(sample);
        }
    }//onUpdate
};//FeatureActivityRecognitionListner
byte levelMic;
public Feature.FeatureListener mMicLevelListner = new Feature.FeatureListener(){
    @Override
    public void onUpdate(Feature f, Feature.Sample sample) {
        if (f.getName().equals("Mic Level")){
            levelMic = FeatureMicLevel.getMicLevel(sample,1); ///DUBBIO
        }
        MainActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {

                if ((event.equals(FeatureActivity.ActivityType.STATIONARY) || event.equals(FeatureActivity.ActivityType.WALKING)) &&
                        levelMic < 60) {
                    mStatusImage.setImageResource(R.drawable.cane_zen);
                    mStatusText.setText("Calm");
                    mStatusText.setBackgroundColor(Color.GREEN);
                }
                // quando abbaia più di 6 volte in 10 sec, il cane è nervoso
                int count = 0;
                if (levelMic > 100) {
                    count++;
                    for (int i = 0; i == 10; i++) {
                        if (levelMic > 100) {
                            count++;
                            if (count > 6) {
                                mStatusImage.setImageResource(R.drawable.cane_nervoso);
                                mStatusText.setText("Nervous");
                                mStatusText.setBackgroundColor(Color.RED);
                            }
                        }
                    }
                }
                else if (levelMic >= 60 && levelMic <= 100) {
                    mStatusImage.setImageResource(R.drawable.cane_giocoso);
                    mStatusText.setText("Playful");
                    mStatusText.setBackgroundColor(Color.YELLOW);
                }
            }
        });
    }//onUpdate
};//FeatureMicLevelListner

 //    /**
//     * listner FeatureBattery
//     */
//    float levelBat;
//    public final Feature.FeatureListener mBatteryListner = new Feature.FeatureListener() {
//        @Override
//        public void onUpdate(Feature f, Feature.Sample sample){
//            if (f.getName().equals("Battery")) {
//                levelBat = FeatureBattery.getBatteryLevel(sample);
//
//                MainActivity.this.runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//
//                        if(levelBat == 0.0){
//                            mBatteryImage.setImageResource(R.drawable.battery_00);
//                            mBatteryText.setText("Low battery");
//                        }
//                        if(levelBat == 20.0){
//                            mBatteryImage.setImageResource(R.drawable.battery_20);
//                            mBatteryText.setText("Battery about to die");
//                        }
//                        if(levelBat == 40.0){
//                            mBatteryImage.setImageResource(R.drawable.battery_40);
//                            mBatteryText.setText("40%");
//                        }
//                        if(levelBat == 60.0){
//                            mBatteryImage.setImageResource(R.drawable.battery_60);
//                            mBatteryText.setText("60%");
//                        }
//                        if(levelBat == 80.0){
//                            mBatteryImage.setImageResource(R.drawable.battery_80);
//                            mBatteryText.setText("80%");
//                        }
//                        if(levelBat == 100.0){
//                            mBatteryImage.setImageResource(R.drawable.battery_100);
//                            mBatteryText.setText("Battery charged");
//                        }
//
//                    }
//                });
//
//            }
//        }
//
//    };


/**
 * listener for the audio feature, it will updates the audio values
 */
public final Feature.FeatureListener mAudioListener = new Feature.FeatureListener() {

    @Override
    public void onUpdate(final Feature f, final Feature.Sample sample) {
        short[] audioSample = FeatureAudioADPCM.getAudio(sample);

        /* Write audio data for playback
         *    @param short : The array that contains the data for playback
         *    @param int: offset in rawAudio where playback data begins
         *    @param int: The number of shorts to read in rawAudio after the offset
         */
        mAudioTrack.write(audioSample,0,audioSample.length);

    }

};

/**
 * listener for the audioSync feature, it will update the synchronism values
 */
public final Feature.FeatureListener mAudioSyncListener = new Feature.FeatureListener() {
    @Override
    public void onUpdate(Feature f, final Feature.Sample sample) {
        if(mBVAudioSyncManager!=null){
            mBVAudioSyncManager.setSyncParams(sample);
        }
    }
};







////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ImageView mStatusImage;
TextView mStatusText;
ImageView mBatteryImage;
TextView mBatteryText;
Button mPlayButton;
Button mStopButton;
SeekBar mVolumeBar;
FloatingActionButton mRecordButton;
ProgressBar mRecordBar;
AudioManager mAudioManager;
private TextView mRequestStatus;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // find the node.
    String nodeTag = getIntent().getStringExtra(NODE_TAG);
    mNode = Manager.getSharedInstance().getNodeWithTag(nodeTag);

    //create/recover the NodeContainerFragment (DebugConsoleActivity.java)
    if (savedInstanceState == null) {
        Intent i = getIntent();
        mNodeContainer = new NodeContainerFragment();
        mNodeContainer.setArguments(i.getExtras());

        getFragmentManager().beginTransaction()
                .add(mNodeContainer, NODE_FRAGMENT).commit();

    } else {
        mNodeContainer = (NodeContainerFragment) getFragmentManager()
                .findFragmentByTag(NODE_FRAGMENT);
    }//if-else

    mfeatureAct = mNode.getFeature(FeatureActivity.class);
    mMicLevel = mNode.getFeature(FeatureMicLevel.class);
    //mBattery = mNode.getFeature(FeatureBattery.class);
    mAudio = mNode.getFeature(FeatureAudioADPCM.class);
    mAudioSync = mNode.getFeature(FeatureAudioADPCMSync.class);



    //builder audio track
    mAudioTrack = new AudioTrack(
            AudioManager.STREAM_MUSIC,
            SAMPLE_RATE,
            AudioFormat.CHANNEL_OUT_MONO,
            AudioFormat.ENCODING_PCM_16BIT,
            FeatureAudioADPCM.AUDIO_PACKAGE_SIZE,
            AudioTrack.MODE_STREAM);


    mStatusImage = (ImageView)findViewById(R.id.statusImage);
    mStatusText = (TextView)findViewById(R.id.statusText);
    mBatteryImage = (ImageView)findViewById(R.id.batteryImage);
    mBatteryText = (TextView)findViewById(R.id.batteryText);
    mPlayButton = (Button) findViewById(R.id.playButton);
    mStopButton = (Button) findViewById(R.id.stopButton);
    mVolumeBar = (SeekBar)findViewById(R.id.volumeBar);
    mRecordBar = (ProgressBar) findViewById(R.id.recordTimeValue);
    mRecordBar.setIndeterminate(false);
    mRecordButton = (FloatingActionButton) findViewById(R.id.recordButton);
    mRequestStatus = (TextView) findViewById(R.id.requestStatus);


    //  When the play button is pressed
    mPlayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            mAudioTrack.play();
            mAudioManager.setStreamVolume(AUDIO_STREAM,mVolumeBar.getProgress(),0);

        }
    });

    //When the stop button is pressed
    mStopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            stopAudioTrack();
            mAudioManager.setStreamVolume(AUDIO_STREAM,0,0);

        }
    });



    //enable control volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    initControls();

}




private void stopAudioTrack(){
    synchronized(this) {
        mAudioTrack.pause();
        mAudioTrack.flush();
    }
}

//   Volume control from SeekBar
private void initControls()
{
    try
    {
        mVolumeBar = (SeekBar)findViewById(R.id.volumeBar);
        mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        mVolumeBar.setMax(mAudioManager
                .getStreamMaxVolume(AudioManager.STREAM_MUSIC));
        mVolumeBar.setProgress(mAudioManager
                .getStreamVolume(AudioManager.STREAM_MUSIC));


        mVolumeBar.setOnSeekBarChangeListener(new  SeekBar.OnSeekBarChangeListener()
        {
            @Override
            public void onStopTrackingTouch(SeekBar arg0)
            {
            }

            @Override
            public void onStartTrackingTouch(SeekBar arg0)
            {
            }

            @Override
            public void onProgressChanged(SeekBar arg0, int progress, boolean arg2)
            {
                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                        progress, 0);
            }
        });
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

@Override
public void onResume() {
    super.onResume();
    
    // Feature Activity Listner
    mfeatureAct.addFeatureListener(mfeatureRecognListner);
    mNode.enableNotification(mfeatureAct);
    mNode.readFeature(mfeatureAct);
    // Feature MicLevel Listner
    mMicLevel.addFeatureListener(mMicLevelListner);
    mNode.enableNotification(mMicLevel);
    mNode.readFeature(mMicLevel);
    // Feature Battery Listner
//        mBattery.addFeatureListener(mBatteryListner);
//        mNode.enableNotification(mBattery);
//        mNode.readFeature(mBattery);
    // Features Audio Listner
    if(mAudio!=null && mAudioSync!=null) {
        mAudio.addFeatureListener(mAudioListener);
        mBVAudioSyncManager.reinitResetFlag();
        mAudio.setAudioSyncManager(mBVAudioSyncManager);
        mNode.enableNotification(mAudio);
        mAudioSync.addFeatureListener(mAudioSyncListener);
        mNode.enableNotification(mAudioSync);
    }
}

@Override
public void onPause() {
    super.onPause();
    // Feature Activity Listner
    mfeatureAct.removeFeatureListener(mfeatureRecognListner);
    mNode.disableNotification(mfeatureAct);
    // Feature MicLevel Listner
    mMicLevel.removeFeatureListener(mMicLevelListner);
    mNode.disableNotification(mMicLevel);
    // Feature Battery Listner
//        mBattery.removeFeatureListener(mBatteryListner);
//        mNode.disableNotification(mBattery);
    // Features Audio Listner
    if(mAudio!=null) {
        mAudio.removeFeatureListener(mAudioListener);
        mNode.disableNotification(mAudio);
    }
    if(mAudioSync!=null) {
        mAudioSync.removeFeatureListener(mAudioSyncListener);
        mNode.disableNotification(mAudioSync);
    }
   
}`
Lenguaje dominante
Kotlin
Estrellas
99
Forks
49
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de STMicroelectronics/BlueSTSDK_Android

Todos los issues de STMicroelectronics/BlueSTSDK_Android

Issues similares

Más issues de Kotlin

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.