Skip to content

Commit f362f89

Browse files
committed
linux: add reset button for hearing aid adjustments
1 parent ba45eec commit f362f89

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

linux/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,26 @@ To use hearing aid features, you need to have an audiogram. To enable/disable he
7575
python3 hearing_aid.py
7676
```
7777

78-
The script will load the current settings from the AirPods and allow you to adjust them. You can set the audiogram by providing the values for 8 frequencies (250Hz, 500Hz, 1kHz, 2kHz, 3kHz, 4kHz, 6kHz, 8kHz) for both left and right ears. There are also options to adjust amplification, balance, tone, ambient noise reduction, own voice amplification, and conversation boost.
78+
The script will load the current settings from the AirPods and allow you to adjust them. You can set the audiogram by providing the values for 8 frequencies (250Hz, 500Hz, 1kHz, 2kHz, 3kHz, 4kHz, 6kHz, 8kHz) for both left and right ears. There are also options to adjust amplification, balance, tone, ambient noise reduction, own voice amplification, and conversation boost.
79+
80+
AirPods check for the DeviceID characteristic to see if the connected device is an Apple device and only then allow hearing aid features. To set the DeviceID characteristic, you need to add this line to your bluetooth configuration file (usually located at `/etc/bluetooth/main.conf`):
81+
82+
```
83+
DeviceID = bluetooth:004C:0000:0000
84+
```
85+
86+
Then, restart the bluetooth service:
87+
88+
```bash
89+
sudo systemctl restart bluetooth
90+
```
91+
92+
Here, you might need to re-pair your AirPods because they seem to cache this info.
93+
94+
### Troubleshooting
95+
96+
It is possible that the AirPods disconnect after a short period of time and play the disconnect sound. This is likely due to the AirPods expecting some information from an Apple device. Since I have not implemented everything that an Apple device does, the AirPods may disconnect. You don't need to reconnect them manually; the script will handle reconnection automatically for hearing aid features. So, once you are done setting the hearing aid features, change back the `DeviceID` to whatever it was before.
97+
98+
### Why a separate script?
99+
100+
Because I discovered that QBluetooth doesn't support connecting to a socket with its PSM, only a UUID can be used. I could add a dependency on BlueZ, but then having two bluetooth interfaces seems unnecessary. So, I decided to use a separate script for hearing aid features. In the future, QBluetooth will be replaced with BlueZ native calls, and then everything will be in one application.

linux/hearing-aid-adjustments.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,12 @@ def init_ui(self):
354354
self.own_voice_slider = QSlider(Qt.Horizontal)
355355
self.own_voice_slider.setRange(0, 100)
356356
self.own_voice_slider.setValue(50)
357-
layout.addWidget(QLabel("Own Voice Amplification"))
357+
# layout.addWidget(QLabel("Own Voice Amplification"))
358358
# layout.addWidget(self.own_voice_slider) # seems to have no effect
359359

360+
# Reset button
361+
self.reset_button = QPushButton("Reset")
362+
layout.addWidget(self.reset_button)
360363

361364
# Connect signals
362365
for input_box in self.left_eq_inputs + self.right_eq_inputs:
@@ -367,6 +370,7 @@ def init_ui(self):
367370
self.anr_slider.valueChanged.connect(self.on_value_changed)
368371
self.conv_checkbox.stateChanged.connect(self.on_value_changed)
369372
self.own_voice_slider.valueChanged.connect(self.on_value_changed)
373+
self.reset_button.clicked.connect(self.reset_settings)
370374

371375
self.setLayout(layout)
372376
logging.debug("UI initialized")
@@ -435,6 +439,16 @@ def send_settings(self):
435439
)
436440
threading.Thread(target=send_hearing_aid_settings, args=(self.att_manager, settings)).start()
437441

442+
def reset_settings(self):
443+
logging.debug("Resetting settings to defaults")
444+
self.amp_slider.setValue(0)
445+
self.balance_slider.setValue(0)
446+
self.tone_slider.setValue(0)
447+
self.anr_slider.setValue(50)
448+
self.conv_checkbox.setChecked(False)
449+
self.own_voice_slider.setValue(50)
450+
self.on_value_changed()
451+
438452
def closeEvent(self, event):
439453
logging.info("Closing app")
440454
self.att_manager.disconnect()

0 commit comments

Comments
 (0)