onSimulatorDataUpdated() not getting called - android

private void initFlightController() {
DJIAircraft aircraft = DJISimulatorApplication.getAircraftInstance();
if (aircraft == null || !aircraft.isConnected()) {
log("initFlightController: aircraft not connected");
showToast("Disconnected");
mFlightController = null;
return;
} else {
log("initFlightController: aircraft CONNECTED");
mFlightController = aircraft.getFlightController();
DJISimulator djiSimulator = mFlightController.getSimulator();
log("initFlightController: djiSimulator has started : "+djiSimulator.hasSimulatorStarted());
djiSimulator.setUpdatedSimulatorStateDataCallback(new DJISimulator.UpdatedSimulatorStateDataCallback() {
#Override
public void onSimulatorDataUpdated(final DJISimulatorStateData djiSimulatorStateData) {
log("onSimulatorDataUpdated: ");
new Handler(Looper.getMainLooper()).post(new Runnable() {
#Override
public void run() {
String yaw = String.format("%.2f", djiSimulatorStateData.getYaw());
String pitch = String.format("%.2f", djiSimulatorStateData.getPitch());
String roll = String.format("%.2f", djiSimulatorStateData.getRoll());
String positionX = String.format("%.2f", djiSimulatorStateData.getPositionX());
String positionY = String.format("%.2f", djiSimulatorStateData.getPositionY());
String positionZ = String.format("%.2f", djiSimulatorStateData.getPositionZ());
mTextView.setText("Yaw : " + yaw + ", Pitch : " + pitch + ", Roll : " + roll + "\n" + ", PosX : " + positionX +
", PosY : " + positionY +
", PosZ : " + positionZ);
}
});
}
});
}
}
I am testing the sample code given for android in Dji-Developer. Every thing goes fine but the onSimulatorDataUpdated() doesnt get called.
it even prints the log
"initFlightController: djiSimulator has started : true"

I found the solution for the problem. The code doesn't have any problem, the RC has a button at the left front area which has to be set to P mode.

Related

Android Studio PieChart convert String/float to Integer - Toast

