Skip to content

Commit

Permalink
pro3: add voice eq preset; pro: initial profile
Browse files Browse the repository at this point in the history
  • Loading branch information
melianmiko committed Jan 20, 2024
1 parent f466c45 commit 3d574f5
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 22 deletions.
45 changes: 37 additions & 8 deletions src/openfreebuds/device/huawei/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from openfreebuds.device.huawei.spp_handlers.anc_change import AncChangeDetectionHandler
from openfreebuds.device.huawei.spp_handlers.anc_control import AncSettingHandler
from openfreebuds.device.huawei.spp_handlers.battery import BatteryHandler
from openfreebuds.device.huawei.spp_handlers.config_equalizer import EqualizerConfigHandler
from openfreebuds.device.huawei.spp_handlers.config_equalizer import BuiltInEqualizerHandler
from openfreebuds.device.huawei.spp_handlers.config_sound_quality import ConfigSoundQualityHandler
from openfreebuds.device.huawei.spp_handlers.device_info import DeviceInfoHandler
from openfreebuds.device.huawei.spp_handlers.drop import DropLogsHandler
Expand All @@ -11,6 +11,7 @@
from openfreebuds.device.huawei.spp_handlers.gesture_long_separate import SplitLongTapActionConfigHandler
from openfreebuds.device.huawei.spp_handlers.gesture_power import PowerButtonConfigHandler
from openfreebuds.device.huawei.spp_handlers.gesture_swipe import SwipeActionHandler
from openfreebuds.device.huawei.spp_handlers.multi_device_toggle import MultiDeviceToggleHandler
from openfreebuds.device.huawei.spp_handlers.tws_auto_pause import TwsAutoPauseHandler
from openfreebuds.device.huawei.spp_handlers.tws_in_ear import TwsInEarHandler
from openfreebuds.device.huawei.spp_handlers.voice_language import VoiceLanguageHandler
Expand Down Expand Up @@ -54,6 +55,23 @@ def __init__(self, address):
]


class FreeBudsProDevice(GenericHuaweiSppDevice):
def __init__(self, address):
super().__init__(address)
self.handlers = [
DeviceInfoHandler(),
TwsInEarHandler(),
BatteryHandler(),
AncSettingHandler(w_cancel_lvl=True, w_cancel_dynamic=True, w_voice_boost=True),
# not tested, no information
SwipeActionHandler(),
TwsInEarHandler(),
DoubleTapConfigHandler(),
SplitLongTapActionConfigHandler(w_right=True),
VoiceLanguageHandler(),
]


