Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum KarooAction {
VIRTUAL_ENABLE_AUDIO_ALERTS,
VIRTUAL_SINGLE_BEEP,
VIRTUAL_DOUBLE_BEEP,
VIRTUAL_BELL,
VIRTUAL_BELL_OLD,
VIRTUAL_BELL_NEW,
VIRTUAL_LAP,
VIRTUAL_ZOOM_OUT,
VIRTUAL_ZOOM_IN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import android.os.Bundle;

public class AudioAlertMessage extends Message {
private static final String KEY_NAME = "name";
public static final String KEY = "audio-alert";
private static final String KEY_NAME = "name";
private static final String KEY_ADJUST_INTENSITY = "adjust-intensity";

public static AudioAlertMessage parse(Message message) {
if (!message.getClassType().equals(AudioAlertMessage.class.getName())) {
Expand All @@ -15,21 +16,32 @@ public static AudioAlertMessage parse(Message message) {
}

private final String name;
private final boolean adjustIntensity;

private AudioAlertMessage(Message message) {
super(message);
name = getBundle().getString(KEY_NAME);
adjustIntensity = getBundle().getBoolean(KEY_ADJUST_INTENSITY);
}

public AudioAlertMessage(String name) {
public AudioAlertMessage(String name, boolean adjustIntensity) {
super(KEY, new Bundle(), MessageType.AUDIO_ALERT, false);

getBundle().putString(KEY_NAME, name);
getBundle().putBoolean(KEY_ADJUST_INTENSITY, adjustIntensity);
this.name = name;
this.adjustIntensity = adjustIntensity;
}

public AudioAlertMessage(String name) {
this(name, true);
}

public String getName() {
return name;
}

public boolean getAdjustIntensity() {
return adjustIntensity;
}
}
7 changes: 4 additions & 3 deletions app/src/main/java/com/valterc/ki2/input/ActionAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public ActionAdapter(Ki2ExtensionContext context) {
this.keyMapping.put(KarooAction.VIRTUAL_TOGGLE_AUDIO_ALERTS, karooKeyEvent -> toggleAudioAlerts(context));
this.keyMapping.put(KarooAction.VIRTUAL_DISABLE_AUDIO_ALERTS, karooKeyEvent -> disableAudioAlerts(context));
this.keyMapping.put(KarooAction.VIRTUAL_ENABLE_AUDIO_ALERTS, karooKeyEvent -> enableAudioAlerts(context));
this.keyMapping.put(KarooAction.VIRTUAL_SINGLE_BEEP, karooKeyEvent -> context.getAudioManager().playSingleBeep());
this.keyMapping.put(KarooAction.VIRTUAL_DOUBLE_BEEP, karooKeyEvent -> context.getAudioManager().playDoubleBeep());
this.keyMapping.put(KarooAction.VIRTUAL_BELL, karooKeyEvent -> context.getAudioManager().playKarooBell());
this.keyMapping.put(KarooAction.VIRTUAL_SINGLE_BEEP, karooKeyEvent -> context.getAudioManager().playSingleBeep(false));
this.keyMapping.put(KarooAction.VIRTUAL_DOUBLE_BEEP, karooKeyEvent -> context.getAudioManager().playDoubleBeep(false));
this.keyMapping.put(KarooAction.VIRTUAL_BELL_OLD, karooKeyEvent -> context.getAudioManager().playKarooBellOld(false));
this.keyMapping.put(KarooAction.VIRTUAL_BELL_NEW, karooKeyEvent -> context.getAudioManager().playKarooBellNew(false));
this.keyMapping.put(KarooAction.VIRTUAL_LAP, karooKeyEvent -> context.getKarooSystem().dispatch(MarkLap.INSTANCE));
this.keyMapping.put(KarooAction.VIRTUAL_ZOOM_IN, karooKeyEvent -> context.getKarooSystem().dispatch(new ZoomPage(true)));
this.keyMapping.put(KarooAction.VIRTUAL_ZOOM_OUT, karooKeyEvent -> context.getKarooSystem().dispatch(new ZoomPage(false)));
Expand Down
23 changes: 18 additions & 5 deletions app/src/main/java/com/valterc/ki2/input/InputManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class InputManager {
preferenceToSwitchKeyMap.put("press_enable_audio_alerts", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_ENABLE_AUDIO_ALERTS, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_single_beep", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_SINGLE_BEEP, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_double_beep", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_DOUBLE_BEEP, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_bell", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_BELL, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_bell_old", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_BELL_OLD, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_bell_new", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_BELL_NEW, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_control_center", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_CONTROL_CENTER, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_drawer_action", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_DRAWER_ACTION, switchEvent.getRepeat()));
preferenceToSwitchKeyMap.put("press_toggle_overlay", (switchEvent, converter) -> new KarooActionEvent(KarooAction.VIRTUAL_TOGGLE_OVERLAY, switchEvent.getRepeat()));
Expand Down Expand Up @@ -200,17 +201,29 @@ public class InputManager {
}
return new KarooActionEvent(KarooAction.VIRTUAL_SINGLE_BEEP, switchEvent.getRepeat());
});
preferenceToSwitchKeyMap.put("hold_short_single_bell", (switchEvent, converter) -> {
preferenceToSwitchKeyMap.put("hold_short_single_bell_old", (switchEvent, converter) -> {
if (switchEvent.getCommand() != SwitchCommand.LONG_PRESS_DOWN) {
return null;
}
return new KarooActionEvent(KarooAction.VIRTUAL_BELL, switchEvent.getRepeat());
return new KarooActionEvent(KarooAction.VIRTUAL_BELL_OLD, switchEvent.getRepeat());
});
preferenceToSwitchKeyMap.put("hold_continuous_bell", (switchEvent, converter) -> {
preferenceToSwitchKeyMap.put("hold_short_single_bell_new", (switchEvent, converter) -> {
if (switchEvent.getCommand() != SwitchCommand.LONG_PRESS_DOWN) {
return null;
}
return new KarooActionEvent(KarooAction.VIRTUAL_BELL_NEW, switchEvent.getRepeat());
});
preferenceToSwitchKeyMap.put("hold_continuous_bell_old", (switchEvent, converter) -> {
if (switchEvent.getCommand() == SwitchCommand.LONG_PRESS_UP) {
return null;
}
return new KarooActionEvent(KarooAction.VIRTUAL_BELL_OLD, switchEvent.getRepeat());
});
preferenceToSwitchKeyMap.put("hold_continuous_bell_new", (switchEvent, converter) -> {
if (switchEvent.getCommand() == SwitchCommand.LONG_PRESS_UP) {
return null;
}
return new KarooActionEvent(KarooAction.VIRTUAL_BELL, switchEvent.getRepeat());
return new KarooActionEvent(KarooAction.VIRTUAL_BELL_NEW, switchEvent.getRepeat());
});
preferenceToSwitchKeyMap.put("hold_short_single_toggle_overlay", (switchEvent, converter) -> {
if (switchEvent.getCommand() != SwitchCommand.LONG_PRESS_DOWN) {
Expand Down
165 changes: 123 additions & 42 deletions app/src/main/java/com/valterc/ki2/karoo/audio/AudioManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AudioManager(private val context: Ki2ExtensionContext) {
private var intensity: AudioIntensity = AudioIntensity.Normal

private val playAudioConsumer = Consumer<AudioAlertMessage> {
playAudio(it.name)
playAudio(it.name, it.adjustIntensity)
}

private val preferencesConsumer = Consumer<PreferencesView> { preferences ->
Expand All @@ -40,12 +40,13 @@ class AudioManager(private val context: Ki2ExtensionContext) {
context.serviceClient.registerPreferencesWeakListener(preferencesConsumer)
}

private fun playAudio(audio: String?) {
private fun playAudio(audio: String?, adjustIntensity: Boolean = true) {
when (audio) {
"karoo_generic" -> playKarooGeneric()
"karoo_bell" -> playKarooBell()
"custom_single_beep" -> playSingleBeep()
"custom_double_beep" -> playDoubleBeep()
"karoo_generic" -> playKarooGeneric(adjustIntensity)
"karoo_bell_old" -> playKarooBellOld(adjustIntensity)
"karoo_bell_new" -> playKarooBellNew(adjustIntensity)
"custom_single_beep" -> playSingleBeep(adjustIntensity)
"custom_double_beep" -> playDoubleBeep(adjustIntensity)
"disabled" -> return
else -> Timber.i("Unknown audio requested '%s'", audio)
}
Expand All @@ -63,56 +64,136 @@ class AudioManager(private val context: Ki2ExtensionContext) {
else -> max(times(intensity.durationMultiplierK24).toInt(), 50)
}

fun playSingleBeep() {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000.f, 350.d)
fun playSingleBeep(adjustIntensity: Boolean = true) {
if (adjustIntensity){
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000.f, 350.d)
)
)
)
)
} else {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000, 350)
)
)
)
}
}

fun playDoubleBeep() {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000.f, 350.d),
PlayBeepPattern.Tone(null, 150.d),
PlayBeepPattern.Tone(5000.f, 350.d)
fun playDoubleBeep(adjustIntensity: Boolean = true) {
if (adjustIntensity) {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000.f, 350.d),
PlayBeepPattern.Tone(null, 150.d),
PlayBeepPattern.Tone(5000.f, 350.d)
)
)
)
)
} else {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000, 350),
PlayBeepPattern.Tone(null, 150),
PlayBeepPattern.Tone(5000, 350)
)
)
)
}
}

