using VB = Microsoft.VisualBasic; using System.Text; [Serializable()] public class HSPI : MarshalByRefObject { /* ' sample plug-in for HomeSeer ' this control will interface between HomeSeer and a custom ' device supporting X10, IR, or I/O ' after this control is registered, the new device will appear ' in the interfaces tab in HomeSeer and the user may select it */ bool AlreadyDisplayedError; internal Timers.Timer Timer1; internal Timers.Timer IRTimer; //capabilites of device (this OCX) (bits) const short CA_X10 = 1; const short CA_IR = 2; const short CA_IO = 4; const short CA_THERM = 16; const short CA_MUSIC = 32; /*callback constants ' see the HS docs and Appendix A for information on HS callbacks*/ const short EV_TYPE_X10 = 1; const short EV_TYPE_LOG = 2; const short EV_TYPE_STATUS_CHANGE = 4; const short EV_TYPE_AUDIO = 8; const short EV_TYPE_X10_TRANSMIT = 16; const short EV_TYPE_CONFIG_CHANGE = 32; const short EV_TYPE_STRING_CHANGE = 64; private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { DeviceTrigger("Family Room", "Motion"); } #Region " Common Plug-In Interface Procedures " /*' ********************************** Common Interface **************************** ' ' All plug-ins must support these methods and properties ' return capabilities of this device*/ public int Capabilities() { //tell HS we support all interfaces Capabilities = CA_X10 | CA_IR | CA_IO; } /*' return the name of your X10 device ' this name will appear in the HS interfaces tab*/ public string Name { get { return IFACE_NAME; } } /*HomeSeer will call this function to register a callback object ' If events are needed (for things like IR matching, X10 events, etc.), call back ' to HomeSeer using this function.*/ public void RegisterCallback(ref object frm) { /*' call back into HS and get a reference to the HomeSeer ActiveX interface ' this can be used make calls back into HS like hs.SetDeviceStatus, etc. ' The callback object is a different interface reserved for plug-ins. */ callback = frm; hs = frm.GetHSIface; if (hs == null) { MsgBox("Unable to access HS interface", MsgBoxStyle.Critical); } else { hs.WriteLog("Sample Plug-in Info", "Register callback completed"); InterfaceVersion = hs.InterfaceVersion; hs.WriteLog("Sample Plug-in Info", "Application path: " + hs.GetAppPath); } } public short InterfaceStatus() { /*return status of interface ' see Module1.bas for constants*/ InterfaceStatus = ERR_NONE; } /*return the access level for this plugin ' 1=everyone can access, no protection ' 2=level 2 plugin. Level 2 license required to run this plugin */ public short AccessLevel() { AccessLevel = 1; } /*This indicates to HS that we are ready for HomeSeer 2.0 in areas such as ' SetIOEx instead of SetIO*/ public bool SupportsHS2 { get { return true; } } #End Region #Region " SetIOEx - Device Command Handler " /*' This function is called when an action on a device is to be executed. ' If a device's status is set to ON or OFF, or its value changes, this function is called ' note that this will be called for ALL I/O devices. You must check and make sure that ' the housecode value belongs to you. When your control is initialized, allocate a free ' housecode and save it in the registry. Restore it whenever you are initialized*/ public void SetIOEx(object dv, string housecode, string devicecode, short command, short brightness, short data1, short data2, string voice_command, string host) { bool bOurs = false; if (!(dv == null)) { if (dv.interface.trim == IFACE_NAME) { bOurs = true; hs.WriteLog(IFACE_NAME, "SetIOEx called for " + dv.location + " " + dv.location2 + " " + dv.name); } else { return; } } if (!(bOurs)) { if (gBaseCode.ToUpper != housecode.Trim.ToUpper) { return; } } hs.WriteLog(IFACE_NAME, "SetIOEx for " + housecode + devicecode + ", Cmd=" + command.ToString + ", Brt=" + brightness.ToString + ", D1/D2=" + data1.ToString + "/" + data2.ToString + ", Vcmd=" + voice_command + ", Host=" + host); } #End Region #Region " HSEvent - HomeSeer Event Callback Handler " public void HSEvent(ref object[][0] parms) { if (System.Convert.ToInt32(parms(0)) == EV_TYPE_STATUS_CHANGE) { hs.WriteLog(IFACE_NAME, "Status change " + parms(2) + parms(1) + " Command: " + System.Convert.ToString(parms(3))); } else if (System.Convert.ToInt32(parms(0)) == EV_TYPE_AUDIO) { if (parms(1)) { hs.WriteLog(IFACE_NAME, "Audio is started"); } else { hs.WriteLog(IFACE_NAME, "Audio has stopped"); } } else if (System.Convert.ToInt32(parms(0)) == EV_TYPE_STRING_CHANGE) { hs.WriteLog(IFACE_NAME, "String change event for " + System.Convert.ToString(parms(1)) + " to string:" + System.Convert.ToString(parms(2))); } } #End Region #Region " X-10 Plug-In Related Procedures " /*' ********************************** X10 Interface **************************** ' ' X10 interface ' called when HS shuts down ' release any memory or free any ports here*/ public void ShutDownX10() { //Do something... IRTimer.Enabled = false; Timer1.Enabled = false; WebLink1 = null; //then indicate that it has been shut down: gX10Enabled = false; } /*init function, called when HS starts up ' return error string or empty string if ok*/ public string InitX10(ref int port) { string s = ""; // TODO: NotImplemented statement: ICSharpCode.SharpRefactory.Parser.AST.VB.OnErrorStatement if (gIREnabled | gIOEnabled | gX10Enabled) { return ""; } s = InitHW(port); if (s.Trim == "") InitCommon(); gX10Enabled = true; return s; } /* send an X10 command over the powerline ' the command should be queued as this function can be called ' many times. Queuing is optional ' ' data1 and data2 are the two extended bytes for the X10 Extended command*/ public void Exec(ref object dv, ref string housecode, ref string devicecode, ref short command, ref short brightness, ref short data1, ref short data2) { hs.WriteLog(IFACE_NAME, "Exec called for " + housecode + devicecode); } /*send an X10 command over the powerline and do not return until command ' is actually sent ' ' data1 and data2 are the two extended bytes for the X10 Extended command '*/ public void ExecWait(ref object dv, ref string housecode, ref string devicecode, ref short command, ref short brightness, ref short data1, ref short data2) { hs.WriteLog(IFACE_NAME, "ExecWait called for " + housecode + devicecode); } }