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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user