private fun playKarooGeneric() {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000.f, 350.d),
PlayBeepPattern.Tone(null, 100.d),
PlayBeepPattern.Tone(4250.f, 100.d),
PlayBeepPattern.Tone(null, 50.d),
PlayBeepPattern.Tone(4250.f, 100.d),
PlayBeepPattern.Tone(null, 50.d),
PlayBeepPattern.Tone(4250.f, 100.d)
private fun playKarooGeneric(adjustIntensity: Boolean = true) {
if (adjustIntensity) {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000.f, 350.d),
PlayBeepPattern.Tone(null, 100.d),
PlayBeepPattern.Tone(4250.f, 100.d),
PlayBeepPattern.Tone(null, 50.d),
PlayBeepPattern.Tone(4250.f, 100.d),
PlayBeepPattern.Tone(null, 50.d),
PlayBeepPattern.Tone(4250.f, 100.d)
)
)
)
)
} else {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(5000, 350),
PlayBeepPattern.Tone(null, 100),
PlayBeepPattern.Tone(4250, 100),
PlayBeepPattern.Tone(null, 50),
PlayBeepPattern.Tone(4250, 100),
PlayBeepPattern.Tone(null, 50),
PlayBeepPattern.Tone(4250, 100)
)
)
)
}
}

fun playKarooBell() {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(3750.f, 50.d),
PlayBeepPattern.Tone(5800.f, 200.d),
PlayBeepPattern.Tone(null, 50.d),
PlayBeepPattern.Tone(3750.f, 50.d),
PlayBeepPattern.Tone(5800.f, 300.d)
fun playKarooBellOld(adjustIntensity: Boolean = true) {
if (adjustIntensity){
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(3750.f, 50.d),
PlayBeepPattern.Tone(5800.f, 200.d),
PlayBeepPattern.Tone(null, 50.d),
PlayBeepPattern.Tone(3750.f, 50.d),
PlayBeepPattern.Tone(5800.f, 300.d)
)
)
)
)
} else {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(3750, 50),
PlayBeepPattern.Tone(5800, 200),
PlayBeepPattern.Tone(null, 50),
PlayBeepPattern.Tone(3750, 50),
PlayBeepPattern.Tone(5800, 300)
)
)
)
}
}

