Skip to content

Commit

Permalink
AFSK: allow bluetooth headset, audio routing
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0rg committed Feb 15, 2012
1 parent 3bc1e70 commit 9463772
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 10 deletions.
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE"/>

Expand Down
6 changes: 6 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<item>afsk</item>
<item>bluetooth</item>
</string-array>
<string-array name="p_afsk_out_ev">
<item>0</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>

<string-array name="p_locsource_e">
<item>@string/p_source_smart</item>
Expand Down
12 changes: 12 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@
<string name="p_afsk_prefix">Frame Sync Prefix</string>
<string name="p_afsk_prefix_summary">No-Op Preamble (e.g. for VOX control)</string>
<string name="p_afsk_prefix_entry">Enter the prefix time [ms]</string>
<string name="p_afsk_btsco">Bluetooth Headset</string>
<string name="p_afsk_btsco_summary">Use Bluetooth (SCO) headset for AFSK</string>
<string name="p_afsk_output">Audio Output</string>
<string-array name="p_afsk_out_e">
<item>Voice Call</item>
<item>Ringtone</item>
<item>Music</item>
<item>Alarm</item>
</string-array>

<!-- TCP server settings -->
<string name="p_tcp_server_summary">APRS-IS TCP server (port 14580) to contact</string>
Expand Down Expand Up @@ -300,4 +309,7 @@
<string name="bt_error_unsupported">Bluetooth is not supported!</string>
<string name="bt_error_disabled">Please enable Bluetooth!</string>
<string name="bt_error_no_tnc">Please configure a Bluetooth TNC!</string>

<string name="afsk_info_sco_req">Requesting bluetooth SCO link...</string>
<string name="afsk_info_sco_est">Bluetooth SCO link established.</string>
</resources>
30 changes: 23 additions & 7 deletions res/xml/backend_afsk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
<PreferenceCategory
android:title="@string/p_conn_afsk">

<de.duenndns.EditTextPreferenceWithValue
android:key="digi_path"
android:hint="hop1,hop2,.."
android:defaultValue="WIDE1-1"
android:title="@string/p_aprs_path"
android:summary="@string/p_aprs_path_summary"
android:dialogTitle="@string/p_aprs_path_entry" />
<CheckBoxPreference
android:key="afsk.btsco"
android:title="@string/p_afsk_btsco"
android:summary="@string/p_afsk_btsco_summary"
android:defaultValue="false"
/>

<de.duenndns.ListPreferenceWithValue
android:key="afsk.output"
android:title="@string/p_afsk_output"
android:entries="@array/p_afsk_out_e"
android:entryValues="@array/p_afsk_out_ev"
android:defaultValue="0"
android:dialogTitle="@string/p_afsk_output"
/>

<de.duenndns.EditTextPreferenceWithValue
android:key="afsk.prefix"
Expand All @@ -22,6 +30,14 @@
android:summary="@string/p_afsk_prefix_summary"
android:dialogTitle="@string/p_afsk_prefix_entry" />

<de.duenndns.EditTextPreferenceWithValue
android:key="digi_path"
android:hint="hop1,hop2,.."
android:defaultValue="WIDE1-1"
android:title="@string/p_aprs_path"
android:summary="@string/p_aprs_path_summary"
android:dialogTitle="@string/p_aprs_path_entry" />

</PreferenceCategory>

</PreferenceScreen>
Expand Down
41 changes: 38 additions & 3 deletions src/backend/AfskUploader.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.aprsdroid.app

import _root_.android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import _root_.android.media.AudioManager
import _root_.android.util.Log
import _root_.java.net.{InetAddress, DatagramSocket, DatagramPacket}
import _root_.net.ab0oo.aprs.parser.{APRSPacket, Digipeater, Parser}
Expand All @@ -13,12 +15,36 @@ class AfskUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUp
// frame prefix: bytes = milliseconds * baudrate / 8 / 1000
var FrameLength = prefs.getStringInt("afsk.prefix", 1000)*1200/8/1000
var Digis = prefs.getString("digi_path", "WIDE1-1")
val output = new Afsk()
val use_bt = prefs.getAfskBluetooth()
val out_type = prefs.getAfskOutput()
val output = new Afsk(out_type)
val abp = new AudioBufferProcessor(this)

val btScoReceiver = new BroadcastReceiver() {
override def onReceive(ctx : Context, i : Intent) {
val state = i.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1)
Log.d(TAG, "AudioManager SCO event: " + state)
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
// we are connected, perform actual start
log(service.getString(R.string.afsk_info_sco_est))
abp.start()
service.unregisterReceiver(this)
service.postPosterStarted()
}
}
}

def start() = {
abp.start()
true
if (use_bt) {
log(service.getString(R.string.afsk_info_sco_req))
service.getSystemService(Context.AUDIO_SERVICE)
.asInstanceOf[AudioManager].startBluetoothSco()
service.registerReceiver(btScoReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED))
false
} else {
abp.start()
true
}
}

def update(packet : APRSPacket) : String = {
Expand All @@ -35,6 +61,9 @@ class AfskUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUp

def stop() {
abp.stopRecording()
if (use_bt)
service.getSystemService(Context.AUDIO_SERVICE)
.asInstanceOf[AudioManager].stopBluetoothSco()
}

def received(data : Array[Byte]) {
Expand All @@ -45,4 +74,10 @@ class AfskUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUp
Log.e(TAG, "bad packet: %s".format(data.map("%02x".format(_)).mkString(" "))); e.printStackTrace()
}
}

def log(s : String) {
Log.i(TAG, s)
service.postAddPost(StorageDatabase.Post.TYPE_INFO, R.string.post_info, s)
}

}

0 comments on commit 9463772

Please sign in to comment.