Skip to content

Commit

Permalink
Add output twist support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Riggs committed Nov 24, 2018
1 parent b2378ec commit 9dcea34
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

4 changes: 2 additions & 2 deletions mobilinkdTNC/build.gradle
Expand Up @@ -10,10 +10,10 @@ android {
targetSdkVersion 28

// Defines the version number of your app.
versionCode 17
versionCode 18

// Defines a user-friendly version name for your app.
versionName "1.2.3"
versionName "1.2.4"
}

buildTypes {
Expand Down
12 changes: 12 additions & 0 deletions mobilinkdTNC/mobilinkdTNC.iml
Expand Up @@ -87,24 +87,36 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotation_processor_list" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/apk_list" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-libraries" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/checkDebugClasspath" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/checkReleaseClasspath" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/compatible_screen_manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_main_apk_resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_merged_manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processed_res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shader_assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split_list" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
Expand Down
Expand Up @@ -27,6 +27,8 @@
import android.widget.ToggleButton;
import android.widget.SeekBar.OnSeekBarChangeListener;

import java.util.Locale;

public class AudioOutputFragment extends DialogFragment {
// Debugging
private static final String TAG = "AudioOutputFragment";
Expand All @@ -44,6 +46,7 @@ public interface Listener {
void onAudioOutputDialogPttStyleChanged(AudioOutputFragment dialog);
void onAudioOutputDialogLevelChanged(AudioOutputFragment dialog);
void onAudioOutputDialogToneChanged(AudioOutputFragment dialog);
void onAudioOutputDialogTwistLevelChanged(AudioOutputFragment dialog);
}

private Context mContext = null;
Expand All @@ -66,7 +69,13 @@ public interface Listener {

private long mLastOutputVolumeUpdateTimestamp = 0;

@SuppressLint("SetTextI18n")
private boolean mHasOutputTwistControl = false;
private TextView mOutputTwistLevelText = null;
private SeekBar mOutputTwistLevelBar = null;
private int mOutputTwistLevel = 0;
private long mLastOutputTwistUpdateTimestamp = 0;

@SuppressLint("SetTextI18n")
private View configureDialogView(View view)
{
mPttStyleGroup = view.findViewById(R.id.pttStyleGroup);
Expand Down Expand Up @@ -202,11 +211,68 @@ public void onClick(View view) {
mPttStyleGroup.getChildAt(i).setEnabled(!mPtt);
}
mOutputVolumeLevel.setEnabled(mPtt);
mOutputTwistLevelBar.setEnabled(mPtt);
mListener.onAudioOutputDialogToneChanged(AudioOutputFragment.this);
}
});
mPttButton.getBackground().setAlpha(64);

LinearLayout outputTwistLayout = view.findViewById(R.id.outputTwistLayout);

if (mHasOutputTwistControl) {
outputTwistLayout.setVisibility(LinearLayout.VISIBLE);
} else {
outputTwistLayout.setVisibility(LinearLayout.GONE);
}

mOutputTwistLevelText = view.findViewById(R.id.outputTwistLevelText);
mOutputTwistLevelBar = view.findViewById(R.id.outputTwistLevelBar);
mOutputTwistLevelBar.setProgress(mOutputTwistLevel);
mOutputTwistLevelBar.setEnabled(mPtt);
mOutputTwistLevelText.setText(String.format(Locale.getDefault(),"%d", mOutputTwistLevel));

ImageButton outputTwistHelpButton = view.findViewById(R.id.outputTwistHelpButton);
outputTwistHelpButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
new AlertDialog.Builder(mContext)
.setTitle(R.string.output_twist_help_title)
.setMessage(R.string.output_twist_help)
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// pass
}
}).show();
}
});
outputTwistHelpButton.getBackground().setAlpha(64);

mOutputTwistLevelBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekbar, int level, boolean fromUser) {

if (fromUser) {
long now = System.currentTimeMillis();
mOutputTwistLevel = level;
// Limit update rate to 100ms.
if (now - mLastOutputTwistUpdateTimestamp >= 100) {
mListener.onAudioOutputDialogTwistLevelChanged(AudioOutputFragment.this);
mLastOutputTwistUpdateTimestamp = now;
}
}
mOutputTwistLevelText.setText(String.format(Locale.getDefault(),"%d", mOutputTwistLevel));
}
@Override
public void onStartTrackingTouch(SeekBar seekbar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekbar) {
mListener.onAudioOutputDialogTwistLevelChanged(AudioOutputFragment.this);
mLastOutputTwistUpdateTimestamp = System.currentTimeMillis();
}
});

return view;
}