fun playKarooBellNew(adjustIntensity: Boolean = true) {
if (adjustIntensity){
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(2349.f, 31.d),
PlayBeepPattern.Tone(3520.f, 125.d),
PlayBeepPattern.Tone(null, 31.d),
PlayBeepPattern.Tone(2349.f, 31.d),
PlayBeepPattern.Tone(3520.f, 406.d)
)
)
)
} else {
context.karooSystem.dispatch(
PlayBeepPattern(
listOf(
PlayBeepPattern.Tone(2349, 31),
PlayBeepPattern.Tone(3520, 125),
PlayBeepPattern.Tone(null, 31),
PlayBeepPattern.Tone(2349, 31),
PlayBeepPattern.Tone(3520, 406)
)
)
)
}
}

fun playKarooDeviceWarning() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.valterc.ki2.update.post.actions.IPostUpdateAction;
import com.valterc.ki2.update.post.actions.IPreInitPostUpdateAction;
import com.valterc.ki2.update.post.actions.KarooAudioAlertsUpdateAction;
import com.valterc.ki2.update.post.actions.KarooBellUpdateAction;
import com.valterc.ki2.update.post.actions.ShowOverlayUpdateAction;

import java.util.HashMap;
Expand All @@ -26,6 +27,7 @@ private PostUpdateActions() {
preInitActionMap = new HashMap<>();
preInitActionMap.put(KarooAudioAlertsUpdateAction.class.getSimpleName(), new KarooAudioAlertsUpdateAction());
preInitActionMap.put(ShowOverlayUpdateAction.class.getSimpleName(), new ShowOverlayUpdateAction());
preInitActionMap.put(KarooBellUpdateAction.class.getSimpleName(), new KarooBellUpdateAction());
postInitActionMap = new HashMap<>();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.valterc.ki2.update.post.actions

import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.valterc.ki2.R
import com.valterc.ki2.update.post.PostUpdateContext

class KarooBellUpdateAction : IPreInitPostUpdateAction {
override fun execute(context: PostUpdateContext) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context.context)

val preferencesWithPossibleBellValue = listOf(
context.context.getString(R.string.preference_audio_alert_lowest_gear),
context.context.getString(R.string.preference_audio_alert_highest_gear),
context.context.getString(R.string.preference_audio_alert_shifting_limit),
context.context.getString(R.string.preference_audio_alert_upcoming_synchro_shift),
context.context.getString(R.string.preference_switch_ch1_single_press),
context.context.getString(R.string.preference_switch_ch1_double_press),
context.context.getString(R.string.preference_switch_ch1_hold),
context.context.getString(R.string.preference_switch_ch2_single_press),
context.context.getString(R.string.preference_switch_ch2_double_press),
context.context.getString(R.string.preference_switch_ch2_hold),
context.context.getString(R.string.preference_switch_ch3_single_press),
context.context.getString(R.string.preference_switch_ch3_double_press),
context.context.getString(R.string.preference_switch_ch3_hold),
context.context.getString(R.string.preference_switch_ch4_single_press),
context.context.getString(R.string.preference_switch_ch4_double_press),
context.context.getString(R.string.preference_switch_ch4_hold),
)

for (preferenceKey in preferencesWithPossibleBellValue) {
val preferenceValue = preferences.getString(preferenceKey, null)

when (preferenceValue) {
"press_bell" -> preferences.edit {
putString(preferenceKey, "press_bell_old")
}
"hold_short_single_bell" -> preferences.edit {
putString(preferenceKey, "hold_short_single_bell_old")
}
"hold_continuous_bell" -> preferences.edit {
putString(preferenceKey, "hold_continuous_bell_old")
}
"karoo_bell" -> preferences.edit {
putString(preferenceKey, "karoo_bell_old")
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setValue(String value) {

try {
if (service != null) {
service.sendMessage(new AudioAlertMessage(value));
service.sendMessage(new AudioAlertMessage(value, true));
}
} catch (Exception e) {
Timber.w(e, "Unable to send message");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setValue(String value) {

try {
if (service != null) {
service.sendMessage(new AudioAlertMessage("custom_single_beep"));
service.sendMessage(new AudioAlertMessage("custom_single_beep", true));
}
} catch (Exception e) {
Timber.w(e, "Unable to send message");
Expand Down
Loading