class FreeBuds5iDevice(GenericHuaweiSppDevice):
"""
HUAWEI FreeBuds 5i
Expand All @@ -64,14 +82,19 @@ def __init__(self, address):
# DropLogsHandler(),
DeviceInfoHandler(),
TwsInEarHandler(),
AncSettingHandler(w_cancel_lvl=True),
BatteryHandler(),
AncSettingHandler(w_cancel_lvl=True),
DoubleTapConfigHandler(),
SplitLongTapActionConfigHandler(with_right=True),
SplitLongTapActionConfigHandler(w_right=True),
SwipeActionHandler(),
TwsAutoPauseHandler(),
ConfigSoundQualityHandler(),
EqualizerConfigHandler(),
BuiltInEqualizerHandler(w_presets={
1: "default",
2: "hardbass",
3: "treble",
}),
MultiDeviceToggleHandler(),
VoiceLanguageHandler(),
]

Expand All @@ -86,16 +109,22 @@ def __init__(self, address):
self.handlers = [
# May work
DeviceInfoHandler(),
TwsInEarHandler(),
AncSettingHandler(w_cancel_lvl=True, w_cancel_dynamic=True, w_voice_boost=True),
BatteryHandler(),
ConfigSoundQualityHandler(),
EqualizerConfigHandler(),
# Not tested, no research data
BuiltInEqualizerHandler(w_presets={
5: "default",
1: "hardbass",
2: "treble",
9: "voice",
}),
TwsAutoPauseHandler(),
MultiDeviceToggleHandler(),
# Not tested, no research data
TwsInEarHandler(),
VoiceLanguageHandler(),
DoubleTapConfigHandler(),
SplitLongTapActionConfigHandler(with_right=True),
SplitLongTapActionConfigHandler(w_right=True),
SwipeActionHandler(),
]

Expand Down
19 changes: 9 additions & 10 deletions src/openfreebuds/device/huawei/spp_handlers/config_equalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
from openfreebuds.device.huawei.generic.spp_package import HuaweiSppPackage
from openfreebuds.device.huawei.tools import reverse_dict

KNOWN_OPTIONS = {
1: "equalizer_preset_default",
2: "equalizer_preset_hardbass",
3: "equalizer_preset_treble",
}


class EqualizerConfigHandler(HuaweiSppHandler):
class BuiltInEqualizerHandler(HuaweiSppHandler):
"""
Built-in equalizer settings handler (5i)
"""
Expand All @@ -24,13 +18,18 @@ class EqualizerConfigHandler(HuaweiSppHandler):
("config", "equalizer_preset")
)

def __init__(self, w_presets=None):
self.w_presets = w_presets or {}
for i in self.w_presets:
self.w_presets[i] = "equalizer_preset_" + self.w_presets[i]

def on_init(self):
self.device.send_package(HuaweiSppPackage(b"\x2b\x49", [
(2, b""),
]))

def on_prop_changed(self, group: str, prop: str, value):
value = reverse_dict(KNOWN_OPTIONS)[value]
value = reverse_dict(self.w_presets)[value]
pkg = HuaweiSppPackage(b"\x2b\x49", [
(1, value),
])
Expand All @@ -44,6 +43,6 @@ def on_package(self, package: HuaweiSppPackage):
if len(value) == 1:
value = int.from_bytes(value, byteorder="big", signed=True)
self.device.put_property("config", "equalizer_preset",
KNOWN_OPTIONS[value])
self.w_presets[value])
self.device.put_property("config", "equalizer_preset_options",
",".join(KNOWN_OPTIONS.keys()))
",".join(self.w_presets.keys()))
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class SplitLongTapActionConfigHandler(HuaweiSppHandler):
("action", "noise_control_right"),
]

def __init__(self, with_right=False):
self.with_right = with_right
def __init__(self, w_right=False):
self.w_right = w_right

def on_init(self):
self.device.send_package(HuaweiSppPackage(b"\x2b\x17", [
Expand Down Expand Up @@ -82,7 +82,7 @@ def on_package(self, package: HuaweiSppPackage):
value = int.from_bytes(left, byteorder="big", signed=True)
self.device.put_property("action", "long_tap_left",
KNOWN_LONG_TAP_OPTIONS.get(value, value))
if len(right) == 1 and self.with_right:
if len(right) == 1 and self.w_right:
value = int.from_bytes(right, byteorder="big", signed=True)
self.device.put_property("action", "long_tap_right",
KNOWN_LONG_TAP_OPTIONS.get(value, value))
Expand All @@ -99,7 +99,7 @@ def on_package(self, package: HuaweiSppPackage):
value = int.from_bytes(left, byteorder="big", signed=True)
self.device.put_property("action", "noise_control_left",
KNOWN_ANC_OPTIONS.get(value, value))
if len(right) == 1 and self.with_right:
if len(right) == 1 and self.w_right:
value = int.from_bytes(right, byteorder="big", signed=True)
self.device.put_property("action", "noise_control_right",
KNOWN_ANC_OPTIONS.get(value, value))
Expand Down
37 changes: 37 additions & 0 deletions src/openfreebuds/device/huawei/spp_handlers/multi_device_toggle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from openfreebuds.device.huawei.generic.spp_handler import HuaweiSppHandler
from openfreebuds.device.huawei.generic.spp_package import HuaweiSppPackage


class MultiDeviceToggleHandler(HuaweiSppHandler):
"""
Enable/disable multi-device support (pro 3, maybe 5i)
"""
handler_id = "multi_device_toggle"
handle_commands = (
b"\x2b\x2f"
)
ignore_commands = (
b"\x2b\x2e",
)
handle_props = (
("multi_device", "enabled"),
)

def on_init(self):
self.device.send_package(HuaweiSppPackage(b"\x2b\x2f", [
(1, b""),
]))

def on_prop_changed(self, group: str, prop: str, value):
pkg = HuaweiSppPackage(b"\x2b\x2e", [
(1, 1 if value else 0),
])
self.device.send_package(pkg)
self.on_init()

def on_package(self, package: HuaweiSppPackage):
value = package.find_param(1)

if len(value) == 1:
value = int(value[0])
self.device.put_property("multi_device", "enabled", value)
1 change: 1 addition & 0 deletions src/openfreebuds_assets/locale/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"equalizer_preset_default": "Default",
"equalizer_preset_hardbass": "Bass-boost",
"equalizer_preset_treble": "Treble-boost",
"equalizer_preset_voice": "Voice",
"theme_auto": "Auto-detect",
"theme_dark": "Dark",
"theme_light": "Light",
Expand Down
5 changes: 5 additions & 0 deletions src/openfreebuds_assets/locale/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
"sound_quality_preference": "Предпочтения по звуку",
"sqp_quality": "Качество",
"sqp_connectivity": "Общение",
"equalizer_preset": "Эквалайзер",
"equalizer_preset_default": "По умолчанию",
"equalizer_preset_hardbass": "Усиление нижних частот",
"equalizer_preset_treble": "Усиление верхних частот",
"equalizer_preset_voice": "Голоса",
"theme_auto": "Выбирать автоматически",
"theme_dark": "Тёмный",
"theme_light": "Светлый",
Expand Down

0 comments on commit 3d574f5

Please sign in to comment.