I want to make PieChart and when you will press on the your chosen field on PieChart, then you will see Value of Chart (integer 15.. ect.)
I have problem with Toast.maketext when show value of "counter" show value 15.0 insted only 15. I want to have number without .0 at the end.
When I was trying this option below (convert)the app was stopped working:
int x = Integer.parseInt(counter);
int x = Integer.valueOf(counter)
try{ x = Integer.parseInt(counter)}
catch(NumberFormat Exception nfe){}
My code:
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
#Override
public void onValueSelected(Entry e, Highlight h) {
Log.d(TAG, "onValueSelected: Value select from chart.");
Log.d(TAG, "onValueSelected: " + e.toString());
Log.d(TAG, "onValueSelected: " + h.toString());
int pos1 = e.toString().indexOf("y: ");
String counter = e.toString().substring(pos1 + 3);
for(int i = 0; i < yData.length; i++){
if(yData[i] == Float.parseFloat(counter)){
pos1 = i;
break;
}
}
String days = xData[pos1];
/*
1.) int x = Integer.parseInt(counter);
2.) int x = Integer.valueOf(counter)
3.)try{ x = Integer.parseInt(counter)}
catch(NumberFormat Exception nfe){}
*/
Toast.makeText(Main2Activity.this, days+ " Day" + "counter" + x, Toast.LENGTH_LONG).show();
//Toast.makeText(Main2Activity.this, days+ " Day" + "counter" + counter, Toast.LENGTH_LONG).show();
//add counter to Toast if you want to show counter
}
#Override
public void onNothingSelected() {
}
});
Thank you for answers :)
Can you try
System.out.print(String.format("%1.0f", counter));
Toast.makeText(Main2Activity.this, days+ " Day" + "counter" + String.format("%1.0f", counter), Toast.LENGTH_LONG).show();
For now I was solving like that:
Log.d(TAG, "onValueSelected: counter num " +counter);
for(int i = 0; i < yData.length; i++){
if(yData[i] == Float.parseFloat(counter)){
pos1 = i;
break;
}
}
String days = xData[pos1];
switch (pos1) {
case 0:
Toast.makeText(Main2Activity.this, days + " Day " + "\n" + "Numbers " +numberBad, Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(Main2Activity.this, days + " Day " + "\n" + "Numbers " +numberGod, Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(Main2Activity.this, days + " Day " + "\n" + "Numbers " +numberNor, Toast.LENGTH_SHORT).show();
break;
default:
break;
}

How to get the results from multiple servers in a function in Android

I'm installing Hybrid Ranking algorithm for Linked Data Extraction & Context on Android. Documents you can search Google for the keywords above.
And now I'm installing semantic similarity between two uri1 and uri2.
Input: two DBpedia URIs
Output: a value representing their similarity
private float similarity(String uri1, String uri2) {
float wikipedia = wikiS(uri1, uri2);
float abtract = abtractS(uri1, uri2);
float google = engineS(uri1, uri2, google);
float yahoo = engineS(uri1, uri2, yahoo);
float bing = engineS(uri1, uri2, bing);
float dilicious = engineS(uri1, uri2, dilicicous);
return wikipedia + abtract + google + yahoo + bing + dilicious;
}
And with each child function, I have to query data using SPARQL dbpedia, google, yahoo, bing, dilicious using provided API. The results obtained will be calculated to the parser and returns the corresponding float value.
Example for abtractS(uri1, uri2) below:
private float abstractS(String uri1, String uri2, final float wikiS){
String url = createUrlAbstractS(uri1, uri2);
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
float abtractS = 0.0f;
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray data = jsonObject.getJSONObject("results").getJSONArray("bindings");
if(data.length() == 0){
showLogAndToast("No result");
}else{
JSONObject element = data.getJSONObject(0);
String label1 = element.getJSONObject("label1").getString("value");
String abtract1 = element.getJSONObject("abtract1").getString("value");
String label2 = element.getJSONObject("label2").getString("value");
String abtract2 = element.getJSONObject("abtract2").getString("value");
abtractS = calWordContained(label1, abtract2) + calWordContained(label2, abtract1) + wikiS;
//TODO: RESULT ABTRACTS HERE. How next?
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(request);
return 0.0f;//HERE: no results
}
private float calWordContained(String label, String abtract){
if(label.length() == 0 || abtract.length() == 0){
return 0.0f;
}
List<String> words = Arrays.asList(label.split(" "));
int count = 0;
float length = words.size();
for(int i = 0; i < length; i++){
if(abtract.toLowerCase().contains(words.get(i).toLowerCase())){
count++;
}
}
return (count/length);
}
public String createUrlAbstractS(String uri1, String uri2){
private String BASE_URL_DBPEDIA = "http://dbpedia.org/sparql?default-graph-uri=&query=";
String query = createQueryAbstractS(uri1, uri2);
String url = "";
try {
url = Config.BASE_URL_DBPEDIA + URLEncoder.encode(query, "UTF-8") + Config.RESULT_JSON_TYPE;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return url;
}
private String createQueryAbstractS(String uri1, String uri2){
String query = Config.PREFIX_DBPEDIA + " \n" +
"prefix dbpedia-owl: <http://dbpedia.org/ontology/>\n" +
"\n" +
"\n" +
"select ?label1, ?label2, ?abtract1, ?abtract2 where\n" +
"{\n" +
" {\n" +
" select *\n" +
" where{\n" +
" <" + uri1 + "> rdfs:label ?label1 ;\n" +
" dbpedia-owl:abstract ?abtract1 .\n" +
" FILTER langMatches(lang(?abtract1),'en') . \n" +
" FILTER langMatches(lang(?label1),'en') .\n" +
" }\n" +
" }\n" +
"\n" +
"\n" +
" {\n" +
" select *\n" +
" where{\n" +
" <" + uri2 + "> rdfs:label ?label2 ;\n" +
" dbpedia-owl:abstract ?abtract2 .\n" +
" FILTER langMatches(lang(?label2),'en') . \n" +
" FILTER langMatches(lang(?abtract2),'en') .\n" +
" }\n" +
" }\n" +
"}";
return query;
}
but how to do this on, I could not get the results I wanted in the similarity function (uri1, uri2). Therefore it will affect the results in different functions.
So I'm asking is: how can I get all the results of the function Wikis, abtractS, engine (google), engine (bing), engine (yahoo), engine (dilicious) in a simple way Best. I currently do on Android and data load times is very important.
Thank you very much!

SPP Android BT Connection quits after seconds (EEG readings)

I have created an app that receives data from a bt transmitter (Bluegiga). The readings are from EEG signals. The data rate is 1Khz (I have to admit it's high). Anyway, I acquire some data for some seconds and then the Bluetooth acts like there is no incoming data (which is not true). If I try to disconnect the Bluetooth using the app is clear that there is no more communication with the bt module at the EEG board since it doesn't respond to the desconnection (It has a led that indicates when is connected, and it doesn't turn of/on or anything).
If I decrease the data rate to (let's say 500hz) the app works ok, with some occasional 'quits', but tolerable. If I decrease it more the app works with no problems.
Of curse, by design, my app must work at 1Khz data rate so here is where the problem comes.
I have check some other post, trying to hit some kind of sns but nothing match my problem exactly (anyway I have tried to use the information on them but with no success obviously).
Sometimes I get this message, "dm_pm_timer expires", sometimes no (after the bt stops working).
Sadly there is no indication, Exception or message that can tell me what's going on.
Here is my Code for the BT reception Thread
class BluetoothReadThread extends Thread {
private final InputStream iStream;
private final OutputStream mmOutputStream;
private boolean continueReading = true;
public BluetoothReadThread() {
InputStream tmp = null;
OutputStream tmp2 = null;
try {
tmp = btSocket.getInputStream();
tmp2 = btSocket.getOutputStream();
} catch (IOException e) {
}
iStream = tmp;
mmOutputStream = tmp2;
}
#Override
public void run() {
int c;
int waitCount = 0;
while (continueReading) {
try {
if (iStream.available() > 0) {
waitCount = 0;
c = iStream.read();
readBuffer[readBufferPosition++] = c;
if (readBufferPosition == bitsExpected) {
if (bitsExpected == 22) {
ch1 = MultiplicationCombine(readBuffer[4], readBuffer[3]);
ch2 = MultiplicationCombine(readBuffer[6], readBuffer[5]);
ch3 = MultiplicationCombine(readBuffer[8], readBuffer[7]);
ch4 = MultiplicationCombine(readBuffer[10], readBuffer[9]);
ch5 = MultiplicationCombine(readBuffer[12], readBuffer[11]);
ch6 = MultiplicationCombine(readBuffer[14], readBuffer[13]);
ch7 = MultiplicationCombine(readBuffer[16], readBuffer[15]);
ch8 = MultiplicationCombine(readBuffer[18], readBuffer[17]);
} else {
ch1 = (int) filter_3((double)MultiplicationCombine(readBuffer[5], readBuffer[4], readBuffer[3]));
ch2 = (int) filter_4((double)MultiplicationCombine(readBuffer[8], readBuffer[7], readBuffer[6]));
ch3 = (int) filter_2((double)MultiplicationCombine(readBuffer[11], readBuffer[10], readBuffer[9]));
ch4 = (int) filter_2((double)MultiplicationCombine(readBuffer[14], readBuffer[13], readBuffer[12]));
ch5 = (int) filter_2((double)MultiplicationCombine(readBuffer[17], readBuffer[16], readBuffer[15]));
ch6 = (int) filter_2((double)MultiplicationCombine(readBuffer[20], readBuffer[19], readBuffer[18]));
ch7 = (int) filter_2((double)MultiplicationCombine(readBuffer[23], readBuffer[22], readBuffer[21]));
ch8 = (int) filter_2((double)MultiplicationCombine(readBuffer[26], readBuffer[25], readBuffer[24]));
}
Header_int = readBuffer[0];
PK_ID_int = readBuffer[1];
PK_Counter_int = readBuffer[2];
if (downsample++ == downsample_value) {
addEntry(ch1 / scaCh1, ch2 / scaCh2, ch3 / scaCh3, ch4 / scaCh4, ch5 / scaCh5, ch6 / scaCh6, ch7 / scaCh7, ch8 / scaCh8);
downsample = 0;
}
//ProgrNum,PacketType,Ch1,Ch2,Ch3,Ch4,Ch5,Ch6,Ch7,Ch8,MRK
if (write_open) {
osw.write(PK_Counter_int + "," + PK_ID_int + "," + ch1 + "," + ch2 + "," + ch3 + "," + ch4 + "," + ch5 + "," + ch6 + "," + ch7 + "," + ch8 + "," + bolOpenClose + "\n");
//osw.write(PK_Counter_int + "," + PK_ID_int + "," + ch1 + "," + ch2 + "," + ch3 + "," + ch4 + "," + ch5 + "," + ch6 + "," + ch7 + "," + ch8 + "," + "\n");
}
System.out.println(PK_Counter_int + "," + PK_ID_int + "," + ch1 + "," + ch2 + "," + ch3 + "," + ch4 + "," + ch5 + "," + ch6 + "," + ch7 + "," + ch8 + ", AV=" + iStream.available() );
mmOutputStream.write(valueSTR.getBytes());
// if(downsample++==14) { safe_copy(readBuffer); plot=true; downsample=0;}
readBufferPosition = 0;
try {
Thread.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} catch (IOException e) {
System.out.println(e + "\nError sending data + :" + e);
// Bluetooth error! Stop reading.
//this.stopAndSendIntent();
}
}
}
/*
public void stopAndSendIntent() {
this.cancel();
Intent intent = new Intent();
intent.setAction(BLUETOOTH_ACTION_DONE_READING);
sendBroadcast(intent);
}
*/
public void cancel() {
System.out.println("-----Cancelling readThread!!");
try {
iStream.close();
} catch (IOException e) {
} catch (NullPointerException e) {
}
;
continueReading = false;
}
}
It works like this:
I read a received character (c=iStream.read()).
Then I copy this character to an int array until I reach the length of the packet (it can be 22 or 28 (bitsExpected)).
The following part is just filtering and plotting of the signal.
I have tried many other implementations but I get the same result.
Even if I eliminate the part of the filtering and plotting (just reading data) the problem persists.
If instead of working with array, I work with string, i.e, using append() (which should be the same?) I manage to get an working connection (no quits) but, as soon as I manipulate the program using the array everything is the same.
I'm stuck with this for 1 month already, so I will really appreciate any comments, past experience or suggestions.
Thanks in advance.
I just added this piece of code
if (PK_Counter_int % 100 == 0) mmOutputStream.write(startTring.getBytes());
and it works just fine so far.

Empty EditText return string into name, id

I am trying to get the string of the EditText and if it is " I want to get " also but the string is appearing this in the EditText
android.support.v7.widget.AppCompatEditText{42e33310 VFED..CL .F ....ID40,40-1160,315 #7f0c006f app:id\CalculatorDisplay}
after getting it and giving it to the EditText again
and here is a part of the onClick that works when I press a button and the rest of it is not dealing with this problem the problem is in NoRepeatNumber as I tested that when I get it in TestTV TextView I saw the code above
public void onClick(View view) {
TestTV.setText("enterd ");
String buttonPressed = ((Button) view).getText().toString();
PublicButtonPressed = buttonPressed;
if (DIGITS.contains(buttonPressed)) {
SinOrNumber=2;
TestTV.append("numbering");
// digit was pressed
if (!Started) {
mCalculatorDisplay.setText("");
TestTV.append("\nenterd setText");
} else {
TestTV.append("\nenterd setText eslse");
}
if (Started) {
OperationEnded = true;
}
if (NumberingEnded) {
FullNumber = String.valueOf(Number[Ni]);
Ni++;
NumberingEnded = false;
FullCalculation= FullNumber + " ";
NoRepeatNumber="";
DisplayCalculations();
}
FullNumber = FullNumber + buttonPressed;
Number[Ni] = Integer.parseInt(FullNumber);
TestTV.append("\nNumber[" + Ni + "] =" + + Number[Ni] + "\n" + "buttonPressed =" + buttonPressed + "\nFullNumber =" + FullNumber);
//DisplayCalculations();
if ("".equals(mCalculatorDisplay)) {
TestTV.append("\nentered equal\"\"");
NoRepeatNumber="";
} else {
if (NoRepeatNumber == "") {
NoRepeatNumber = String.valueOf(mCalculatorDisplay);
TestTV.append("\nNoRepeatNumber =" + NoRepeatNumber);
}
}
if(!NumberingEnded){
mCalculatorDisplay.setText(NoRepeatNumber + FullNumber);
}
if (!Started) {
Started = true;
}
if (userIsInTheMiddleOfTypingANumber) {
if (buttonPressed.equals(".") && mCalculatorDisplay.getText().toString().contains(".")) {
// ERROR PREVENTION
// Eliminate entering multiple decimals
} else {
Number[Ni] = Integer.parseInt(FullNumber);
}
}
userIsInTheMiddleOfTypingANumber = true;
} else {}}
Call mCalculatorDisplay.getText().toString() instead of String.valueOf(mCalculatorDisplay).
I guess mCalculatorDisplay is an EditText?
Update: NoRepeatNumber = String.valueOf(mCalculatorDisplay); - this is the problem part

get maximum value of a object

I have a little problem. I get data from more then one Beacon and I put it into an arrayList. Now I want that the nearest one should be returned.
ArrayList<Beacon> arrayList = new ArrayList<Beacon>();
String beaconName;
public void addToBeaconInfo(Beacon beacon) {
boolean beaconAlreadyInList = false;
//arrayList.add(beacon);
beaconName = "" + beacon.getId2() + "" + beacon.getId3();
//Log.i("BeaconInfo","addBeacon_beaconName: "+beaconName + " distance" + beacon.getDistance());
int i;
for(i = 0; i < arrayList.size(); i++){
Beacon tempBeacon = arrayList.get(i);
if(tempBeacon.getId2().equals(beacon.getId2())){
beaconAlreadyInList = true;
arrayList.remove(beacon);
Log.i("BeaconInfo", "addBeacon_tempBeacon: " + beacon.getId3() + " distance: " + beacon.getDistance());
break;
}
}
if(beaconAlreadyInList == false){
arrayList.add(beacon);
Log.i("arrayList","" + beacon.getDistance() + " " + beacon.getBluetoothName());
double maxDistance = beacon.getDistance();
//double a = Collections.max(maxDistance);
//Log.i("maxDistance","" + Math.max());
}
}
Beacon nearest = null;
double distance = Double.MAX_VALUE;
for (Beacon beacon: arrayList){
double maxDistance = beacon.getDistance();
if (maxDistance < distance) {
distance = maxDistance;
nearest = beacon;
}
}

Categories

Resources