remake everything, now with serial
This commit is contained in:
parent
3faeb5d6aa
commit
a7b14fe39d
52
__main__.py
52
__main__.py
@ -6,23 +6,56 @@ except:
|
||||
print("DEBUG; winrt disabled")
|
||||
DEBUG = True
|
||||
import win32com.client
|
||||
import pythoncom
|
||||
import time
|
||||
import pythoncom
|
||||
|
||||
from resources import LineState, CLMgrMessage
|
||||
|
||||
phone_mgr = ""
|
||||
lines = []
|
||||
import serial
|
||||
from serial import SerialException
|
||||
|
||||
portName = 'COM3'
|
||||
|
||||
def sendSerial(byte):
|
||||
try:
|
||||
ser = serial.Serial(port=portName, baudrate=115200)
|
||||
ser.write(byte)
|
||||
except SerialException:
|
||||
print('port already open')
|
||||
|
||||
class PhoneLineEventHandler():
|
||||
phone_mgr = None
|
||||
lines = []
|
||||
line_selected = None
|
||||
connected = False
|
||||
|
||||
def OnDispOnLineMgrNotification(self, msg, param, returns=""):
|
||||
if msg == 0:
|
||||
print(CLMgrMessage.s[msg], LineState.s[param])
|
||||
for line in lines:
|
||||
|
||||
if not self.phone_mgr:
|
||||
self.phone_mgr = win32com.client.Dispatch("CLMgr.ClientLineMgr")
|
||||
if not self.phone_mgr:
|
||||
"Swyx not connected!"
|
||||
else:
|
||||
print("Swyx connected!")
|
||||
if self.phone_mgr:
|
||||
if msg == CLMgrMessage.CLMgrLineStateChangedMessage:
|
||||
line = self.phone_mgr.DispGetLine(param)
|
||||
print("Line: {} {}".format(
|
||||
param,
|
||||
LineState.s[line.DispState])
|
||||
)
|
||||
if line.DispState != LineState.Inactive:
|
||||
if line.DispState == LineState.Ringing:
|
||||
sendSerial(b'y')
|
||||
else:
|
||||
sendSerial(b'r')
|
||||
asyncio.run(try_pause())
|
||||
for linenum in range(self.phone_mgr.DispNumberOfLines):
|
||||
line = self.phone_mgr.DispGetLine(linenum)
|
||||
if line.DispState != LineState.Inactive:
|
||||
return True
|
||||
asyncio.run(try_play())
|
||||
sendSerial(b'o')
|
||||
return True
|
||||
|
||||
# async def get_media_info():
|
||||
@ -70,10 +103,7 @@ async def try_pause():
|
||||
await current_session.try_pause_async()
|
||||
|
||||
if __name__ == '__main__':
|
||||
phone_mgr = win32com.client.Dispatch("CLMgr.ClientLineMgr")
|
||||
phone_mgr_event = win32com.client.WithEvents("CLMgr.ClientLineMgr", PhoneLineEventHandler)
|
||||
for i in range(3):
|
||||
lines.append(phone_mgr.DispGetLine(i))
|
||||
win32com.client.WithEvents("CLMgr.ClientLineMgr", PhoneLineEventHandler)
|
||||
while True:
|
||||
#pythoncom.PumpWaitingMessages()
|
||||
pythoncom.PumpWaitingMessages()
|
||||
time.sleep(0.1) # Don't use up all our CPU checking constantly
|
Loading…
x
Reference in New Issue
Block a user