Skip to content

Commit

Permalink
Functionality to enable/disable Adaptive Link and set TX power (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexodessa authored Feb 23, 2025
1 parent e7cdf78 commit 70e9b59
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 132 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ android {
buildFeatures {
viewBinding = true
}
buildToolsVersion '35.0.0'
ndkVersion '26.1.10909125'
}

dependencies {
Expand Down
64 changes: 61 additions & 3 deletions app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private void initializeUI() {
private void initializeWfbNg() {
setDefaultGsKey();
copyGSKey();
WfbNgLink wfbLink = new WfbNgLink(this);
wfbLink = new WfbNgLink(this);
wfbLink.SetWfbNGStatsChanged(this);
wfbLinkManager = new WfbLinkManager(this, binding, wfbLink);
}
Expand Down Expand Up @@ -553,6 +553,9 @@ private void showSettingsMenu(View anchor) {
// WFB submenu
setupWFBSubMenu(popup);

// Adaptive link submenu
setupAdaptiveLinkSubMenu(popup);

// Recording submenu
setupRecordingSubMenu(popup);

Expand Down Expand Up @@ -648,7 +651,7 @@ private void setupOSDSubMenu(PopupMenu popup) {
* Submenu handling WFB-NG logic (e.g. selecting gs.key from storage).
*/
private void setupWFBSubMenu(PopupMenu popup) {
SubMenu wfb = popup.getMenu().addSubMenu("WFB-NG");
SubMenu wfb = popup.getMenu().addSubMenu("WFB-NG key");
MenuItem keyBtn = wfb.add("gs.key");
keyBtn.setOnMenuItemClickListener(item -> {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
Expand All @@ -659,6 +662,61 @@ private void setupWFBSubMenu(PopupMenu popup) {
});
}

/**
* Submenu for Adaptive link functionality.
* It creates two options:
* - "Enable": toggles the adaptive link quality thread
* - "Power": a submenu that lets the user choose the TX power (1, 10, 20, 30, 40)
*/
private void setupAdaptiveLinkSubMenu(PopupMenu popup) {
SubMenu adaptiveMenu = popup.getMenu().addSubMenu("Adaptive link");

SharedPreferences prefs = getSharedPreferences("general", MODE_PRIVATE);
boolean adaptiveEnabled = prefs.getBoolean("adaptive_link_enabled", true);
int adaptiveTxPower = prefs.getInt("adaptive_tx_power", 30);
wfbLink.nativeSetAdaptiveLinkEnabled(adaptiveEnabled);
wfbLink.nativeSetTxPower(adaptiveTxPower);

// Adaptive link Enable option
MenuItem adaptiveEnable = adaptiveMenu.add("Enable");
adaptiveEnable.setCheckable(true);
adaptiveEnable.setChecked(adaptiveEnabled);
adaptiveEnable.setOnMenuItemClickListener(item -> {
boolean newState = !item.isChecked();
item.setChecked(newState);
SharedPreferences.Editor editor = getSharedPreferences("general", MODE_PRIVATE).edit();
editor.putBoolean("adaptive_link_enabled", newState);
editor.apply();
// Call instance method on the WfbNgLink instance via the wfbLinkManager.
wfbLink.nativeSetAdaptiveLinkEnabled(newState);
return true;
});

// Adaptive link Power submenu
SubMenu powerSubMenu = adaptiveMenu.addSubMenu("Power");
int[] txOptions = {1, 10, 20, 30, 40};
for (int power : txOptions) {
MenuItem powerItem = powerSubMenu.add(String.valueOf(power));
powerItem.setCheckable(true);
if (power == adaptiveTxPower) {
powerItem.setChecked(true);
}
powerItem.setOnMenuItemClickListener(item -> {
// Uncheck all items in the submenu
for (int i = 0; i < powerSubMenu.size(); i++) {
powerSubMenu.getItem(i).setChecked(false);
}
item.setChecked(true);
SharedPreferences.Editor editor = getSharedPreferences("general", MODE_PRIVATE).edit();
editor.putInt("adaptive_tx_power", power);
editor.apply();
// Call instance method on the WfbNgLink instance via the wfbLinkManager.
wfbLink.nativeSetTxPower(power);
return true;
});
}
}

/**
* Submenu for recording options, including start/stop DVR and toggling fMP4.
*/
Expand Down Expand Up @@ -851,7 +909,7 @@ private void shareLogs() {
}

// ----------------------------------------------------------------------------
// VPN Service
// VPN SERVICE
// ----------------------------------------------------------------------------
private void startVpnService() {
int VPN_REQUEST_CODE = 100;
Expand Down
Loading

0 comments on commit 70e9b59

Please sign in to comment.