Function Custom_Initialize(msgPort As Object, userVariables As Object, bsp as Object)

    print "Custom_Initialize - entry"
    print "type of msgPort is ";type(msgPort)
    print "type of userVariables is ";type(userVariables)

    Custom = newCustom(msgPort, userVariables, bsp)

    return Custom

End Function


Function newCustom(msgPort As Object, userVariables As Object, bsp as Object)
	print "initCustom"

	' Create the object to return and set it up
	s = {}
	s.msgPort = msgPort
	s.userVariables = userVariables
	s.bsp = bsp
	s.ProcessEvent = Custom_ProcessEvent
	s.HandlePluginTimerEvent = HandlePluginTimerEvent
	s.objectName = "Custom_object"
	s.gpioPort = CreateObject("roControlPort", "BrightSign")
	s.gpioPort.SetPort(s.msgPort)
	s.transitionSFX1 = val(s.uservariables.TransitionEffect1.currentvalue$)
	s.transitionRate1 = val(s.uservariables.TransitionRateInMS1.currentvalue$)
	s.transitionSFX2 = val(s.uservariables.TransitionEffect2.currentvalue$)
	s.transitionRate2 = val(s.uservariables.TransitionRateInMS2.currentvalue$)

	return s
End Function

Function Custom_ProcessEvent(event As Object) as boolean

	retval = false
    print "Custom_ProcessEvent - entry"
    print "type of m is ";type(m)
    print "type of event is ";type(event)
	
	if type(event) = "roTimerEvent" then
		retval = HandlePluginTimerEvent(event, m)
	end if
	
	return retval

End Function




Function HandlePluginTimerEvent(origMsg as Object, Custom as object) as boolean

	if type(origMsg) = "roTimerEvent" then
	
		timerIdentity = origMsg.GetSourceIdentity()
		
		if Custom.bsp.sign.zoneshsm[0].statetable.DoesExist("ImageList") then
		
			Print "XXX!!! ImageList Found !!!XXX"
	
				indexnum = 0
			
				Custom.bsp.sign.zoneshsm[0].statetable.ImageList.statemachine.imageplayer.SetTransitionDuration(Custom.transitionRate1)
			
				'Custom.bsp.sign.zoneshsm[0].statetable.ImageList.statemachine.imageplayer.SetDefaultTransition(Custom.transitionSFX)
			
				for each indtransition in Custom.bsp.sign.zoneshsm[0].statetable.ImageList.items
							
					Custom.bsp.sign.zoneshsm[0].statetable.ImageList.items[indexnum].slideTransition% = Custom.transitionSFX1
			
					indexnum = indexnum + 1
			
				next
			
			'end if
			
		else
		
			Print "!!! ImageList Not Found !!!"	
			
		end if
				

		if Custom.bsp.sign.zoneshsm[0].statetable.DoesExist("ImageList2") then
		
					Print "XXX!!! ImageList2 Found !!!XXX"
			
						indexnum = 0
			
						Custom.bsp.sign.zoneshsm[0].statetable.ImageList2.statemachine.imageplayer.SetTransitionDuration(Custom.transitionRate2)
			
						for each indtransition in Custom.bsp.sign.zoneshsm[0].statetable.ImageList2.items
							
							Custom.bsp.sign.zoneshsm[0].statetable.ImageList2.items[indexnum].slideTransition% = Custom.transitionSFX2
			
							indexnum = indexnum + 1
			
						next
		
		
		else
		
			Print "!!! ImageList2 Not Found !!!"
		
		end if 
		'stop
						
			'Custom.bsp.sign.zoneshsm[0].statetable.ImageList.items[0].slideTransition% = 25
			'Custom.bsp.sign.zoneshsm[0].statetable.ImageList.items[1].slideTransition% = 15
			'Custom.bsp.sign.zoneshsm[0].statetable.ImageList.items[2].slideTransition% = 10			
						
	else
	
		print "some other event received "
	
	end if


End Function



