Skip to content

Commit f67c26e

Browse files
committed
read settings when started, not when created
1 parent d226cb9 commit f67c26e

File tree

9 files changed

+47
-49
lines changed

9 files changed

+47
-49
lines changed

TelemetryCore/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
defaultConfig {
99
minSdkVersion rootProject.minSdkVersion
1010
targetSdkVersion rootProject.targetSdkVersion
11-
versionCode 1
12-
versionName "1.0"
11+
versionCode 2
12+
versionName "2.0"
1313
externalNativeBuild {
1414
cmake {
1515
cppFlags "-std=c++17"
Binary file not shown.
Binary file not shown.
20 Bytes
Binary file not shown.
Binary file not shown.

TelemetryCore/src/main/cpp/Telemetry/TelemetryReceiver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void TelemetryReceiver::startReceiving(JNIEnv *env,jobject context,AAssetManager
4646
assert(mTelemetryDataReceiver.get()==nullptr);
4747
assert(mEZWBDataReceiver.get()== nullptr);
4848
assert(mTestFileReader.get()== nullptr);
49-
49+
5050
//read all the settings usw begin --------------------------
5151
SettingsN settingsN(env,context,"pref_telemetry");
5252
T_Protocol=(static_cast<PROTOCOL_OPTIONS >(settingsN.getInt(IDT::T_PROTOCOL,1)));
@@ -565,7 +565,7 @@ const std::string TelemetryReceiver::getStatisticsAsString()const {
565565
}else{
566566
ostream<<"Source type==File. ("+getProtocolAsString()+") Select UDP as data source\n";
567567
ostream<<"nTelemetryBytes"<<nTelemetryBytes<<"\n";
568-
ostream<<"nParsedBytes"<<mTestFileReader->getNReceivedbytes()<<"\n";
568+
ostream<<"nParsedBytes"<<(mTestFileReader ? mTestFileReader->getNReceivedbytes() : -1)<<"\n";
569569
ostream<<"Packets:"<<uav_td.validmsgsrx<<"\n";
570570
}
571571
return ostream.str();
@@ -682,7 +682,7 @@ const std::string TelemetryReceiver::getProtocolAsString() const {
682682
case TelemetryReceiver::XLTM:ss<<"ltm";break;
683683
case TelemetryReceiver::FRSKY:ss<<"frsky";break;
684684
case TelemetryReceiver::MAVLINK:ss<<"mavlink";break;
685-
default:assert(false);break;
685+
default:assert(true);break;
686686
}
687687
return ss.str();
688688
}

TelemetryCore/src/main/java/constantin/telemetry/core/TelemetryReceiver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public class TelemetryReceiver implements HomeLocation.IHomeLocationChanged, Lif
3939
public static final int SOURCE_TYPE_FILE=1;
4040
public static final int SOURCE_TYPE_ASSETS=2;
4141

42-
4342
static {
4443
System.loadLibrary("TelemetryReceiver");
4544
}
@@ -64,15 +63,14 @@ private static native void setDecodingInfo(long instance,float currentFPS, float
6463
private final Context context;
6564
private final HomeLocation mHomeLocation;
6665

67-
//settings are initialized when creating the native instance !
6866

6967
//Only use with AppCombatActivity for lifecycle listener
7068
//receives data in between onPause()<-->onResume()
7169
public <T extends Activity & LifecycleOwner> TelemetryReceiver(final T parent){
72-
parent.getLifecycle().addObserver(this);
7370
context=parent;
7471
nativeInstance=createInstance(parent,getDirectoryToSaveDataTo());
7572
mHomeLocation=new HomeLocation(parent,this);
73+
parent.getLifecycle().addObserver(this);
7674
}
7775

7876
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)

TelemetryCore/src/main/java/constantin/telemetry/core/TestReceiverTelemetry.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class TestReceiverTelemetry implements Runnable, LifecycleObserver {
2929
private Thread mThread;
3030

3131
public <T extends Activity & LifecycleOwner> TestReceiverTelemetry(final T t){
32-
t.getLifecycle().addObserver(this);
3332
this.activity=t;
3433
telemetryReceiver =new TelemetryReceiver(t);
34+
t.getLifecycle().addObserver(this);
3535
}
3636

3737
public void setViews(TextView receivedTelemetryDataTV, TextView ezwbForwardDataTV, TextView telemetryValuesAsString){
@@ -53,6 +53,44 @@ private void stopUiUpdates(){
5353
try {mThread.join();} catch (InterruptedException e) {e.printStackTrace();}
5454
}
5555

56+
@Override
57+
public void run() {
58+
long lastCheckMS = System.currentTimeMillis() - 2*1000;
59+
while (!Thread.currentThread().isInterrupted()){
60+
//if any of the TV are not null, we update its content
61+
//with the corresponding string, and optionally change color
62+
if(receivedTelemetryDataTV !=null){
63+
final String s= telemetryReceiver.getStatisticsAsString();
64+
final int newColor=telemetryReceiver.anyTelemetryDataReceived() ? Color.GREEN : Color.RED;
65+
updateViewIfStringChanged(receivedTelemetryDataTV,s,true,newColor);
66+
}
67+
if(ezwbForwardDataTV!=null){
68+
final String s= telemetryReceiver.getEZWBDataAsString();
69+
updateViewIfStringChanged(ezwbForwardDataTV,s,false,0);
70+
}
71+
if(dataAsStringTV!=null){
72+
final String s = telemetryReceiver.getTelemetryDataAsString();
73+
updateViewIfStringChanged(dataAsStringTV,s,false,0);
74+
}
75+
if(telemetryReceiver.isEZWBIpAvailable()){
76+
onEZWBIpDetected(telemetryReceiver.getEZWBIPAdress());
77+
}
78+
//Every 3.5s we check if we are receiving video data, but cannot parse the data. Probably the user did mix up
79+
//ezwb-versions
80+
if(System.currentTimeMillis()- lastCheckMS >=3500){
81+
final boolean errorEZ_WB= telemetryReceiver.receivingEZWBButCannotParse();
82+
lastCheckMS =System.currentTimeMillis();
83+
if(errorEZ_WB){
84+
makeToastOnUI("You are receiving ez-wifibroadcast telemetry data, but FPV-VR cannot parse it. Probably you are using" +
85+
" app version 1.5 or higher with ez-wb. 1.6 or lower. Please upgrade to ez-wb 2.0. This also allows you to read all useful" +
86+
" telemetry data from your EZ-WB rx pi on android.",Toast.LENGTH_SHORT);
87+
}
88+
}
89+
//Refresh every 200ms
90+
try {Thread.sleep(200);} catch (InterruptedException e) {return;}
91+
}
92+
}
93+
5694
@SuppressLint("ApplySharedPref")
5795
private void onEZWBIpDetected(String ip){
5896
//System.out.println("Called from native:"+ip);
@@ -92,44 +130,6 @@ public void run() {
92130
});
93131
}
94132

95-
@Override
96-
public void run() {
97-
long lastCheckMS = System.currentTimeMillis() - 2*1000;
98-
while (!Thread.currentThread().isInterrupted()){
99-
//if any of the TV are not null, we update its content
100-
//with the corresponding string, and optionally change color
101-
if(receivedTelemetryDataTV !=null){
102-
final String s= telemetryReceiver.getStatisticsAsString();
103-
final int newColor=telemetryReceiver.anyTelemetryDataReceived() ? Color.GREEN : Color.RED;
104-
updateViewIfStringChanged(receivedTelemetryDataTV,s,true,newColor);
105-
}
106-
if(ezwbForwardDataTV!=null){
107-
final String s= telemetryReceiver.getEZWBDataAsString();
108-
updateViewIfStringChanged(ezwbForwardDataTV,s,false,0);
109-
}
110-
if(dataAsStringTV!=null){
111-
final String s = telemetryReceiver.getTelemetryDataAsString();
112-
updateViewIfStringChanged(dataAsStringTV,s,false,0);
113-
}
114-
if(telemetryReceiver.isEZWBIpAvailable()){
115-
onEZWBIpDetected(telemetryReceiver.getEZWBIPAdress());
116-
}
117-
//Every 3.5s we check if we are receiving video data, but cannot parse the data. Probably the user did mix up
118-
//ezwb-versions
119-
if(System.currentTimeMillis()- lastCheckMS >=3500){
120-
final boolean errorEZ_WB= telemetryReceiver.receivingEZWBButCannotParse();
121-
lastCheckMS =System.currentTimeMillis();
122-
if(errorEZ_WB){
123-
makeToastOnUI("You are receiving ez-wifibroadcast telemetry data, but FPV-VR cannot parse it. Probably you are using" +
124-
" app version 1.5 or higher with ez-wb. 1.6 or lower. Please upgrade to ez-wb 2.0. This also allows you to read all useful" +
125-
" telemetry data from your EZ-WB rx pi on android.",Toast.LENGTH_SHORT);
126-
}
127-
}
128-
//Refresh every 200ms
129-
try {Thread.sleep(200);} catch (InterruptedException e) {return;}
130-
}
131-
}
132-
133133
public interface EZWBIpAddressDetected{
134134
void onEZWBIpDetected(String ip);
135135
}

TelemetryExample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId "constantin.telemetry.example"
1010
minSdkVersion rootProject.minSdkVersion
1111
targetSdkVersion rootProject.targetSdkVersion
12-
versionCode 1
13-
versionName "1.0"
12+
versionCode 2
13+
versionName "2.0"
1414

1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616

0 commit comments

Comments
 (0)