Feature-type objects do not receive any data from SensorTile

オープン
#6 コメント 16 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
android, java
領域
mobile

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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);
    }
   
}`
主要言語
Kotlin
スター
99
フォーク
49
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

STMicroelectronics/BlueSTSDK_Android のほかの issue

STMicroelectronics/BlueSTSDK_Android の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。