Expand Down Expand Up @@ -327,4 +393,23 @@ public int getTone() {
public boolean getPtt() {
return mPtt;
}

public int getOutputTwist()
{
return mOutputTwistLevel;
}

public void setOutputTwist(int level)
{
if(D) Log.d(TAG, "setOutputTwist = " + level);

mHasOutputTwistControl = true;
mOutputTwistLevel = level;

if (isAdded()) {
mOutputTwistLevelBar.setProgress(mOutputTwistLevel);
mOutputTwistLevelText.setText(String.format(Locale.getDefault(),"%d",level));
}
}

}
Expand Up @@ -113,7 +113,9 @@ public class BluetoothTncService {
new byte[] { (byte)0xc0, 0x06, 0x01, 0, 0, (byte)0xC0 }; // API 2.0
private static final byte[] TNC_GET_OUTPUT_VOLUME =
new byte[] { (byte)0xc0, 0x06, 0x0C, (byte)0xC0 };
private static final byte[] TNC_SET_SQUELCH_LEVEL =
private static final byte[] TNC_SET_OUTPUT_TWIST =
new byte[] { (byte)0xc0, 0x06, 0x1A, (byte)0xC0 };
private static final byte[] TNC_SET_SQUELCH_LEVEL =
new byte[] { (byte)0xc0, 0x06, 0x03, 0, (byte)0xC0 };
private static final byte[] TNC_GET_ALL_VALUES =
new byte[] { (byte)0xc0, 0x06, 0x7F, (byte)0xC0 };
Expand Down Expand Up @@ -748,7 +750,24 @@ public void volume(int v)
c[4] = (byte) (v & 0xFF);
r.write(c); }
}


public void outputTwist(int v)
{
if (D) Log.d(TAG, "outputTwist() = " + v);

// Create temporary object
ConnectedThread r;
// Synchronize a copy of the ConnectedThread
synchronized (this) {
if (mState != STATE_CONNECTED) return;
r = mConnectedThread;
}
byte c[] = TNC_SET_OUTPUT_TWIST;
c[3] = (byte) v;
r.write(c);
}


/**
* Write to the ConnectedThread in an unsynchronized manner
* @param out The bytes to write
Expand Down Expand Up @@ -1044,6 +1063,13 @@ public void run() {
mHdlc.size(), data).sendToTarget();
}
break;
case HdlcDecoder.TNC_GET_OUTPUT_TWIST:
// Send the obtained bytes to the UI Activity
Log.i(TAG, "TNC_GET_OUTPUT_TWIST = " + mHdlc.getValue());
mHandler.obtainMessage(
TncConfig.MESSAGE_OUTPUT_TWIST, (int) mHdlc.getValue(),
mHdlc.size(), mHdlc.data()).sendToTarget();
break;
case HdlcDecoder.TNC_GET_TXDELAY:
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(
Expand Down
24 changes: 22 additions & 2 deletions mobilinkdTNC/src/main/java/com/mobilinkd/tncconfig/TncConfig.java
Expand Up @@ -82,7 +82,7 @@ public class TncConfig extends FragmentActivity
public static final int MESSAGE_INPUT_TWIST = 26;
public static final int MESSAGE_INPUT_TWIST_MIN = 27;
public static final int MESSAGE_INPUT_TWIST_MAX = 28;

public static final int MESSAGE_OUTPUT_TWIST = 29;

// Key names received from the BluetoothTncService Handler
public static final String DEVICE_NAME = "device_name";
Expand Down Expand Up @@ -115,6 +115,8 @@ public class TncConfig extends FragmentActivity
private boolean mHasPttStyle = false;
private int mPttStyle = AudioOutputFragment.PTT_STYLE_SIMPLEX;
private int mOutputVolume = 0;
private boolean mHasOutputTwist = false;
private int mOutputTwist = 50;

private AudioInputFragment mAudioInputFragment = null;
private Button mAudioInputButton = null;
Expand Down Expand Up @@ -168,6 +170,8 @@ private void onBluetoothConnected() {
mTncService.setDateTIme();
mTncService.getAllValues();
mNeedsSave = false;
mHasOutputTwist = false;
mHasInputGain = false;
} else {
Toast.makeText(this, R.string.msg_bt_not_connected, Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -211,6 +215,8 @@ private void onBluetoothDisconnected() {
mSaveButton.setVisibility(Button.GONE);
mHasEeprom = false;
mNeedsSave = false;
mHasOutputTwist = false;
mHasInputGain = false;
}

private void settingsUpdated() {
Expand Down Expand Up @@ -255,6 +261,11 @@ public void handleMessage(Message msg) {
tncConfig.mOutputVolume = msg.arg1;
if(D) Log.d(TAG, "output volume: " + tncConfig.mOutputVolume);
break;
case MESSAGE_OUTPUT_TWIST:
tncConfig.mHasOutputTwist = true;
tncConfig.mOutputTwist = msg.arg1;
if(D) Log.d(TAG, "output twist: " + tncConfig.mOutputTwist);
break;
case MESSAGE_TX_DELAY:
tncConfig.mTxDelay = msg.arg1;
if(D) Log.d(TAG, "tx delay: " + msg.arg1);
Expand Down Expand Up @@ -537,6 +548,10 @@ public void onClick(View view) {

audioOutputFragment.setVolume(mOutputVolume);

if (mHasOutputTwist) {
audioOutputFragment.setOutputTwist(mOutputTwist);
}

FrameLayout fragmentView = (FrameLayout) findViewById(R.id.fragment_view);
if (fragmentView != null) {
audioOutputFragment.setShowsDialog(false);
Expand Down Expand Up @@ -842,7 +857,12 @@ public void onAudioOutputDialogToneChanged(AudioOutputFragment dialog) {
mTncService.ptt(TONE_NONE);
}
}


@Override
public void onAudioOutputDialogTwistLevelChanged(AudioOutputFragment dialog) {
mOutputTwist = dialog.getOutputTwist();
mTncService.outputTwist(mOutputTwist);
}

@Override
public void onAudioInputDialogClose(AudioInputFragment dialog) {
Expand Down

0 comments on commit 9dcea34

Please sign in to comment.