Skip to content

Commit

Permalink
backed/DigiRig: Sync RTS signal to audio playback
Browse files Browse the repository at this point in the history
I originally had some hacky code in here to _hopfeully_ ensure that the
RTS signal was raise while packets were being transmitted, but it was
only a best-guess attempt.  This commit implements an
OnPlaybackPositionUpdateListener to tell us exactly when the audio for a
packet has finished playing, so we know exactly when to clear the RTS
signal.
  • Loading branch information
bxlentpartyon committed Aug 3, 2024
1 parent 69f6cc3 commit e93b820
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/backend/DigiRig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.content.SharedPreferences
import android.hardware.usb.UsbManager
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbDeviceConnection
import android.media.AudioTrack.OnPlaybackPositionUpdateListener
import android.util.Log
import java.io.{InputStream, OutputStream}

Expand Down Expand Up @@ -59,7 +60,15 @@ class DigiRig(service : AprsService, prefs : PrefsWrapper) extends AfskUploader(
val pendingIntent = PendingIntent.getBroadcast(service, 0, intent, 0)

// Audio stuff
var audioPlaying = false
output.setVolume(AudioTrack.getMaxVolume())
output.setPlaybackPositionUpdateListener(new OnPlaybackPositionUpdateListener {
override def onMarkerReached(audioTrack: AudioTrack): Unit = {
DigiRig.this.audioPlaying = false
}

override def onPeriodicNotification(audioTrack: AudioTrack): Unit = {}
})

val receiver = new BroadcastReceiver() {
override def onReceive(ctx: Context, i: Intent) {
Expand Down Expand Up @@ -167,14 +176,11 @@ class DigiRig(service : AprsService, prefs : PrefsWrapper) extends AfskUploader(
Log.d(TAG, "update(): From: " + from + " To: " + to + " Via: " + Digis + " telling " + data)

ser.setRTS(true)
val bits_per_byte = 8
val bits_in_frame = packet.toAX25Frame().length / bits_per_byte
val ms_per_s = 1000
val sleep_ms = bits_in_frame * ms_per_s / 1200 // aprs is 1200 baud
val sleep_pad_ms = 1500
Thread.sleep(sleep_ms + sleep_pad_ms)
audioPlaying = true
val result = sendMessage(msg)
Thread.sleep(sleep_ms + sleep_pad_ms)
while (audioPlaying) {
Thread.sleep(10)
}
ser.setRTS(false)

if (result)
Expand Down

0 comments on commit e93b820

Please sign in to comment.