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") |     print("DEBUG; winrt disabled") | ||||||
|     DEBUG = True |     DEBUG = True | ||||||
| import win32com.client | import win32com.client | ||||||
| import pythoncom |  | ||||||
| import time | import time | ||||||
|  | import pythoncom | ||||||
| 
 | 
 | ||||||
| from resources import LineState, CLMgrMessage | from resources import LineState, CLMgrMessage | ||||||
| 
 | 
 | ||||||
| phone_mgr = "" | import serial | ||||||
| lines = [] | 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():  | class PhoneLineEventHandler():  | ||||||
|  |     phone_mgr = None | ||||||
|  |     lines = [] | ||||||
|  |     line_selected = None | ||||||
|  |     connected = False | ||||||
| 
 | 
 | ||||||
|     def OnDispOnLineMgrNotification(self, msg, param, returns=""): |     def OnDispOnLineMgrNotification(self, msg, param, returns=""): | ||||||
|         if msg == 0: | 
 | ||||||
|             print(CLMgrMessage.s[msg], LineState.s[param]) |         if not self.phone_mgr: | ||||||
|             for line in lines: |             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.Inactive: | ||||||
|  |                     if line.DispState == LineState.Ringing: | ||||||
|  |                         sendSerial(b'y') | ||||||
|  |                     else: | ||||||
|  |                         sendSerial(b'r') | ||||||
|                     asyncio.run(try_pause()) |                     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 |                     return True | ||||||
|             asyncio.run(try_play()) |             asyncio.run(try_play()) | ||||||
|  |                 sendSerial(b'o') | ||||||
|         return True |         return True | ||||||
| 
 | 
 | ||||||
| # async def get_media_info(): | # async def get_media_info(): | ||||||
| @ -70,10 +103,7 @@ async def try_pause(): | |||||||
|         await current_session.try_pause_async() |         await current_session.try_pause_async() | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     phone_mgr =  win32com.client.Dispatch("CLMgr.ClientLineMgr") |     win32com.client.WithEvents("CLMgr.ClientLineMgr", PhoneLineEventHandler) | ||||||
|     phone_mgr_event = win32com.client.WithEvents("CLMgr.ClientLineMgr", PhoneLineEventHandler) |  | ||||||
|     for i in range(3): |  | ||||||
|         lines.append(phone_mgr.DispGetLine(i)) |  | ||||||
|     while True: |     while True: | ||||||
|         #pythoncom.PumpWaitingMessages() |         pythoncom.PumpWaitingMessages() | ||||||
|         time.sleep(0.1) # Don't use up all our CPU checking constantly |         time.sleep(0.1) # Don't use up all our CPU checking constantly | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user