'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"

Option Explicit

'*****************************************************************************
' Module:
'        OSC
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'OSC'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        1.0   ahe         27.04.00     final version for C165UTAH
'
'        ----------------------------------------------------------------------
'        2.0   ahe         05.09.00     final version for C167CS, C161PI, C161CS/JC/JI
'             
'        ----------------------------------------------------------------------
'        3.0   ahe         31.10.00     final version for 
'                                         C167CS
'                                         C161PI
'                                         C161CS/JC/JI
'                                         C167CR/SR r2
'
'                                       - check ISNC
'
'        ----------------------------------------------------------------------
'        4.0   ahe         07.08.01     final version for 
'                                         C167CS
'                                         C161PI
'                                         C161CS/JC/JI
'                                         C167CR/SR r2
'                                         Pegasus
'                                       - no changes
'
'*****************************************************************************


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

    OnLoad = False

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnLoadPageControl(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePEC(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnLoadPageParameters(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNotes(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' end of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "OSC\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
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 successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error Goto OnChangingPageError

    OnChangingPage = False

    
    '-------------------------------------------------------------------------
    'page: Control
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: PEC
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePEC (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Functions
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnChangingPageParameters (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes (ps, Pagename, "OSC")) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
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 successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnShowError

    OnShow = False

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnShowPageControl(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts(ps, Controlname, v, "OSC", Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnShowPagePEC(ps, Controlname, v, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function 
       
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, "OSC", v)) Then Exit Function


    OnShow = True
    Exit Function

OnShowError:
    Errorbox "Can not show page.", Err.Description
    Exit Function
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 successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False

    Dim np As Peripherals

    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function


    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not Text in OnClick.", 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 successfull 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, "OSC\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 the page 'PLL_Control'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl = False

  If (Not ps.AddPage("Control")) Then Exit Function

  OnLoadPageControl = 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 successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim vIndex As Variant
  Dim r As ProjectData

  Set r = ps.ProjectData

  OnChangingPageControl = False
  
  If (Not ps.ExtenderCollection("Control").Loaded) And (Pagename = "Control") Then
    ps.ExtenderCollection("Control").Loaded = True
  

    '-------------------------------
    ' frame: frmOSCENBL
    '-------------------------------
    If (Not ps.AddFrame("frmOSCENBL",100,100, 5800, 1600, "Oscillator Watchdog Disable Bit (" & GetOWDDisebleBitName(r, vIndex) & ")")) Then Exit Function
        If (Not ps.AddOption("optOSCENBL_0", 200, 400, 5100, 380, "The on-chip oscillator watchdog is enabled and active")) Then Exit Function
        If (Not ps.AddOption("optOSCENBL_1", 200, 900, 5100, 380, "The on-chip oscillator watchdog is disabled and the CPU clock is always fed from the oscillator input")) Then Exit Function

    '-------------------------------
    ' frame: frmIC
    '-------------------------------
    If (Not ps.AddFrame("frmIC",100,1900, 5800, 1000, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkPLLIE", 200, 350, 3825, 380, "Enable PLL unlock / OWD interrupt (XP3IE)")) Then Exit Function

  End If
  OnChangingPageControl = 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 successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControlError

  OnShowPageControl = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sVarPre As String

  sVarPre = "OSC"

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

  If (Pagename = "Control") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkPLLIE (action)
        '---------------------------------------------------------------------
        Case "chkPLLIE"
             If (r.regs.SfrFind("ISNC") = True) Then
                 r.v("ISNC_PLLIE") = v(1)
             End If
             If (v(1) = 1) Then
               r.v(sVarPre & "_USE_Init") = 1
               Call EnableSRN(r, sVarPre, "XP3IC", "XP3IE", "UnlockOWD")
             Else
               r.v(sVarPre & "_USE_Init") = 0
               Call DisablePLLInt(r)
             End If

        '---------------------------------------------------------------------
        ' control: optOSCENBL_1 (action)
        '---------------------------------------------------------------------
        Case "optOSCENBL_1"
             r.v("SYSCON_" & GetOWDDisebleBitName(r, vIndex)) = 1
             r.v(sVarPre & "_USE_Init") = 0
             Call DisablePLLInt(r)

        '---------------------------------------------------------------------
        ' control: optOSCENBL_0 (action)
        '---------------------------------------------------------------------
        Case "optOSCENBL_0"
             r.v("SYSCON_" & GetOWDDisebleBitName(r, vIndex)) = 0

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkPLLIE (show)
    '-------------------------------------------------------------------------
    With c("chkPLLIE")
      bDisabled = (r.v("SYSCON_" & GetOWDDisebleBitName(r, vIndex)) = 1 And (r.v("RP0H_CLKCFG") = 1 Or r.v("RP0H_CLKCFG") = 3))
      .Enabled = Not(bDisabled)
      
      If (r.regs.SfrFind("ISNC") = True) Then
          .Value = -CInt(r.v("ISNC_PLLIE") = 1)
      Else
          .Value = -CInt(r.v("XP3IC_XP3IE") = 1)
      End If
    
    End With

    With e("chkPLLIE")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("SYSCON_" & GetOWDDisebleBitName(r, vIndex)) = 1 And (r.v("RP0H_CLKCFG") = 1 Or r.v("RP0H_CLKCFG") = 3)) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("no PLL operation mode selected AND the OWD is disabled (PLL operation mode see Project-Settings)")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optOSCENBL_1 (show)
    '-------------------------------------------------------------------------
    With c("optOSCENBL_1")
      bDisabled = r.v("RP0H_CLKCFG") <> 1 And r.v("RP0H_CLKCFG") <> 3
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("SYSCON_" & GetOWDDisebleBitName(r, vIndex)) = 1)
    End With

    With e("optOSCENBL_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("RP0H_CLKCFG") <> 1 And r.v("RP0H_CLKCFG") <> 3) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("PLL is operating (see Project Settings)")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optOSCENBL_0 (show)
    '-------------------------------------------------------------------------
    With c("optOSCENBL_0")
      'bDisabled = r.v("RP0H_CLKCFG") <> 1 And r.v("RP0H_CLKCFG") <> 3
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("SYSCON_" & GetOWDDisebleBitName(r, vIndex)) = 0)
    End With

    With e("optOSCENBL_0")
      If (bDisabled) Then
        .DisabledTooltipText = e("optOSCENBL_1").DisabledTooltipText
      End If
    End With

  End If

  OnShowPageControl = True
  Exit Function

OnShowPageControlError:
  Errorbox "Can not show page.", Err.Description
  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 successfull 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 successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim aFunctions(1 To 16) As String


  OnChangingPageFunctions = False

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

    '-------------------------------
    ' frame: fra_Init
    '-------------------------------
    If (Not ps.AddFrame("fra_Init", 100 , 100, 4150, 700, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 200, 275, "")) Then Exit Function
      If (Not ps.AddText("txt_Init", 400, 250, 3600, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400 , 100, 4150, 700, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txt_CFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_CFile", 0, 200, 300, 1250, 275, CAPTION_LBL_CFILE)) Then Exit Function


    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
    ' initialize the array
    For i = Lbound(aFunctions) To Ubound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = Lbound(aFunctions)

    aFunctions(i) = "UnlockOWD"
    i = i + 1

    If (Not ps.AddFrame("fraLibrary1", 100 , 900, 4150, 4400, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = Lbound(aFunctions) To Ubound(aFunctions)
        If Not(aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

  End If

  OnChangingPageFunctions = 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 successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error Goto OnShowPageFunctionsError

  OnShowPageFunctions = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim d As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName As String
  Dim vIndex As Variant

  sVarPre = "OSC"
  sRegPre = "OSC"

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

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions(vIndex, func, r)

    If (Not UpdateFunction(sVarPre, ps, func , Controlname, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r)

    sName = sVarPre & "_NAME_Init" 
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    'd = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v("XP3IC_XP3IE") = 0) Then
      d = FormatNormalTooltip("This function will selected by DAvE if the PLL interrupt (XP3IE) is enabled")
    End If
    If (r.v("XP3IC_XP3IE") = 1) Then
      d = FormatFunctionToolTip(r, func, sName)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_UnlockOWD" 
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, "XP3IC", "XP3IE", "UnlockOWD") 'And Not(IsSubNodeIntDisabled(r))


    If (Not ShowFunction(sVarPre, ps, func , v)) Then Exit Function


  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowPageFunctionsError:
  Errorbox "Can not show page.", Err.Description
  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 successfull 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 successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageParameters = False

  If (Not ps.ExtenderCollection("Parameters").Loaded) And (Pagename = "Parameters") Then
    ps.ExtenderCollection("Parameters").Loaded = True

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fra_HFile", 100 , 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txt_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_HFile",0 , 200 , 300, 1250, 300, CAPTION_LBL_HFILE)) 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 successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error Goto OnShowPageParametersError
  OnShowPageParameters = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim para As ParameterClass
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName As String
  Dim d As String
  Dim i As Integer

  vIndex = ps.Parameters.v("x")   
  sVarPre = "OSC" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set para = New ParameterClass


  If (Pagename = "Parameters") Then

    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    RefreshParameterDescriptions(vIndex, para, r)

    If (Not UpdateParameter(sVarPre, ps, para , Controlname, v)) Then Exit Function


    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------

    Set para = New ParameterClass
    RefreshParameterDescriptions(vIndex, para, r)

'    sName = sIndex & "_PARA_T2" 
'    ' disable condition
'    para.Disabled(sName) = True
'    ' tooltip if control is disabled
'    d = FormatDisabledTooltip("Fred ...")
'    para.DisabledToolTip(sName) = d

    If (Not ShowParameter(sVarPre, ps, para, v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

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


