Skip to content

Commit

Permalink
Merge branch 'VanceVagell:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
SmittyHalibut authored Dec 5, 2024
2 parents 5be4ba6 + b227af2 commit fe50696
Show file tree
Hide file tree
Showing 12 changed files with 632 additions and 169 deletions.
Binary file not shown.
Binary file not shown.
15 changes: 14 additions & 1 deletion android-src/KV4PHT/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions android-src/KV4PHT/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.vagell.kv4pht"
minSdk 26
targetSdk 34
versionCode 19
versionName "1.2.3"
versionCode 21
versionName "1.3.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ public interface RadioAudioServiceCallbacks {
public void scannedToMemory(int memoryId);
public void outdatedFirmware(int firmwareVer);
public void missingFirmware();
public void txAllowed(boolean allowed);
public void txStarted();
public void txEnded();
public void chatError(String snackbarText);
}

public void setCallbacks(RadioAudioServiceCallbacks callbacks) {
Expand Down Expand Up @@ -409,21 +413,34 @@ public void tuneToFreq(String frequencyStr, int squelchLevel, boolean forceTune)

// Reset audio prebuffer
restartAudioPrebuffer();

try {
Float freq = Float.parseFloat(activeFrequencyStr);
if (freq < 144.0f || freq > maxFreq) {
callbacks.txAllowed(false);
} else {
callbacks.txAllowed(true);
}
} catch (NumberFormatException nfe) {
}
}

public static String makeSafe2MFreq(String strFreq) {
Float freq;
try {
freq = Float.parseFloat(strFreq);
} catch (NumberFormatException nfe) { // Not sure how some people are breaking this, but default to FM calling frequency if we can't understand strFreq.
nfe.printStackTrace();
return "146.5200";
return "144.0000";
}
while (freq > 148.0f) { // Handle cases where user inputted "1467" or "14670" but meant "146.7".
while (freq > 500.0f) { // Handle cases where user inputted "1467" or "14670" but meant "146.7".
freq /= 10;
}
freq = Math.min(freq, maxFreq);
freq = Math.max(freq, 144.0f);

if (freq < 134.0f) {
freq = 134.0f; // Lowest freq supported by radio module
} else if (freq > 174.0f) {
freq = 174.0f; // Highest freq supported
}

strFreq = String.format(java.util.Locale.US,"%.4f", freq);

Expand Down Expand Up @@ -483,6 +500,16 @@ public void tuneToMemory(ChannelMemory memory, int squelchLevel, boolean forceTu

// Reset audio prebuffer
restartAudioPrebuffer();

try {
Float txFreq = Float.parseFloat(getTxFreq(memory.frequency, memory.offset));
if (txFreq < 144.0f || txFreq > maxFreq) {
callbacks.txAllowed(false);
} else {
callbacks.txAllowed(true);
}
} catch (NumberFormatException nfe) {
}
}

private String getToneIdxStr(String toneStr) {
Expand Down Expand Up @@ -549,7 +576,7 @@ private void initAudioTrack() {
}
}

public void startPtt(boolean dataMode) {
public void startPtt() {
setMode(MODE_TX);

// Setup runaway tx safety measures.
Expand All @@ -576,6 +603,7 @@ public void run() {

sendCommandToESP32(ESP32Command.PTT_DOWN);
audioTrack.stop();
callbacks.txStarted();
}

public void endPtt() {
Expand All @@ -586,6 +614,7 @@ public void endPtt() {
sendCommandToESP32(ESP32Command.PTT_UP);
audioTrack.flush();
restartAudioPrebuffer();
callbacks.txEnded();
}

public void reconnectViaUSB() {
Expand Down Expand Up @@ -1163,8 +1192,15 @@ public void sendChatMessage(String targetCallsign, String outText) {
Log.d("DEBUG", "Warning: Tried to send a chat message with no recipient callsign, defaulted to 'CQ'.");
targetCallsign = "CQ";
}
APRSPacket aprsPacket = new APRSPacket(callsign, targetCallsign, digipeaters, msgPacket.getRawBytes());
Packet ax25Packet = new Packet(aprsPacket.toAX25Frame());

Packet ax25Packet = null;
try {
APRSPacket aprsPacket = new APRSPacket(callsign, targetCallsign, digipeaters, msgPacket.getRawBytes());
ax25Packet = new Packet(aprsPacket.toAX25Frame());
} catch (IllegalArgumentException iae) {
callbacks.chatError("Error in your callsign or To: callsign.");
return;
}

// TODO start a timer to re-send this packet (up to a few times) if we don't receive an ACK for it.
txAX25Packet(ax25Packet);
Expand All @@ -1186,7 +1222,7 @@ private void txAX25Packet(Packet ax25Packet) {
}
byte[] simpleAudioBytes = ArrayUtils.toPrimitive(audioBytes.toArray(new Byte[0]));

startPtt(true);
startPtt();
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ kv4p HT (see http://kv4p.com)
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.textfield.TextInputEditText;
import com.vagell.kv4pht.R;
Expand All @@ -51,6 +53,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_edit_memory);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

threadPoolExecutor = new ThreadPoolExecutor(2,
2, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

Expand Down Expand Up @@ -122,6 +126,25 @@ public void run() {
AutoCompleteTextView editMemoryGroupTextInputEditText = findViewById(R.id.editMemoryGroupTextInputEditText);
editMemoryGroupTextInputEditText.setText(selectedMemoryGroup, false);
}

String offset = extras.getString("offset");
if (offset != null) {
AutoCompleteTextView editOffset = findViewById(R.id.editOffsetTextView);
editOffset.setText(offset, false);
}

String tone = extras.getString("tone");
if (tone != null) {
AutoCompleteTextView editTone = findViewById(R.id.editToneTextView);
editTone.setText(tone, false);
}

String name = extras.getString("name");
if (name != null) {
TextInputEditText editNameTextInputEditText = findViewById(R.id.editNameTextInputEditText);
editNameTextInputEditText.setText(name);
}

}
}

Expand Down Expand Up @@ -160,6 +183,13 @@ private void populateMemoryGroups() {
threadPoolExecutor.execute(new Runnable() {
@Override
public void run() {
if( MainViewModel.appDb == null ) {
//For example direct call other app intent.
//If app is not already open do not nullpointer-exception.
MainViewModel preloader = new MainViewModel();
preloader.setActivity(activity);
preloader.loadData();
}
List<String> memoryGroups = MainViewModel.appDb.channelMemoryDao().getGroups();

// Remove any blank memory groups from the list (shouldn't have been saved, ideally).
Expand Down
Loading

0 comments on commit fe50696

Please sign in to comment.