Originally posted by huggy_d1
View Post

If this is your first visit, be sure to check out the FAQ. You must register before you can post.
IMPORTANT: Your first post will be checked for appropriate content. This may take a bit of time.
Public Sub Main(ByVal Params As Object)
'====================================================================
'
' Sets the rgb color according to ratio of supplied rgb colors
' but still respects the max intensity settings using
' wifi rgb controller
'
' parameters : Red|Green|Blue
' example : Main("96,48,32")
'
' writes to HS log if an error occurs
'
'====================================================================
'--------------------------------------------------------------------
' CONSTANTS
'--------------------------------------------------------------------
Const sRED As String = "Red"
Const sGREEN As String = "Green"
Const sBLUE As String = "Blue"
Const sON As String = "On"
Const sOFF As String = "Off"
Const Client As Integer = 1
' Set to HS2 device code, or to a virtual device you control to set max
' level, perhaps set via script
' Q13 = ###.## with the . implied, so 100% = 10000 in Q13
Const LightLevelDevice As String = "Q13"
Const pluginName As String = "WifiRGB (3P)"
Const LogHeader As String = "rgbWifi_Controller1"
'--------------------------------------------------------------------
' VARIABLES
'--------------------------------------------------------------------
Dim parms As String()
Dim RedCmd As Integer
Dim GreenCmd As Integer
Dim BlueCmd As Integer
Dim MaxIntensity As Integer = 255
Dim LightBasedIntensity As Integer
Dim LightLevel As Integer
'--------------------------------------------------------------------
' Program code
'--------------------------------------------------------------------
parms = Split(Params,",")
If parms.Length > 1 then
RedCmd = CInt(parms(0))
GreenCmd = CInt(parms(1))
BlueCmd = CInt(parms(2))
LightLevel = hs.DeviceValue(LightLevelDevice)
RedCmd = RedCmd * LightLevel / 10000
GreenCmd = GreenCmd * LightLevel / 10000
BlueCmd = BlueCmd * LightLevel / 10000
LightBasedIntensity = (MaxIntensity * LightLevel)/10000
hs.Plugin(pluginName).SetRGB(Client, RedCmd , GreenCmd , BlueCmd )
hs.WriteLog(LogHeader, "LightLevel Estimate : " & CStr(LightBasedIntensity) & ". Levels set to R="&CStr(RedCmd)&", G="&CStr(GreenCmd)&", B="&CStr(BlueCmd))
Else
hs.WriteLog(LogHeader, "Parameter issue. Received "&parms.ToString)
End If
End Sub
Public Sub Main(ByVal Params As Object)
'====================================================================
'
' Performs a visual PowerOnSelfTest (POST) to display some of the
' rgb controller and LED strip capabilities
'
'
' writes to HS log if an error occurs
'====================================================================
'--------------------------------------------------------------------
' CONSTANTS
'--------------------------------------------------------------------
Const sRED As String = "Red"
Const sGREEN As String = "Green"
Const sBLUE As String = "Blue"
Const sON As String = "On"
Const sOFF As String = "Off"
Const Client As Integer = 1
Const pluginName As String = "WifiRGB (3P)"
'--------------------------------------------------------------------
' VARIABLES
'--------------------------------------------------------------------
Dim MaxRedIntensity As Integer
Dim MaxGreenIntensity As Integer
Dim MaxBlueIntensity As Integer
Dim LogHeader As String = "rgbWifi_Controller1"
Dim RedHalfIntensity As Integer
Dim GreenHalfIntensity As Integer
Dim BlueHalfIntensity As Integer
Dim LightBasedIntensity As Integer
Dim RandomRedColor As New Random(30876)
Dim RandomGreenColor As New Random(6456)
Dim RandomBlueColor As New Random(6368)
Dim i,j,k As Integer ' loop index variables
Dim LightLevel As Integer
'--------------------------------------------------------------------
' Program code
'--------------------------------------------------------------------
LightLevel = hs.DeviceValue("Q13")
LightBasedIntensity = (255 * LightLevel)/10000
hs.WriteLog(LogHeader, "LightLevel Estimate : " & CStr(LightBasedIntensity))
MaxRedIntensity = LightBasedIntensity
MaxGreenIntensity = LightBasedIntensity
MaxBlueIntensity = LightBasedIntensity
' Establish 1/2 full allowed brightness for fade testing
RedHalfIntensity = MaxRedIntensity / 2
GreenHalfIntensity = MaxGreenIntensity / 2
BlueHalfIntensity = MaxBlueIntensity / 2
hs.WriteLog(LogHeader, "POST Started")
'hs.WriteLog(LogHeader, "Wifi RGB LED Controller FW Ver " & CStr(hs.Plugin(pluginName).FWVersion(Client)))
hs.Plugin(pluginName).SetRGB(Client, RedHalfIntensity, GreenHalfIntensity , BlueHalfIntensity )
hs.Plugin(pluginName).SingleControl(Client, sRED, sOFF)
hs.WaitSecs(1.25)
hs.Plugin(pluginName).SingleControl(Client, sGREEN, sOFF)
hs.WaitSecs(1.25)
hs.Plugin(pluginName).SingleControl(Client, sBLUE, sOFF)
hs.WaitSecs(1.25)
hs.Plugin(pluginName).SetFadeRate(Client, 16)
For i = 1 To 10 ' Loop to randomly assign colors
hs.Plugin(pluginName).SetRGB(Client, RandomRedColor.Next(0, MaxBlueIntensity), RandomGreenColor.Next(0, MaxBlueIntensity), RandomBlueColor.Next(0, MaxBlueIntensity))
hs.WaitSecs(0.1)
Next
hs.Plugin(pluginName).SetRGB(Client, RedHalfIntensity+10, GreenHalfIntensity+5, BlueHalfIntensity)
End Sub
Comment