AFSK: allow bluetooth headset, audio routing

white
Georg Lukas 2012-02-15 21:58:20 +01:00
rodzic 3bc1e7011a
commit 9463772c18
5 zmienionych plików z 80 dodań i 10 usunięć

Wyświetl plik

@ -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"/>

Wyświetl plik

@ -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>

Wyświetl plik

@ -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>
@ -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>

Wyświetl plik

@ -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"
@ -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>

Wyświetl plik

@ -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}
@ -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 = {
@ -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]) {
@ -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)
}
}