Moskus Skrevet 28. mars 2016 Skrevet 28. mars 2016 GrandbeingMX0404.vb Script for å styre en Grandbeing MX0404 HDMI matrise. Lager en root med tilhørende child-devicer for hver utgang hvor man kan trykke på de forskjellige inngangene. Alt i et script, men dette blir nok en plugin på sikt (der er det lettere å få til en autorefresh, og sånt). '© Moskus 2014 Dim Scriptname As String = "GrandbeingMX0404.vb" Dim hdmi_outputs() As String = {"None", "TV", "SageTV", "Xbox", "Extra"} Dim ip_address As String = "192.168.0.39" Public Sub Main(parm As Object) End Sub Public Sub Setup(parm As Object) 'Setting up devices 'Creating master device Dim dt As New HomeSeerAPI.DeviceTypeInfo Dim devref As Integer = hs.NewDeviceRef("Root") Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devref) Try dv.Location(hs) = "HDMI matrix" dv.Location2(hs) = "Media" dv.Device_Type_String(hs) = "HDMI root" dv.DeviceType_Set(hs) = New HomeSeerAPI.DeviceTypeInfo dv.Status_Support(hs) = True dv.Can_Dim(hs) = False hs.SaveEventsDevices() dv.MISC_Set(hs, HomeSeerAPI.Enums.dvMISC.SHOW_VALUES) dv.MISC_Clear(hs, HomeSeerAPI.Enums.dvMISC.STATUS_ONLY) 'Adding a "Refresh" button to the root device hs.DeviceScriptButton_AddButton(devref, "Refresh", 0, Scriptname, "ButtonPress", "Refresh", 1, 1, 1) hs.SaveEventsDevices() Dim SVpair As New HomeSeerAPI.VSPair(HomeSeerAPI.ePairStatusControl.Status) SVpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue SVpair.Value = 0 SVpair.Status = "HDMI matrix" hs.DeviceVSP_AddPair(devref, SVpair) Dim VGpair As New HomeSeerAPI.VGPair VGpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue VGpair.Set_Value = 0 VGpair.Graphic = "images/Moskus/icon_hdmi.png" hs.DeviceVGP_AddPair(devref, VGpair) hs.WriteLog("HDMI matrix", "Root device for HDMI matrix created") Catch ex As Exception hs.WriteLog("HDMI matrix", "Error creating root device: " & ex.Message) End Try 'Creating child devices dv.Relationship(hs) = HomeSeerAPI.Enums.eRelationship.Parent_Root For i As Integer = 1 To 4 Dim childref As Integer = CreateOutputDevice(i, devref) If childref > 0 Then dv.AssociatedDevice_Add(hs, childref) Next End Sub Public Function CreateOutputDevice(ByVal output As Integer, masterdevice As Integer) As Integer 'Creating device Dim dt As New HomeSeerAPI.DeviceTypeInfo Dim devref As Integer = hs.NewDeviceRef("Output " & output) Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devref) Try dv.Location(hs) = "HDMI matrix" dv.Location2(hs) = "Media" dv.Device_Type_String(hs) = "HDMI out " & output dv.DeviceType_Set(hs) = New HomeSeerAPI.DeviceTypeInfo hs.SaveEventsDevices() dv.Status_Support(hs) = True dv.Can_Dim(hs) = False dv.MISC_Set(hs, HomeSeerAPI.Enums.dvMISC.SHOW_VALUES) dv.MISC_Clear(hs, HomeSeerAPI.Enums.dvMISC.STATUS_ONLY) dv.Relationship(hs) = HomeSeerAPI.Enums.eRelationship.Child dv.AssociatedDevice_Add(hs, masterdevice) dv = Nothing hs.WriteLog("HDMI matrix", "Test Device for output " & output & " created") Catch ex As Exception hs.WriteLog("HDMI matrix", "Error creating devices: " & ex.Message) Return 0 End Try Dim SVpair_off As New HomeSeerAPI.VSPair(HomeSeerAPI.ePairStatusControl.Status) SVpair_off.PairType = HomeSeerAPI.VSVGPairType.SingleValue SVpair_off.Value = 0 SVpair_off.Status = "None" hs.DeviceVSP_AddPair(devref, SVpair_off) Dim VGpair_off As New HomeSeerAPI.VGPair VGpair_off.PairType = HomeSeerAPI.VSVGPairType.SingleValue VGpair_off.Set_Value = 0 VGpair_off.Graphic = "images/Moskus/icon_hdmi_X.png" hs.DeviceVGP_AddPair(devref, VGpair_off) 'Adding buttons, values and graphic For i As Integer = 1 To 4 hs.DeviceScriptButton_AddButton(devref, output & "-" & i, i, Scriptname, "ButtonPress", output & "-" & i, 1, i, 1) Dim SVpair As New HomeSeerAPI.VSPair(HomeSeerAPI.ePairStatusControl.Status) SVpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue SVpair.Value = i SVpair.Status = "Input " & i hs.DeviceVSP_AddPair(devref, SVpair) Dim VGpair As New HomeSeerAPI.VGPair VGpair.PairType = HomeSeerAPI.VSVGPairType.SingleValue VGpair.Set_Value = i VGpair.Graphic = "images/Moskus/icon_hdmi_" & i & ".png" hs.DeviceVGP_AddPair(devref, VGpair) Next Return devref End Function Public Sub ButtonPress(Input As Object) Dim devref As Integer = Input(0) Dim ButtonName As String = Input(1) Dim output As String = String.Empty 'Gets filled by GetURLIE Dim device As Integer = 0 Dim master As Integer = hs.GetDeviceParentRefByRef(devref) If master = 0 Then master = devref Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(master) For Each devid As Integer In dv.AssociatedDevices(hs) Dim dev As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devid) Select Case dev.Device_Type_String(hs) Case Is = "HDMI root" device = 0 Case Is = "HDMI out 1" device = 1 Case Is = "HDMI out 2" device = 2 Case Is = "HDMI out 3" device = 3 Case Is = "HDMI out 4" End Select Next Dim command As String = "Refresh" If device > 0 Then Dim value As Integer = hdmi_outputs.ToList.IndexOf(ButtonName) command = device & "-" & value End If Select Case command Case Is = "Refresh" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=refrash", True) '"refrash" is actually not a typo on my part... Case Is = "1-1" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a09", True) Case Is = "1-2" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a1D", True) Case Is = "1-3" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a1F", True) Case Is = "1-4" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a0D", True) Case Is = "2-1" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a17", True) Case Is = "2-2" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a12", True) Case Is = "2-3" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a59", True) Case Is = "2-4" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a08", True) Case Is = "3-1" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a5E", True) Case Is = "3-2" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a06", True) Case Is = "3-3" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a05", True) Case Is = "3-4" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a03", True) Case Is = "4-1" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a18", True) Case Is = "4-2" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a44", True) Case Is = "4-3" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a0F", True) Case Is = "4-4" output = hs.GetURLIE("http://" & ip_address & "/get_data?type=port&cmd=a51", True) End Select InterpretOutput(devref, output) End Sub Public Sub InterpretOutput(ByVal devref As Integer, ByVal output As String) 'output: Output1=1Output2=1Output3=1Output4=1 Dim data(3) As Integer data(0) = CInt(output(8).ToString) data(1) = CInt(output(17).ToString) data(2) = CInt(output(26).ToString) data(3) = CInt(output(35).ToString) Dim master As Integer = hs.GetDeviceParentRefByRef(devref) If master = 0 Then master = devref Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(master) For Each devid As Integer In dv.AssociatedDevices(hs) Dim dev As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(devid) Select Case dev.Device_Type_String(hs) Case Is = "HDMI out 1" If hs.DeviceValue(devid) <> data(0) Then hs.SetDeviceValueByRef(devid, data(0), True) Else hs.SetDeviceValueByRef(devid, data(0), False) End If Case Is = "HDMI out 2" If hs.DeviceValue(devid) <> data(1) Then hs.SetDeviceValueByRef(devid, data(1), True) Else hs.SetDeviceValueByRef(devid, data(1), False) End If Case Is = "HDMI out 3" If hs.DeviceValue(devid) <> data(2) Then hs.SetDeviceValueByRef(devid, data(2), True) Else hs.SetDeviceValueByRef(devid, data(2), False) End If Case Is = "HDMI out 4" If hs.DeviceValue(devid) <> data(3) Then hs.SetDeviceValueByRef(devid, data(3), True) Else hs.SetDeviceValueByRef(devid, data(3), False) End If End Select Next End Sub Gir: 1 Siter
Christian Skrevet 16. februar 2017 Skrevet 16. februar 2017 Jeg har laget en ett matrise oppsett med VIrtuelle Devicer, men mine innganger er ikke gruppert sånn som dine. Jeg ser du gjør dette via ett script, betyr det at devicene blir opprettet hver gang du kjører dette scriptet. Når kjører du det ? Er det mulig å gruppere devicer i fra Websiden, eller må dette gjøres vha script ? Siter
Moskus Skrevet 17. februar 2017 Forfatter Skrevet 17. februar 2017 Som du ser i scriptet har jeg en "Setup()" rutine. Her er "dv" root-devicen, og siste delen lager children og assosierer dem med root: 'Creating child devices dv.Relationship(hs) = HomeSeerAPI.Enums.eRelationship.Parent_Root For i As Integer = 1 To 4 Dim childref As Integer = CreateOutputDevice(i, devref) If childref > 0 Then dv.AssociatedDevice_Add(hs, childref) Next Siter
Christian Skrevet 26. desember 2017 Skrevet 26. desember 2017 Hva gjør den siste subrutina ? data(0) = CInt(output(8).ToString) data(1) = CInt(output(17).ToString) data(2) = CInt(output(26).ToString) data(3) = CInt(output(35).ToString) Hva er output(8), output(17), output(26), og output(35) ? Siter
Moskus Skrevet 27. desember 2017 Forfatter Skrevet 27. desember 2017 "Output" er bare en laaaang streng. "Output(8)" henter ut den niende bokstaven (som "Char") og konverterer den til String. Og deretter blir hele sulamiten konvertert til et tall. Siter
Christian Skrevet 27. desember 2017 Skrevet 27. desember 2017 Ja, så det nå..... En del ting er innlysende bare man får ett lite hint ? Siter
Anbefalte innlegg
Bli med i samtalen
Du kan publisere innhold nå og registrere deg senere. Hvis du har en konto, logg inn nå for å poste med kontoen din.