Skip to content

Instantly share code, notes, and snippets.

@tumugin
Created July 5, 2026 19:35
Show Gist options
  • Select an option

  • Save tumugin/5e4a67e399d4efff9329005cb825cc39 to your computer and use it in GitHub Desktop.

Select an option

Save tumugin/5e4a67e399d4efff9329005cb825cc39 to your computer and use it in GitHub Desktop.
Controll ANC mode of MOONDDROP Golden Ages 2 with PyQt6
import sys
from PyQt6.QtCore import QCoreApplication, QByteArray, QTimer, QIODeviceBase
from PyQt6.QtBluetooth import (
QBluetoothAddress,
QBluetoothSocket,
QBluetoothServiceInfo,
QBluetoothUuid
)
ADDR = "xx:xx:xx:xx:xx:xx"
SERVICE_UUID = "00001101-0000-1000-8000-00805f9b34fb"
# 外音取り込み
# PAYLOAD = bytearray([0xff, 0x04, 0x00, 0x01, 0x00, 0x1d, 0x10, 0x04, 0x04])
# ANC(基本ノイズ低減)
PAYLOAD = bytearray([0xff, 0x04, 0x00, 0x01, 0x00, 0x1d, 0x10, 0x04, 0x02])
# ANC(ウィンドノイズ低減)
# PAYLOAD = bytearray([0xff, 0x04, 0x00, 0x01, 0x00, 0x1d, 0x10, 0x04, 0x03])
# OFF
# PAYLOAD = bytearray([0xff, 0x04, 0x00, 0x01, 0x00, 0x1d, 0x10, 0x04, 0x01])
class Client:
def __init__(self):
self.socket = QBluetoothSocket(QBluetoothServiceInfo.Protocol.RfcommProtocol)
self.socket.connected.connect(self.on_connected)
self.socket.readyRead.connect(self.on_ready_read)
self.socket.disconnected.connect(self.on_disconnected)
self.socket.errorOccurred.connect(self.on_error)
def start(self):
self.socket.connectToService(
QBluetoothAddress(ADDR),
QBluetoothUuid(SERVICE_UUID),
QIODeviceBase.OpenModeFlag.ReadWrite,
)
def on_connected(self):
print("connected")
self.socket.write(QByteArray(PAYLOAD))
QTimer.singleShot(1000, self.socket.disconnectFromService)
def on_ready_read(self):
data = bytes(self.socket.readAll())
if data:
print("recv:", data.hex(" "))
def on_disconnected(self):
print("disconnected")
QCoreApplication.quit()
def on_error(self, error):
print("error:", error, self.socket.errorString())
QCoreApplication.quit()
if __name__ == "__main__":
app = QCoreApplication(sys.argv)
client = Client()
client.start()
sys.exit(app.exec())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment