Feature-type objects do not receive any data from SensorTile
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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);
}
}`
- Dominant language
- Kotlin
- Stars
- 99
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from STMicroelectronics/BlueSTSDK_Android
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 15/100
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
STMicroelectronics/BlueSTSDK_Android#29 · 2 comments ·
-
README Links Dead Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
All issues in STMicroelectronics/BlueSTSDK_Android
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
Issue: Bug
Difficulty 1/5 Under an hour Newbie friendliness 91/100
OpenAPITools/openapi-generator#24978 ·
-
helsemelding-json-schema json-schema-core
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
contributor: external needs review
Difficulty 2/5 1-3 hours Newbie friendliness 82/100