Skip to content

Commit 691c842

Browse files
authored
Improve video link status OSD (#89)
* Improve link status osd * Improve RSSI calculation * Change RSSI font size (cherry picked from commit a6ff030)
1 parent c69cdd8 commit 691c842

File tree

6 files changed

+64
-23
lines changed

6 files changed

+64
-23
lines changed

app/src/main/java/com/openipc/pixelpilot/VideoActivity.java

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,9 @@ private void setupPieChart() {
511511
chart.getDescription().setEnabled(false);
512512
chart.setDrawHoleEnabled(true);
513513
chart.setHoleColor(Color.WHITE);
514-
chart.setTransparentCircleColor(Color.WHITE);
515-
chart.setTransparentCircleAlpha(110);
516-
chart.setHoleRadius(58f);
517-
chart.setTransparentCircleRadius(61f);
514+
chart.setHoleRadius(75f);
515+
chart.setCenterTextSize(12);
516+
chart.setCenterText("RSSI");
518517
chart.setHighlightPerTapEnabled(false);
519518
chart.setRotationEnabled(false);
520519
chart.setClickable(false);
@@ -809,11 +808,26 @@ private void showFecThresholdsDialog() {
809808
.setView(layout)
810809
.setPositiveButton("OK", (dialog, which) -> {
811810
SharedPreferences.Editor editor = prefs.edit();
812-
try { editor.putInt("fec_lost_to_5", Integer.parseInt(edits[0].getText().toString())); } catch (Exception ignored) {}
813-
try { editor.putInt("fec_recovered_to_4", Integer.parseInt(edits[1].getText().toString())); } catch (Exception ignored) {}
814-
try { editor.putInt("fec_recovered_to_3", Integer.parseInt(edits[2].getText().toString())); } catch (Exception ignored) {}
815-
try { editor.putInt("fec_recovered_to_2", Integer.parseInt(edits[3].getText().toString())); } catch (Exception ignored) {}
816-
try { editor.putInt("fec_recovered_to_1", Integer.parseInt(edits[4].getText().toString())); } catch (Exception ignored) {}
811+
try {
812+
editor.putInt("fec_lost_to_5", Integer.parseInt(edits[0].getText().toString()));
813+
} catch (Exception ignored) {
814+
}
815+
try {
816+
editor.putInt("fec_recovered_to_4", Integer.parseInt(edits[1].getText().toString()));
817+
} catch (Exception ignored) {
818+
}
819+
try {
820+
editor.putInt("fec_recovered_to_3", Integer.parseInt(edits[2].getText().toString()));
821+
} catch (Exception ignored) {
822+
}
823+
try {
824+
editor.putInt("fec_recovered_to_2", Integer.parseInt(edits[3].getText().toString()));
825+
} catch (Exception ignored) {
826+
}
827+
try {
828+
editor.putInt("fec_recovered_to_1", Integer.parseInt(edits[4].getText().toString()));
829+
} catch (Exception ignored) {
830+
}
817831
editor.apply();
818832
setFecThresholdsFromPrefs();
819833
})
@@ -1428,6 +1442,7 @@ public void onWfbNgStatsChanged(WfbNGStats data) {
14281442
if (data.count_p_all > 0) {
14291443
binding.tvMessage.setVisibility(View.INVISIBLE);
14301444
binding.tvMessage.setText("");
1445+
14311446
if (data.count_p_dec_err > 0) {
14321447
binding.tvLinkStatus.setText("Waiting for session key.");
14331448
} else {
@@ -1437,23 +1452,36 @@ public void onWfbNgStatsChanged(WfbNGStats data) {
14371452
entries.add(new PieEntry((float) data.count_p_dec_ok / data.count_p_all));
14381453
entries.add(new PieEntry((float) data.count_p_fec_recovered / data.count_p_all));
14391454
entries.add(new PieEntry((float) data.count_p_lost / data.count_p_all));
1455+
14401456
PieDataSet dataSet = new PieDataSet(entries, "Link Status");
14411457
dataSet.setDrawIcons(false);
14421458
dataSet.setDrawValues(false);
1459+
14431460
ArrayList<Integer> colors = new ArrayList<>();
14441461
colors.add(getColor(R.color.colorGreen));
14451462
colors.add(getColor(R.color.colorYellow));
14461463
colors.add(getColor(R.color.colorRed));
14471464
dataSet.setColors(colors);
1465+
14481466
PieData pieData = new PieData(dataSet);
14491467
pieData.setValueFormatter(new PercentFormatter());
14501468
pieData.setValueTextSize(11f);
14511469
pieData.setValueTextColor(Color.WHITE);
14521470

1471+
int rssiColor = getColor(R.color.colorGreenBg);
1472+
if (data.avg_rssi < 60 && 30 <= data.avg_rssi) {
1473+
rssiColor = getColor(R.color.colorYellow);
1474+
} else if (data.avg_rssi < 30) {
1475+
rssiColor = getColor(R.color.colorRed);
1476+
}
1477+
14531478
binding.pcLinkStat.setData(pieData);
1454-
binding.pcLinkStat.setCenterText("" + data.count_p_fec_recovered);
1479+
binding.pcLinkStat.setCenterTextSize(22);
1480+
binding.pcLinkStat.setCenterText("" + data.avg_rssi);
1481+
binding.pcLinkStat.setCenterTextColor(rssiColor);
14551482
binding.pcLinkStat.invalidate();
14561483

1484+
// Set link icon tint color.
14571485
int color = getColor(R.color.colorGreenBg);
14581486
if ((float) data.count_p_fec_recovered / data.count_p_all > 0.2) {
14591487
color = getColor(R.color.colorYellowBg);
@@ -1462,14 +1490,15 @@ public void onWfbNgStatsChanged(WfbNGStats data) {
14621490
color = getColor(R.color.colorRedBg);
14631491
}
14641492
binding.imgLinkStatus.setImageTintList(ColorStateList.valueOf(color));
1465-
binding.tvLinkStatus.setText(String.format("O%sD%sR%sL%s",
1466-
paddedDigits(data.count_p_outgoing, 6),
1467-
paddedDigits(data.count_p_dec_ok, 6),
1468-
paddedDigits(data.count_p_fec_recovered, 6),
1469-
paddedDigits(data.count_p_lost, 6)));
1493+
1494+
binding.tvLinkStatus.setText(String.format("Outgoing %3d Decoded %3d Recovered %3d Lost %3d",
1495+
data.count_p_outgoing,
1496+
data.count_p_dec_ok,
1497+
data.count_p_fec_recovered,
1498+
data.count_p_lost));
14701499
}
14711500
} else {
1472-
binding.tvLinkStatus.setText("No wfb-ng data.");
1501+
binding.tvLinkStatus.setText("No Video Link");
14731502
}
14741503
});
14751504
}

app/src/main/java/com/openipc/pixelpilot/osd/OSDManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public void onFinish() {
9999
listOSDItems.add(new OSDElement("Timer", binding.itemTimer));
100100
listOSDItems.add(new OSDElement("Total Distance", binding.itemTotDis));
101101
listOSDItems.add(new OSDElement("Video Decoding", binding.itemVideoStats));
102-
listOSDItems.add(new OSDElement("Video Link Txt", binding.itemLinkStatus));
103-
listOSDItems.add(new OSDElement("Video Link Graph", binding.itemLinkStatusChart));
102+
listOSDItems.add(new OSDElement("Video Link Status", binding.itemLinkStatus));
103+
listOSDItems.add(new OSDElement("Video Link Status Graph", binding.itemLinkStatusChart));
104104
restoreOSDConfig();
105105
}
106106

@@ -218,6 +218,7 @@ public void render(MavlinkData data) {
218218
};
219219
binding.tvFlightMode.setText(flightMode);
220220

221+
// Video status
221222
if (!Objects.equals(currentFCStatus, data.status_text)) {
222223
currentFCStatus = data.status_text;
223224
binding.tvStatus.setVisibility(View.VISIBLE);

app/src/main/res/layout/activity_video.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
android:layout_height="38dp"
129129
android:layout_marginStart="5dp"
130130
android:gravity="start|center_vertical"
131-
android:text="Video Stats"
131+
android:text="Video Decoding Stats"
132132
android:textColor="@color/colorWhite"
133133
android:textSize="14sp" />
134134
</com.openipc.pixelpilot.osd.MovableLayout>

app/wfbngrtl8812/src/main/cpp/SignalQualityCalculator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ SignalQualityCalculator::SignalQuality SignalQualityCalculator::calculate_signal
8585

8686
// __android_log_print(ANDROID_LOG_DEBUG, TAG, "avg_rssi: %f", avg_rssi);
8787

88-
// Map the RSSI from range 10..80 to -1024..1024
88+
// Map the RSSI from range 0..80 to -1024..1024
8989
avg_rssi = map_range(avg_rssi, 0.f, 80.f, -1024.f, 1024.f);
9090
avg_rssi = std::max(-1024.f, std::min(1024.f, avg_rssi));
9191

app/wfbngrtl8812/src/main/cpp/WfbngLink.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_native
350350
native(wfbngLinkN)->stop(env, androidContext, fd);
351351
}
352352

353+
float map_range(float value, float inputMin, float inputMax, float outputMin, float outputMax) {
354+
return outputMin + ((value - inputMin) * (outputMax - outputMin) / (inputMax - inputMin));
355+
}
356+
353357
extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_nativeCallBack(JNIEnv *env,
354358
jclass clazz,
355359
jobject wfbStatChangedI,
@@ -363,12 +367,16 @@ extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_native
363367
if (jcStats == nullptr) {
364368
return;
365369
}
366-
jmethodID jcStatsConstructor = env->GetMethodID(jcStats, "<init>", "(IIIIIIII)V");
370+
jmethodID jcStatsConstructor = env->GetMethodID(jcStats, "<init>", "(IIIIIIIII)V");
367371
if (jcStatsConstructor == nullptr) {
368372
return;
369373
}
370374
SignalQualityCalculator::get_instance().add_fec_data(
371375
aggregator->count_p_all, aggregator->count_p_fec_recovered, aggregator->count_p_lost);
376+
377+
auto quality = SignalQualityCalculator::get_instance().calculate_signal_quality();
378+
uint32_t avg_rssi_int = round(map_range(quality.quality, -1024.f, 1024.f, 0.f, 100.f));
379+
372380
auto stats = env->NewObject(jcStats,
373381
jcStatsConstructor,
374382
(jint)aggregator->count_p_all,
@@ -378,7 +386,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_native
378386
(jint)aggregator->count_p_lost,
379387
(jint)aggregator->count_p_bad,
380388
(jint)aggregator->count_p_override,
381-
(jint)aggregator->count_p_outgoing);
389+
(jint)aggregator->count_p_outgoing,
390+
(jint)avg_rssi_int);
382391
if (stats == nullptr) {
383392
return;
384393
}

app/wfbngrtl8812/src/main/java/com/openipc/wfbngrtl8812/WfbNGStats.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ public class WfbNGStats {
1212
public final int count_p_bad;
1313
public final int count_p_override;
1414
public final int count_p_outgoing;
15+
public final int avg_rssi;
1516

1617
public WfbNGStats(int cntPall, int cntDecErr, int cntDecOk, int cntFecRec,
17-
int cntLost, int cntBad, int cntOverride, int cntOutgoing) {
18+
int cntLost, int cntBad, int cntOverride, int cntOutgoing, int avgRssi) {
1819
count_p_all = cntPall;
1920
count_p_dec_err = cntDecErr;
2021
count_p_dec_ok = cntDecOk;
@@ -23,5 +24,6 @@ public WfbNGStats(int cntPall, int cntDecErr, int cntDecOk, int cntFecRec,
2324
count_p_bad = cntBad;
2425
count_p_override = cntOverride;
2526
count_p_outgoing = cntOutgoing;
27+
avg_rssi = avgRssi;
2628
}
2729
}

0 commit comments

Comments
 (0)