Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\Port.cls"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Global.inc"
'#Uses "Include.inc"

Option Explicit
'*****************************************************************************
' Module:
'        IO
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'IO'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  Sunil          04-10-04     initial version
'
'
'
'*****************************************************************************

'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As Peripherals) As Boolean

    OnLoad = False

    If (Not OnLoadPagePorts(ps)) Then Exit Function
    If (Not OnLoadPageFunctions(ps)) Then Exit Function
    If (Not OnLoadPageParameters(ps)) Then Exit Function
    If (Not OnLoadPageNotes(ps)) Then Exit Function
    
    ' call function to initialize the menu
        If (Not InitMenu(ps, "IO\Dialog")) Then Exit Function

    OnLoad = True

End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
        
        OnChangingPage = False
    
        If (Not OnChangingPagePorts(ps, Pagename)) Then Exit Function
        If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function
        If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function
        If (Not OnChangingPageNotes(ps, Pagename, "IO")) Then Exit Function
        
        OnChangingPage = True

End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is a empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
        OnShow = False

            If (Not OnShowPagePorts(ps, Controlname, Pagename, v)) Then Exit Function
            If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function
            If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
            If (Not OnShowPageNotes(ps, Controlname, Pagename, "IO", v)) Then Exit Function
            

        OnShow = True
End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
On Error GoTo OnClickError

    Dim np  As Peripherals
    Dim cPorts As DAvECollection
    Dim Port As Port
    
    Set cPorts = ObjectCollection("PORTS")

    For Each Port In cPorts
      If (Controlname = "btnConfigPort" & Port.PortNumber) Then
          Set np = New Peripherals
          np.Parameters.Add ("PortIndex")
          np.Parameters.v("PortIndex") = Port.PortNumber
          np.Parameters.Add ("FirstPinIndex")
          np.Parameters.v("FirstPinIndex") = Port.FirstPin
          np.Parameters.Add ("LastPinIndex")
          np.Parameters.v("LastPinIndex") = Port.LastPin
          np.Parameters.Add ("Addr")
          np.Parameters.v("Addr") = Port.Addr
          Set np.ProjectData = ps.ProjectData
          np.Caption = "Configure " & Port.Description
          np.Scriptfile = DefGetPath("Scripts") & "IO\PortxDialog.DAVE"
          np.Show
      End If
    Next Port
          
    OnClick = True
    
    Exit Function
    
OnClickError:
    Errorbox "Can not process the click", Err.Description
    Exit Function

End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False
    
    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "IO\Dialog")) Then Exit Function
        
    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function

