Skip to content

Commit c0e737f

Browse files
committed
Use dedicated trx type for flash light
1 parent 6e15f16 commit c0e737f

File tree

12 files changed

+40
-60
lines changed

12 files changed

+40
-60
lines changed

codec2talkie/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.radio.codec2talkie"
1111
minSdkVersion 23
1212
targetSdkVersion 31
13-
versionCode 175
14-
versionName "1.75"
13+
versionCode 176
14+
versionName "1.76"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

codec2talkie/src/main/java/com/radio/codec2talkie/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ private void startTransportConnection() {
292292
private final ActivityResultLauncher<Intent> _usbActivityLauncher = registerForActivityResult(
293293
new ActivityResultContracts.StartActivityForResult(),
294294
result -> {
295-
Intent data = result.getData();
296-
assert data != null;
297295
int resultCode = result.getResultCode();
298296
if (SettingsWrapper.isSoundModemEnabled(_sharedPreferences)) {
299297
_isRigCtlUsbConnected = resultCode == RESULT_OK;
@@ -302,6 +300,8 @@ private void startTransportConnection() {
302300
_textConnInfo.setText(R.string.main_status_loopback_test);
303301
startAppService(TransportFactory.TransportType.LOOPBACK);
304302
} else if (resultCode == RESULT_OK) {
303+
Intent data = result.getData();
304+
assert data != null;
305305
_textConnInfo.setText(data.getStringExtra("name"));
306306
startAppService(TransportFactory.TransportType.USB);
307307
}

codec2talkie/src/main/java/com/radio/codec2talkie/app/AppWorker.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.radio.codec2talkie.storage.position.PositionItemRepository;
3636
import com.radio.codec2talkie.storage.station.StationItemRepository;
3737
import com.radio.codec2talkie.tools.AudioTools;
38-
import com.radio.codec2talkie.tools.FlashLight;
3938
import com.radio.codec2talkie.transport.Transport;
4039
import com.radio.codec2talkie.transport.TransportFactory;
4140

@@ -50,9 +49,6 @@ public class AppWorker extends Thread {
5049
private static final int PROCESS_INTERVAL_MS = 10;
5150
private static final int LISTEN_AFTER_MS = 1500;
5251

53-
private static final int FLASHLIGHT_PTT_ON_DELAY_MS = 350;
54-
private static final int FLASHLIGHT_PTT_OFF_DELAY_MS = 100;
55-
5652
private boolean _needTransmission = false;
5753
private AppMessage _currentStatus = AppMessage.EV_DISCONNECTED;
5854

@@ -80,9 +76,6 @@ public class AppWorker extends Thread {
8076
private final PositionItemRepository _positionItemRepository;
8177
private final StationItemRepository _stationItemRepository;
8278

83-
// flash light / torch
84-
private final FlashLight _flashLight;
85-
8679
private final Context _context;
8780
private final SharedPreferences _sharedPreferences;
8881

@@ -101,8 +94,6 @@ public AppWorker(TransportFactory.TransportType transportType,
10194
_transport = TransportFactory.create(transportType, context);
10295
_protocol = ProtocolFactory.create(context);
10396

104-
_flashLight = new FlashLight(_context);
105-
10697
_processPeriodicTimer = new Timer();
10798

10899
int audioSource = Integer.parseInt(_sharedPreferences.getString(PreferenceKeys.APP_AUDIO_SOURCE, "6"));
@@ -442,13 +433,11 @@ private void onListening() {
442433
sendTxAudioLevelUpdate(null);
443434
sendRxRadioLevelUpdate(0, 0);
444435
sendStatusUpdate(AppMessage.EV_LISTENING, null);
445-
flashLightOff();
446436
}
447437

448438
private void processRecordPlaybackToggle() throws IOException {
449439
// playback -> recording
450440
if (_needTransmission && _systemAudioRecorder.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
451-
flashLightOn();
452441
_systemAudioPlayer.stop();
453442
_systemAudioRecorder.startRecording();
454443
sendRxAudioLevelUpdate(null);
@@ -458,7 +447,6 @@ private void processRecordPlaybackToggle() throws IOException {
458447
_protocol.flush();
459448
_systemAudioRecorder.stop();
460449
sendTxAudioLevelUpdate(null);
461-
flashLightOff();
462450
}
463451
}
464452

@@ -488,28 +476,6 @@ private void cleanup() {
488476
Log.i(TAG, "cleanup() completed");
489477
}
490478

491-
private void flashLightOn() {
492-
if (SettingsWrapper.isFlashLightPttEnabled(_sharedPreferences)) {
493-
_flashLight.turnOn();
494-
try {
495-
sleep(FLASHLIGHT_PTT_ON_DELAY_MS);
496-
} catch (InterruptedException e) {
497-
e.printStackTrace();
498-
}
499-
}
500-
}
501-
502-
private void flashLightOff() {
503-
if (SettingsWrapper.isFlashLightPttEnabled(_sharedPreferences)) {
504-
try {
505-
sleep(FLASHLIGHT_PTT_OFF_DELAY_MS);
506-
} catch (InterruptedException e) {
507-
e.printStackTrace();
508-
}
509-
_flashLight.turnOff();
510-
}
511-
}
512-
513479
private void processRxTx() throws IOException {
514480
processRecordPlaybackToggle();
515481

@@ -545,7 +511,6 @@ private void onWorkerIncomingMessage(Message msg) {
545511
quitProcessing();
546512
break;
547513
case CMD_SEND_LOCATION_TO_TNC:
548-
flashLightOn();
549514
try {
550515
_protocol.sendPosition((Position)msg.obj);
551516
} catch (IOException e) {
@@ -554,7 +519,6 @@ private void onWorkerIncomingMessage(Message msg) {
554519
}
555520
break;
556521
case CMD_SEND_MESSAGE:
557-
flashLightOn();
558522
TextMessage textMessage = (TextMessage) msg.obj;
559523
try {
560524
_protocol.sendTextMessage(textMessage);

codec2talkie/src/main/java/com/radio/codec2talkie/connect/UsbConnectActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public void run() {
197197
@Override
198198
public void handleMessage(Message msg) {
199199
String toastMsg;
200+
Log.i(TAG, "usb state changed " + msg.what);
200201
if (msg.what == USB_CONNECTED) {
201202
UsbPortHandler.setPort(_usbPort);
202203
UsbPortHandler.setName(_usbDeviceName);

codec2talkie/src/main/java/com/radio/codec2talkie/rigctl/Disabled.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import java.io.IOException;
88

9-
public class Disabled implements RigCtl{
9+
public class Disabled implements RigCtl {
1010
@Override
1111
public void initialize(Transport transport, Context context, RigCtlCallback protocolCallback) throws IOException {
1212
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.radio.codec2talkie.rigctl;
2+
3+
import android.content.Context;
4+
import com.radio.codec2talkie.tools.FlashLight;
5+
import com.radio.codec2talkie.transport.Transport;
6+
7+
import java.io.IOException;
8+
9+
public class PhoneTorch implements RigCtl {
10+
11+
private FlashLight _flashLight;
12+
13+
@Override
14+
public void initialize(Transport transport, Context context, RigCtlCallback protocolCallback) throws IOException {
15+
_flashLight = new FlashLight(context);
16+
}
17+
18+
@Override
19+
public void pttOn() {
20+
_flashLight.turnOn();
21+
}
22+
23+
@Override
24+
public void pttOff() {
25+
_flashLight.turnOff();
26+
}
27+
}

codec2talkie/src/main/java/com/radio/codec2talkie/rigctl/RigCtlFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ public class RigCtlFactory {
1313
private static final String TAG = RigCtlFactory.class.getSimpleName();
1414

1515
public static final String RIG_DISABLED = "Disabled";
16+
public static final String RIG_PHONE_TORCH = "PhoneTorch";
1617

1718
public static RigCtl create(Context context) {
18-
if (UsbPortHandler.getPort() == null)
19-
return new Disabled();
2019
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
2120
String rigName = sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_RIG, RIG_DISABLED);
21+
if (UsbPortHandler.getPort() == null && !rigName.equals(RIG_PHONE_TORCH))
22+
return new Disabled();
2223
try {
2324
Class<?> loadClass = Class.forName(String.format("com.radio.codec2talkie.rigctl.%s", rigName));
2425
Log.i(TAG, "Using rig " + rigName);

codec2talkie/src/main/java/com/radio/codec2talkie/settings/PreferenceKeys.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public final class PreferenceKeys {
7272
public static String KISS_EXTENSIONS_ACTION_REBOOT_REQUESTED = "com.radio.codec2talkie.MODEM_REBOOT";
7373

7474
public static String APP_VOLUME_PTT = "app_volume_ptt";
75-
public static String APP_FLASHLIGHT_PTT = "app_flashlight_ptt";
7675
public static String APP_KEEP_SCREEN_ON = "app_keep_screen_on";
7776
public static String APP_NO_LOCK = "app_no_lock";
7877
public static String APP_TURN_SCREEN_ON = "app_turn_screen_on";

codec2talkie/src/main/java/com/radio/codec2talkie/settings/SettingsWrapper.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
public class SettingsWrapper {
99

1010
public static boolean isSoundModemRigDisabled(SharedPreferences sharedPreferences) {
11-
return sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_RIG,
12-
RigCtlFactory.RIG_DISABLED).equals(RigCtlFactory.RIG_DISABLED);
11+
String rigTypeName = sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_RIG, RigCtlFactory.RIG_DISABLED);
12+
return rigTypeName.equals(RigCtlFactory.RIG_DISABLED) || rigTypeName.equals(RigCtlFactory.RIG_PHONE_TORCH);
1313
}
1414

1515
public static boolean isSoundModemEnabled(SharedPreferences sharedPreferences) {
@@ -108,8 +108,4 @@ public static boolean isTextPacketsEnabled(SharedPreferences sharedPreferences)
108108
public static boolean isAprsIsEnabled(SharedPreferences sharedPreferences) {
109109
return sharedPreferences.getBoolean(PreferenceKeys.APRS_IS_ENABLE, false);
110110
}
111-
112-
public static boolean isFlashLightPttEnabled(SharedPreferences sharedPreferences) {
113-
return sharedPreferences.getBoolean(PreferenceKeys.APP_FLASHLIGHT_PTT, false);
114-
}
115111
}

codec2talkie/src/main/res/values/arrays.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@
481481

482482
<string-array name="ports_sound_modem_rig_entries">
483483
<item>Do not use rig control</item>
484+
<item>Use phone torch</item>
484485
<item>FT-817/818/MCHF</item>
485486
<item>IC-7000</item>
486487
<item>IC-7100</item>
@@ -490,6 +491,7 @@
490491

491492
<string-array name="ports_sound_modem_rig_values">
492493
<item>Disabled</item>
494+
<item>PhoneTorch</item>
493495
<item>Ft817</item>
494496
<item>Ic7000</item>
495497
<item>Ic7100</item>

0 commit comments

Comments
 (0)