mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-02-26 02:43:34 +00:00
implement conversational awareness in tray app
This commit is contained in:
@@ -5,13 +5,14 @@ class NoiseCancellation:
|
||||
ADAPTIVE = b"\x04"
|
||||
|
||||
class ConversationAwareness:
|
||||
Off = b"\x02"
|
||||
On = b"\x01"
|
||||
OFF = b"\x02"
|
||||
ON = b"\x01"
|
||||
|
||||
class Capabilites:
|
||||
NOISE_CANCELLATION = b"\x0d"
|
||||
CONVERSATION_AWARENESS = b"\x28"
|
||||
CUSTOMIZABLE_ADAPTIVE_TRANSPARENCY = b"\x01\x02"
|
||||
EAR_DETECTION = b"\x06"
|
||||
|
||||
NoiseCancellation = NoiseCancellation
|
||||
ConversationAwareness = ConversationAwareness
|
||||
@@ -20,31 +20,6 @@ class ANCNotification:
|
||||
else:
|
||||
return False
|
||||
|
||||
def setANC(self, data: bytes):
|
||||
def setData(self, data: bytes):
|
||||
self.status = data[7]
|
||||
pass
|
||||
|
||||
def getANC(self, returnString: bool = False, fromInt: int = None):
|
||||
if fromInt is not None:
|
||||
fromInt = bytes([fromInt])
|
||||
if fromInt == self.OFF:
|
||||
return "Off"
|
||||
elif fromInt == self.ON:
|
||||
return "On"
|
||||
elif fromInt == self.TRANSPARENCY:
|
||||
return "Transparency"
|
||||
elif fromInt == self.ADAPTIVE:
|
||||
return "Adaptive"
|
||||
pass
|
||||
if returnString:
|
||||
return self.status
|
||||
else:
|
||||
if self.status == self.OFF:
|
||||
return "Off"
|
||||
elif self.status == self.ON:
|
||||
return "On"
|
||||
elif self.status == self.TRANSPARENCY:
|
||||
return "Transparency"
|
||||
elif self.status == self.ADAPTIVE:
|
||||
return "Adaptive"
|
||||
pass
|
||||
pass
|
||||
19
aln/Notifications/ConversationalAwareness.py
Normal file
19
aln/Notifications/ConversationalAwareness.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# 04 00 04 00 4b 00 02 00 01 [01/02/03/0b/09]
|
||||
|
||||
from ..enums import enums
|
||||
|
||||
class ConversationalAwarenessNotification:
|
||||
NOTIFICATION_PREFIX = enums.CONVERSATION_AWARENESS_RECEIVE_PREFIX
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def isConversationalAwarenessData(self, data: bytes):
|
||||
if len(data) != 10:
|
||||
return False
|
||||
if data.hex().startswith(self.NOTIFICATION_PREFIX.hex()):
|
||||
return True
|
||||
|
||||
def setData(self, data: bytes):
|
||||
self.status = data[9]
|
||||
pass
|
||||
@@ -4,7 +4,7 @@ from typing import Literal
|
||||
|
||||
class EarDetectionNotification:
|
||||
NOTIFICATION_BIT = Capabilites.EAR_DETECTION
|
||||
NOTIFICATION_PREFIX = enums.SEND_PREFIX + NOTIFICATION_BIT
|
||||
NOTIFICATION_PREFIX = enums.PREFIX + NOTIFICATION_BIT
|
||||
IN_EAR = 0x00
|
||||
OUT_OF_EAR = 0x01
|
||||
def __init__(self):
|
||||
|
||||
@@ -2,6 +2,7 @@ from bluetooth import BluetoothSocket
|
||||
import threading
|
||||
from .Battery import BatteryNotification
|
||||
from .EarDetection import EarDetectionNotification
|
||||
from .ConversationalAwareness import ConversationalAwarenessNotification
|
||||
from .ANC import ANCNotification
|
||||
import logging
|
||||
|
||||
@@ -11,6 +12,7 @@ class NotificationListener:
|
||||
BATTERY_UPDATED = 0x01
|
||||
ANC_UPDATED = 0x02
|
||||
EAR_DETECTION_UPDATED = 0x03
|
||||
CA_UPDATED = 0x04
|
||||
UNKNOWN = 0x00
|
||||
|
||||
def __init__(self, socket: BluetoothSocket, callback: callable):
|
||||
@@ -18,6 +20,7 @@ class NotificationListener:
|
||||
self.BatteryNotification = BatteryNotification()
|
||||
self.EarDetectionNotification = EarDetectionNotification()
|
||||
self.ANCNotification = ANCNotification()
|
||||
self.ConversationalAwarenessNotification = ConversationalAwarenessNotification()
|
||||
self.callback = callback
|
||||
pass
|
||||
|
||||
@@ -34,8 +37,11 @@ class NotificationListener:
|
||||
self.EarDetectionNotification.setEarDetection(data)
|
||||
self.callback(self.EAR_DETECTION_UPDATED, data)
|
||||
if self.ANCNotification.isANCData(data):
|
||||
self.ANCNotification.setANC(data)
|
||||
self.ANCNotification.setData(data)
|
||||
self.callback(self.ANC_UPDATED, data)
|
||||
if self.ConversationalAwarenessNotification.isConversationalAwarenessData(data):
|
||||
self.ConversationalAwarenessNotification.setData(data)
|
||||
self.callback(self.CA_UPDATED, data)
|
||||
else:
|
||||
self.callback(self.UNKNOWN, data)
|
||||
pass
|
||||
|
||||
@@ -10,6 +10,7 @@ enums = enums()
|
||||
class Notifications:
|
||||
BATTERY_UPDATED = NotificationListener.BATTERY_UPDATED
|
||||
ANC_UPDATED = NotificationListener.ANC_UPDATED
|
||||
CA_UPDATED = NotificationListener.CA_UPDATED
|
||||
EAR_DETECTION_UPDATED = NotificationListener.EAR_DETECTION_UPDATED
|
||||
UNKNOWN = NotificationListener.UNKNOWN
|
||||
def __init__(self, socket: bluetooth.BluetoothSocket, callback: callable):
|
||||
@@ -18,12 +19,13 @@ class Notifications:
|
||||
self.BatteryNotification = self.notificationListener.BatteryNotification
|
||||
self.EarDetectionNotification = self.notificationListener.EarDetectionNotification
|
||||
self.ANCNotification = self.notificationListener.ANCNotification
|
||||
self.ConversationalAwarenessNotification = self.notificationListener.ConversationalAwarenessNotification
|
||||
pass
|
||||
|
||||
def initialize(self):
|
||||
try:
|
||||
self.socket.send(enums.REQUEST_NOTIFICATIONS)
|
||||
self.socket.send(enums.SET_SPECIFIC_FEATURES)
|
||||
self.socket.send(enums.REQUEST_NOTIFICATIONS)
|
||||
self.notificationListener.start()
|
||||
|
||||
except bluetooth.btcommon.BluetoothError as e:
|
||||
|
||||
@@ -23,6 +23,8 @@ class Connection:
|
||||
self.notificationListener = self.notifications.notificationListener
|
||||
self.BatteryNotification = self.notifications.BatteryNotification
|
||||
self.ANCNotification = self.notifications.ANCNotification
|
||||
self.EarDetectionNotification = self.notifications.EarDetectionNotification
|
||||
self.ConversationalAwarenessNotification = self.notifications.ConversationalAwarenessNotification
|
||||
self.notifications.initialize()
|
||||
|
||||
def send(self, data: bytes):
|
||||
@@ -46,7 +48,11 @@ class Connection:
|
||||
pass
|
||||
elif notification_type == Notifications.ANC_UPDATED:
|
||||
logging = logging.getLogger("ANC Status")
|
||||
logging.debug(f'{self.notificationListener.ANCNotification.getANC()}')
|
||||
logging.debug(f'{self.notificationListener.ANCNotification.status}')
|
||||
pass
|
||||
elif notification_type == Notifications.CA_UPDATED:
|
||||
logging = logging.getLogger("Conversational Awareness Status")
|
||||
logging.debug(f'{self.notificationListener.ConversationalAwarenessNotification.status}')
|
||||
pass
|
||||
elif notification_type == Notifications.UNKNOWN:
|
||||
logging = logging.getLogger("Unknown Notification")
|
||||
|
||||
14
aln/enums.py
14
aln/enums.py
@@ -4,19 +4,21 @@ class enums:
|
||||
NOISE_CANCELLATION = Capabilites.NOISE_CANCELLATION
|
||||
CONVERSATION_AWARENESS = Capabilites.CONVERSATION_AWARENESS
|
||||
CUSTOMIZABLE_ADAPTIVE_TRANSPARENCY = Capabilites.CUSTOMIZABLE_ADAPTIVE_TRANSPARENCY
|
||||
SEND_PREFIX = b'\x04\x00\x04\x00'
|
||||
PREFIX = b'\x04\x00\x04\x00'
|
||||
SETTINGS = b"\x09\x00"
|
||||
SUFFIX = b'\x00\x00\x00'
|
||||
NOTIFICATION_FILTER = b'\x0f'
|
||||
SPECIFIC_FEATURES = b'\x4d'
|
||||
SET_SPECIFIC_FEATURES = SEND_PREFIX + SPECIFIC_FEATURES + b"\x00\xff\x00\x00\x00\x00\x00\x00\x00"
|
||||
REQUEST_NOTIFICATIONS = SEND_PREFIX + NOTIFICATION_FILTER + b"\x00\xff\xff\xff\xff"
|
||||
SET_SPECIFIC_FEATURES = PREFIX + SPECIFIC_FEATURES + b"\x00\xff\x00\x00\x00\x00\x00\x00\x00"
|
||||
REQUEST_NOTIFICATIONS = PREFIX + NOTIFICATION_FILTER + b"\x00\xff\xff\xff\xff"
|
||||
HANDSHAKE = b"\x00\x00\x04\x00\x01\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
NOISE_CANCELLATION_PREFIX = SEND_PREFIX + SETTINGS + NOISE_CANCELLATION
|
||||
NOISE_CANCELLATION_PREFIX = PREFIX + SETTINGS + NOISE_CANCELLATION
|
||||
NOISE_CANCELLATION_OFF = NOISE_CANCELLATION_PREFIX + Capabilites.NoiseCancellation.OFF + SUFFIX
|
||||
NOISE_CANCELLATION_ON = NOISE_CANCELLATION_PREFIX + Capabilites.NoiseCancellation.ON + SUFFIX
|
||||
NOISE_CANCELLATION_TRANSPARENCY = NOISE_CANCELLATION_PREFIX + Capabilites.NoiseCancellation.TRANSPARENCY + SUFFIX
|
||||
NOISE_CANCELLATION_ADAPTIVE = NOISE_CANCELLATION_PREFIX + Capabilites.NoiseCancellation.ADAPTIVE + SUFFIX
|
||||
|
||||
SET_CONVERSATION_AWARENESS_OFF = SEND_PREFIX + SETTINGS + CONVERSATION_AWARENESS + Capabilites.ConversationAwareness.Off + SUFFIX
|
||||
SET_CONVERSATION_AWARENESS_ON = SEND_PREFIX + SETTINGS + CONVERSATION_AWARENESS + Capabilites.ConversationAwareness.On + SUFFIX
|
||||
SET_CONVERSATION_AWARENESS_OFF = PREFIX + SETTINGS + CONVERSATION_AWARENESS + Capabilites.ConversationAwareness.OFF + SUFFIX
|
||||
SET_CONVERSATION_AWARENESS_ON = PREFIX + SETTINGS + CONVERSATION_AWARENESS + Capabilites.ConversationAwareness.ON + SUFFIX
|
||||
|
||||
CONVERSATION_AWARENESS_RECEIVE_PREFIX = PREFIX + b"\x4b\x00\x02\00"
|
||||
Reference in New Issue
Block a user