'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPagePorts(ps As Peripherals) As Boolean
  On Error Resume Next

  OnLoadPagePorts = False

  If (Not ps.AddPage("Ports")) Then Exit Function
  
  OnLoadPagePorts = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnChangingPagePorts(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPagePorts = False

  If (Not ps.ExtenderCollection("Ports").Loaded) And (Pagename = "Ports") Then
    ps.ExtenderCollection("Ports").Loaded = True
  
    
    If (Not ps.AddFrame("frmIO1", 100, 100, 8400, 4000, "")) Then Exit Function
        If (Not ps.AddButton("btnConfigPort0", 300, 720, 3600, 350, "Configure Port 0")) Then Exit Function
        If (Not ps.AddButton("btnConfigPort1", 4440, 720, 3600, 350, "Configure Port 1")) Then Exit Function
        If (Not ps.AddButton("btnConfigPort2", 300, 1440, 3600, 350, "Configure Port 2")) Then Exit Function
        If (Not ps.AddButton("btnConfigPort3", 4440, 1440, 3600, 350, "Configure Port 3")) Then Exit Function
        If (Not ps.AddButton("btnConfigPort4", 300, 2160, 3600, 350, "Configure Port 4")) Then Exit Function

  End If
  OnChangingPagePorts = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPagePorts(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPagePortsError

  OnShowPagePorts = False
  
  OnShowPagePorts = True
  Exit Function

OnShowPagePortsError:
  Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFunctions(ps As Peripherals) As Boolean
  On Error Resume Next

  OnLoadPageFunctions = False

  If (Not ps.AddPage("Functions")) Then Exit Function
  
  OnLoadPageFunctions = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  
  Dim e As Collection
  Dim pos As Long

  OnChangingPageFunctions = False

  Set e = ps.ExtenderCollection

  If (Not e("Functions").Loaded) And (Pagename = "Functions") Then
    e("Functions").Loaded = True

    '-------------------------------------------------------------------------------------------------------------------------
    ' Initialization Funtion
    '-------------------------------------------------------------------------------------------------------------------------
    If (Not ps.AddFrame("fraIO_USE_Init", 100, 100, 4150, 700, "Initialization Function")) Then Exit Function
    If (Not ps.AddCheck("chkIO_USE_Init", 200, 275, 900, 275, "IO_vInit")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_Init", 2150, 250, 1900, 325)) Then Exit Function

    '-------------------------------------------------------------------------------------------------------------------------
    ' Source File
    '-------------------------------------------------------------------------------------------------------------------------
    If (Not ps.AddFrame("fraIO_CFile", 4400, 100, 4150, 700, "Source File")) Then Exit Function
    If (Not ps.AddLabel("lblIO_CFile", 0, 200, 275, 1250, 275, "File Name")) Then Exit Function
    If (Not ps.AddText("txtIO_CFile", 1500, 250, 2550, 325)) Then Exit Function

    '-------------------------------------------------------------------------------------------------------------------------
    ' Functions and Macros
    '-------------------------------------------------------------------------------------------------------------------------
    If (Not ps.AddFrame("fraLibrary", 100, 900, 4150, 4400, "Function Library")) Then Exit Function
    pos = 0

    If (Not ps.AddCheck("chkIO_USE_ReadPin", 200, 270 + pos * 300, 2100, 380, "IO_ubReadPin")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_ReadPin", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkIO_USE_SetPin", 200, 270 + pos * 300, 2100, 380, "IO_vSetPin")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_SetPin", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkIO_USE_ResetPin", 200, 270 + pos * 300, 2100, 380, "IO_vResetPin")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_ResetPin", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkIO_USE_ReadPort", 200, 270 + pos * 300, 2100, 380, "IO_ubReadPort")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_ReadPort", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkIO_USE_WritePort", 200, 270 + pos * 300, 2100, 380, "IO_vWritePort")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_WritePort", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkIO_USE_SetInput", 200, 270 + pos * 300, 2100, 380, "IO_vSetInput")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_SetInput", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkIO_USE_SetOutput", 200, 270 + pos * 300, 2100, 380, "IO_vSetOutput")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_SetOutput", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkIO_USE_TogglePin", 200, 270 + pos * 300, 2100, 380, "IO_vTogglePin")) Then Exit Function
    If (Not ps.AddText("txtIO_NAME_TogglePin", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1
  End If

  OnChangingPageFunctions = True
  
ExitLabel:
  
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  OnShowPageFunctions = False
  
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sName As String

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

  If (Pagename = "Functions") Then

    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "chkIO_USE_Init"
            r.v("IO_USE_Init") = v(1)
    
        Case "txtIO_NAME_Init"
            If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkIO_USE_Init").Caption)) Then
                r.v("IO_NAME_Init") = v(1)
            End If

        Case "txtIO_CFile"
             If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblIO_CFile").Caption)) Then
                r.v("IO_CFile") = v(1)
             Else
                Exit Function
             End If
    End Select     ' case Controlname

    If (Not UpdateFunction(ps, Controlname, v, "ReadPin")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SetPin")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ResetPin")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadPort")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "WritePort")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SetInput")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SetOutput")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "TogglePin")) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)

    '-------------------------------------------------------------------------
    ' control: chkIO_USE_.. (show)
    '-------------------------------------------------------------------------
    c("chkIO_USE_Init").Value = -CInt(r.v("IO_USE_Init") = 1)
    e("chkIO_USE_Init").EnabledTooltipText = FormatFunctionToolTip(r, func, "IO_NAME_Init")

    '-------------------------------------------------------------------------
    ' control: txtIO_NAME_... (show)
    '-------------------------------------------------------------------------
    With c("txtIO_NAME_Init")
        bDisabled = (r.v("IO_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = r.s("IO_NAME_Init")
    End With

    With e("txtIO_NAME_Init")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        End If
    End With

    If (Not ShowFunction(ps, v, func, "ReadPin")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SetPin")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ResetPin")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadPort")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "WritePort")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SetInput")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SetOutput")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "TogglePin")) Then Exit Function

    '-------------------------------------------------------------------------
    ' control: lblIO_CFile (show)
    '-------------------------------------------------------------------------
    With c("lblIO_CFile")
      bDisabled = (r.v("IO_USE_Init") = 0)
      .Enabled = Not bDisabled
    End With

    With e("lblIO_CFile")
      If (bDisabled) Then
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtIO_CFile (show)
    '-------------------------------------------------------------------------
    With c("txtIO_CFile")
      bDisabled = (r.v("IO_USE_Init") = 0)
      .Enabled = Not bDisabled
      .Text = r.v("IO_CFile")
    End With

    With e("txtIO_CFile")
      If (bDisabled) Then
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
      End If
    End With

  End If         ' if Pagename
    
    
    OnShowPageFunctions = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageParameters(ps As Peripherals) As Boolean
  On Error Resume Next

  OnLoadPageParameters = False

  If (Not ps.AddPage("Parameters")) Then Exit Function
  
  OnLoadPageParameters = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  OnChangingPageParameters = False
  
  Dim e As Collection

  Set e = ps.ExtenderCollection

  If (Not e("Parameters").Loaded) And (Pagename = "Parameters") Then
    e("Parameters").Loaded = True
    If (Not ps.AddFrame("fraIO_HFile", 100, 100, 8450, 700, "Header File")) Then Exit Function
    If (Not ps.AddText("txtIO_HFile", 1825, 300, 5000, 315)) Then Exit Function
    If (Not ps.AddLabel("lblIO_HFile", 0, 200, 300, 1575, 380, "File name")) Then Exit Function
    
  End If
  
  OnChangingPageParameters = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

 
  If (Pagename = "Parameters") Then
    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "txtIO_HFile"
             If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblIO_HFile").Caption)) Then
                r.v("IO_HFile") = v(1)
             Else
                Exit Function
             End If
    End Select

    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' control: lblIO_HFile (show)
    '-------------------------------------------------------------------------
    With c("lblIO_HFile")
      bDisabled = (r.v("IO_USE_Init") = 0)
      .Enabled = Not (bDisabled)
    End With

    With e("lblIO_HFile")
      If (bDisabled) Then
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtIO_HFile (show)
    '-------------------------------------------------------------------------
    With c("txtIO_HFile")
      bDisabled = (r.v("IO_USE_Init") = 0)
      .Enabled = Not (bDisabled)
      .Text = FormatTextOutput(r.v("IO_HFile"), "S")
    End With

    With e("txtIO_HFile")
      If (bDisabled) Then
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
      End If
    End With

  End If         ' if Pagename
  OnShowPageParameters = True
  Exit Function

OnShowError:
    Errorbox "Can not show page", Err.Description
End Function

'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the Project Data Object
'        Controlname     control name
'        v()             value array
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function UpdateFunction(ps As Peripherals, Controlname As String, v() As Variant, sName As String) As Boolean
  On Error GoTo ExitLabel
  UpdateFunction = False

  Dim r As ProjectData
  Dim c As Collection

  Set r = ps.ProjectData
  Set c = ps.ControlCollection

  '---------------------------------------------------------------------
  ' control: chkIO_USE_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "chkIO_USE_" & sName) Then
    r.v("IO_USE_" & sName) = v(1)
  End If

  '---------------------------------------------------------------------
  ' control: txtIO_NAME_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "txtIO_NAME_" & sName) Then
    If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkIO_USE_" & sName).Caption)) Then
        r.v("IO_NAME_" & sName) = v(1)
    Else
       Exit Function
    End If
  End If

  UpdateFunction = True
ExitLabel:
End Function

'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        v()             value array
'        func            reference to the function object
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function ShowFunction(ps As Peripherals, v() As Variant, func As FunctionClass, sName As String) As Boolean
  On Error GoTo ExitLabel
  ShowFunction = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  '-------------------------------------------------------------------------
  ' control: chkIO_USE_.. (show)
  '-------------------------------------------------------------------------
  With c("chkIO_USE_" & sName)
    bDisabled = (r.v("IO_USE_Init") = 0)
    .Enabled = Not bDisabled
    .Value = -CInt((r.v("IO_USE_Init") = 1) And (r.v("IO_USE_" & sName) = 1))
  End With

  With e("chkIO_USE_" & sName)
    If (bDisabled) Then
        .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "IO_NAME_" & sName)
        .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    Else
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "IO_NAME_" & sName)
    End If
  End With

  '-------------------------------------------------------------------------
  ' control: txtIO_NAME_... (show)
  '-------------------------------------------------------------------------
  With c("txtIO_NAME_" & sName)
    bDisabled = c("chkIO_USE_" & sName).Value = 0
    .Enabled = Not bDisabled
    .Text = FormatTextOutput(r.s("IO_NAME_" & sName), "S")
  End With

  With e("txtIO_NAME_" & sName)
    If (bDisabled) Then
      .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
    End If
  End With

  ShowFunction = True
ExitLabel:
End Function

