I have created a new universal multiprotocol USB IR receiver:
http://www.mikrocontroller.net/articles ... e_Receiver
The topic is in german but the download includes an english description.
Now I'm trying to write my first EventGhost plugin:
Code: Select all
"""<rst>
EventGhost Plugin for the `USB IR Remote Receiver`__.
__ http://www.mikrocontroller.net/articles/USB_IR_Remote_Receiver
"""
import eg
eg.RegisterPlugin(
name = "USB IR Remote Receiver",
author = "Portisch",
version = "0.0.1",
kind = "remote",
description = __doc__
)
import ctypes
import os
from ctypes import *
class USBIRRemoteReceiver(eg.PluginBase):
def ReceivedIRCode(self, Protocol, Address, Command, Flags):
#print "Received Protocol: " + Protocol
#print "Received Address: " + Address
#print "Received Command: " + Command
#print "Received Flags: " + Flags
self.TriggerEvent("Protocol: " + Protocol + ", Address: 0x" + Address + ", Command: 0x" + Command)
def __init__(self):
print ("USBIRRemoteReceiver: Plugin gets loaded.")
print ("USBIRRemoteReceiver: Actual path: " + os.path.dirname(os.path.abspath(__file__)))
try:
print ("USBIRRemoteReceiver: Try to load ''USB_IR_Remote_Receiver.dll''")
self.dll = ctypes.windll.LoadLibrary(os.path.dirname(os.path.abspath(__file__)) + ("\USB_IR_Remote_Receiver.dll"))
print ("USBIRRemoteReceiver: USB_IR_Remote_Receiver.dll found and loaded!")
self.dll.PluginName.restype = c_char_p
print ("USBIRRemoteReceiver: DLL Plugin Name: " + self.dll.PluginName())
self.dll.Version.restype = c_char_p
print ("USBIRRemoteReceiver: DLL Plugin Version: " + self.dll.Version())
self.dll.Copyright.restype = c_char_p
print ("USBIRRemoteReceiver: DLL Plugin Copyright: " + self.dll.Copyright())
self.dll.Initialized = False
except:
raise self.Exceptions.FileNotFound
print ("USBIRRemoteReceiver: Init of USB IR Remote Receiver finished!")
def __start__(self, myString):
#print ("USB IR Remote Receiver is started")
# funtion prototype
prototype = WINFUNCTYPE(None, c_char_p, c_char_p, c_char_p, c_char_p)
# create callback function
self.MyIRCallback = prototype(self.ReceivedIRCode)
self.dll.InitPAnsiChar(self.MyIRCallback)
self.dll.Initialized = True
print ("USBIRRemoteReceiver: DLL got initialized")
def __stop__(self):
#print ("USB IR Remote Receiver is stopped.")
self.dll.InitPAnsiChar(None)
def __close__(self):
ctypes.windll.kernel32.CloseHandle(self.dll._handle)
print ("USBIRRemoteReceiver: USB_IR_Remote_Receiver.DLL is unloaded!")
#print ("USB IR Remote Receiver is closed.")
def Configure(self, myString=""):
panel = eg.ConfigPanel()
ShowSettingsButton = wx.Button(panel, id=-1, label='Show Settings/Option Dialog\n\n(This Dialog can only be shown if the plugin got initialized!)', pos=(8, 8), size=(175, 28))
ShowSettingsButton.Bind(wx.EVT_BUTTON, self.ShowSettingsButtonClick)
if self.dll.Initialized:
print ("USBIRRemoteReceiver: Trying to show Settings/Options dialog")
ShowSettingsButton.Enable()
else:
print ("USBIRRemoteReceiver: DLL is not initialized, can't show dialog")
ShowSettingsButton.Disable()
panel.sizer.Add(ShowSettingsButton, 1, wx.EXPAND)
while panel.Affirmed():
panel.SetResult("")
def ShowSettingsButtonClick(self,event):
try:
self.dll.ShowSettings.restype = None
self.dll.ShowSettings(eg.app.hwnd)
except:
print ("USBIRRemoteReceiver: Error showing Settings/Options dialog")
Is there a more simple way to show the dialog without the panel when I click with the right mouse on the Plugin -> Configure?
Also I can't remove the def __start__(self, myString):,
than I will get the error too many arguments.
Please help tp finish my EventGhost plugin.
The EventGhost plugin can be tested without hardware. Just copy the "USB_IR_Remote_Receiver.dll" in the same folder where the script is located.
Thx!