2013-05-26 04:36:44 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2011 jean-pierre.charras
|
2024-02-02 14:20:36 +00:00
|
|
|
* Copyright (C) 1992-2024 Kicad Developers, see AUTHORS.txt for contributors.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2019-05-01 18:57:59 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2013-05-26 04:36:44 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2019-05-01 18:57:59 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-06-07 22:26:55 +00:00
|
|
|
#include <wx/choicdlg.h>
|
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/msgdlg.h>
|
2024-03-20 12:59:36 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2021-06-07 22:26:55 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
#include <bitmaps.h>
|
2021-10-08 14:44:44 +00:00
|
|
|
#include <calculator_panels/panel_regulator.h>
|
|
|
|
#include <class_regulator_data.h>
|
|
|
|
#include <dialogs/dialog_regulator_form.h>
|
|
|
|
#include <pcb_calculator_settings.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
extern double DoubleFromString( const wxString& TextValue );
|
2020-08-23 13:01:52 +00:00
|
|
|
|
2021-10-05 15:32:31 +00:00
|
|
|
// extension of pcb_calculator data filename:
|
|
|
|
static const wxString DataFileNameExt( wxT( "pcbcalc" ) );
|
|
|
|
|
|
|
|
|
2023-01-27 22:41:05 +00:00
|
|
|
PANEL_REGULATOR::PANEL_REGULATOR( wxWindow* parent, wxWindowID id, const wxPoint& pos,
|
|
|
|
const wxSize& size, long style, const wxString& name ) :
|
2021-10-10 15:03:24 +00:00
|
|
|
PANEL_REGULATOR_BASE( parent, id, pos, size, style, name ),
|
|
|
|
m_RegulatorListChanged( false )
|
2021-10-03 16:01:40 +00:00
|
|
|
{
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bitmapRegul3pins->SetBitmap( KiBitmapBundle( BITMAPS::regul_3pins ) );
|
|
|
|
m_bitmapRegul4pins->SetBitmap( KiBitmapBundle( BITMAPS::regul ) );
|
2021-10-03 16:01:40 +00:00
|
|
|
|
|
|
|
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
|
|
|
|
SelectLastSelectedRegulator();
|
2021-10-09 07:07:18 +00:00
|
|
|
|
|
|
|
// Needed on wxWidgets 3.0 to ensure sizers are correctly set
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2021-10-03 16:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PANEL_REGULATOR::~PANEL_REGULATOR()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2021-10-08 16:30:36 +00:00
|
|
|
void PANEL_REGULATOR::ThemeChanged()
|
|
|
|
{
|
|
|
|
// Update the bitmaps
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bitmapRegul3pins->SetBitmap( KiBitmapBundle( BITMAPS::regul_3pins ) );
|
|
|
|
m_bitmapRegul4pins->SetBitmap( KiBitmapBundle( BITMAPS::regul ) );
|
2021-10-08 16:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnRegulatorCalcButtonClick( wxCommandEvent& event )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
RegulatorsSolve();
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnRegulatorResetButtonClick( wxCommandEvent& event )
|
2019-11-10 09:36:26 +00:00
|
|
|
{
|
2024-03-20 12:59:36 +00:00
|
|
|
m_resTolVal->SetValue( wxT( DEFAULT_REGULATOR_RESTOL ) );
|
|
|
|
|
|
|
|
m_r1MinVal->SetValue( wxT( "" ) );
|
|
|
|
m_r1TypVal->SetValue( wxT( DEFAULT_REGULATOR_R1 ) );
|
|
|
|
m_r1MaxVal->SetValue( wxT( "" ) );
|
|
|
|
|
|
|
|
m_r2MinVal->SetValue( wxT( "" ) );
|
|
|
|
m_r2TypVal->SetValue( wxT( DEFAULT_REGULATOR_R2 ) );
|
|
|
|
m_r2MaxVal->SetValue( wxT( "" ) );
|
|
|
|
|
|
|
|
m_vrefMinVal->SetValue( wxT( DEFAULT_REGULATOR_VREF_MIN ) );
|
|
|
|
m_vrefTypVal->SetValue( wxT( DEFAULT_REGULATOR_VREF_TYP ) );
|
|
|
|
m_vrefMaxVal->SetValue( wxT( DEFAULT_REGULATOR_VREF_MAX ) );
|
|
|
|
|
|
|
|
m_voutMinVal->SetValue( wxT( "" ) );
|
|
|
|
m_voutTypVal->SetValue( wxT( DEFAULT_REGULATOR_VOUT_TYP ) );
|
|
|
|
m_voutMaxVal->SetValue( wxT( "" ) );
|
|
|
|
|
|
|
|
m_iadjTypVal->SetValue( wxT( DEFAULT_REGULATOR_IADJ_TYP ) );
|
|
|
|
m_iadjMaxVal->SetValue( wxT( DEFAULT_REGULATOR_IADJ_MAX ) );
|
|
|
|
|
|
|
|
m_tolTotalMin->SetValue( wxT( "" ) );
|
|
|
|
m_TolTotalMax->SetValue( wxT( "" ) );
|
|
|
|
|
|
|
|
m_choiceRegType->SetSelection( 1 );
|
|
|
|
m_rbRegulR1->SetValue( false );
|
|
|
|
m_rbRegulR2->SetValue( true );
|
2021-10-10 15:03:24 +00:00
|
|
|
m_rbRegulVout->SetValue( false );
|
2019-11-10 09:36:26 +00:00
|
|
|
RegulatorPageUpdate();
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::RegulatorPageUpdate()
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
switch( m_choiceRegType->GetSelection() )
|
|
|
|
{
|
2021-07-18 14:06:48 +00:00
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
m_bitmapRegul4pins->Show( true );
|
|
|
|
m_bitmapRegul3pins->Show( false );
|
2024-03-20 12:59:36 +00:00
|
|
|
|
|
|
|
m_RegulIadjTitle->Show( false );
|
|
|
|
m_iadjTypVal->Show( false );
|
|
|
|
m_iadjMaxVal->Show( false );
|
|
|
|
m_labelUnitsIadj->Show( false );
|
|
|
|
|
2021-07-18 14:06:48 +00:00
|
|
|
m_RegulFormula->SetLabel( wxT( "Vout = Vref * (R1 + R2) / R2" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
m_bitmapRegul4pins->Show( false );
|
|
|
|
m_bitmapRegul3pins->Show( true );
|
2024-03-20 12:59:36 +00:00
|
|
|
|
|
|
|
m_RegulIadjTitle->Show( true );
|
|
|
|
m_iadjTypVal->Show( true );
|
|
|
|
m_iadjMaxVal->Show( true );
|
|
|
|
m_labelUnitsIadj->Show( true );
|
|
|
|
|
2021-07-18 14:06:48 +00:00
|
|
|
m_RegulFormula->SetLabel( wxT( "Vout = Vref * (R1 + R2) / R1 + Iadj * R2" ) );
|
|
|
|
break;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
// The new icon size must be taken in account
|
2021-10-03 16:01:40 +00:00
|
|
|
GetSizer()->Layout();
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
// Enable/disable buttons:
|
|
|
|
bool enbl = m_choiceRegulatorSelector->GetCount() > 0;
|
|
|
|
m_buttonEditItem->Enable( enbl );
|
|
|
|
m_buttonRemoveItem->Enable( enbl );
|
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
Refresh();
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnRegulTypeSelection( wxCommandEvent& event )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
RegulatorPageUpdate();
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnRegulatorSelection( wxCommandEvent& event )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2021-10-10 15:03:24 +00:00
|
|
|
wxString name = m_choiceRegulatorSelector->GetStringSelection();
|
|
|
|
REGULATOR_DATA* item = m_RegulatorList.GetReg( name );
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
m_lastSelectedRegulatorName = item->m_Name;
|
|
|
|
m_choiceRegType->SetSelection( item->m_Type );
|
|
|
|
wxString value;
|
2024-03-20 12:59:36 +00:00
|
|
|
|
|
|
|
value.Printf( wxT( "%g" ), item->m_VrefMin );
|
|
|
|
m_vrefMinVal->SetValue( value );
|
|
|
|
value.Printf( wxT( "%g" ), item->m_VrefTyp );
|
|
|
|
m_vrefTypVal->SetValue( value );
|
|
|
|
value.Printf( wxT( "%g" ), item->m_VrefMax );
|
|
|
|
m_vrefMaxVal->SetValue( value );
|
|
|
|
|
|
|
|
value.Printf( wxT( "%g" ), item->m_IadjTyp );
|
|
|
|
m_iadjTypVal->SetValue( value );
|
|
|
|
|
|
|
|
value.Printf( wxT( "%g" ), item->m_IadjMax );
|
|
|
|
m_iadjMaxVal->SetValue( value );
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 14:06:48 +00:00
|
|
|
// Call RegulatorPageUpdate to enable/disable tools,
|
2013-05-26 04:36:44 +00:00
|
|
|
// even if no item selected
|
|
|
|
RegulatorPageUpdate();
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnDataFileSelection( wxCommandEvent& event )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
wxString fullfilename = GetDataFilename();
|
|
|
|
|
|
|
|
wxString wildcard;
|
2023-01-27 22:41:05 +00:00
|
|
|
wildcard.Printf( _( "PCB Calculator data file" ) + wxT( " (*.%s)|*.%s" ),
|
2019-08-10 08:05:13 +00:00
|
|
|
DataFileNameExt, DataFileNameExt );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2024-02-02 14:20:36 +00:00
|
|
|
wxWindow* topLevelParent = wxGetTopLevelParent( this );
|
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
// Must be wxFD_SAVE, otherwise you cannot assign a file name
|
|
|
|
wxFileDialog dlg( topLevelParent, _( "Select PCB Calculator Data File" ), wxEmptyString,
|
|
|
|
fullfilename, wildcard, wxFD_SAVE );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2021-10-10 15:03:24 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fullfilename = dlg.GetPath();
|
|
|
|
|
|
|
|
if( fullfilename == GetDataFilename() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetDataFilename( fullfilename );
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( wxFileExists( fullfilename ) && m_RegulatorList.GetCount() > 0 ) // Read file
|
|
|
|
{
|
2024-03-20 12:59:36 +00:00
|
|
|
if( wxMessageBox( _( "Do you want to load this file and replace current regulator list?" ),
|
|
|
|
wxASCII_STR( wxMessageBoxCaptionStr ), wxOK | wxCANCEL | wxCENTER, this )
|
|
|
|
!= wxOK )
|
2021-10-10 15:03:24 +00:00
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
2021-10-10 15:03:24 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ReadDataFile() )
|
|
|
|
{
|
|
|
|
m_RegulatorListChanged = false;
|
|
|
|
m_choiceRegulatorSelector->Clear();
|
|
|
|
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString msg;
|
2023-01-27 22:41:05 +00:00
|
|
|
msg.Printf( _( "Unable to read data file '%s'." ), fullfilename );
|
2013-05-26 04:36:44 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnAddRegulator( wxCommandEvent& event )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2024-02-02 17:47:34 +00:00
|
|
|
DIALOG_REGULATOR_FORM dlg( wxGetTopLevelParent( this ), wxEmptyString );
|
2021-07-21 21:37:49 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
REGULATOR_DATA* new_item = dlg.BuildRegulatorFromData();
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
// Add new item, if not existing
|
2021-07-18 14:06:48 +00:00
|
|
|
if( m_RegulatorList.GetReg( new_item->m_Name ) == nullptr )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
// Add item in list
|
|
|
|
m_RegulatorList.Add( new_item );
|
|
|
|
m_RegulatorListChanged = true;
|
|
|
|
m_choiceRegulatorSelector->Clear();
|
|
|
|
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
|
|
|
|
m_lastSelectedRegulatorName = new_item->m_Name;
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-27 22:41:05 +00:00
|
|
|
wxMessageBox( _( "This regulator is already in list. Aborted" ) );
|
2013-05-26 04:36:44 +00:00
|
|
|
delete new_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnEditRegulator( wxCommandEvent& event )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
wxString name = m_choiceRegulatorSelector->GetStringSelection();
|
2021-10-10 15:03:24 +00:00
|
|
|
REGULATOR_DATA* item = m_RegulatorList.GetReg( name );
|
2021-07-18 14:06:48 +00:00
|
|
|
|
|
|
|
if( item == nullptr )
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
|
|
|
|
2024-02-02 17:47:34 +00:00
|
|
|
DIALOG_REGULATOR_FORM dlg( wxGetTopLevelParent( this ), name );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
dlg.CopyRegulatorDataToDialog( item );
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
2021-10-10 15:03:24 +00:00
|
|
|
REGULATOR_DATA* new_item = dlg.BuildRegulatorFromData();
|
2013-05-26 04:36:44 +00:00
|
|
|
m_RegulatorList.Replace( new_item );
|
|
|
|
|
|
|
|
m_RegulatorListChanged = true;
|
|
|
|
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::OnRemoveRegulator( wxCommandEvent& event )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2023-01-27 22:41:05 +00:00
|
|
|
wxString name = wxGetSingleChoice( _( "Remove Regulator" ), wxEmptyString,
|
2013-05-26 04:36:44 +00:00
|
|
|
m_RegulatorList.GetRegList() );
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_RegulatorList.Remove( name );
|
|
|
|
m_RegulatorListChanged = true;
|
|
|
|
m_choiceRegulatorSelector->Clear();
|
|
|
|
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( m_lastSelectedRegulatorName == name )
|
|
|
|
m_lastSelectedRegulatorName.Empty();
|
|
|
|
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::SelectLastSelectedRegulator()
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
// Find last selected in regulator list:
|
|
|
|
int idx = -1;
|
2021-07-18 14:06:48 +00:00
|
|
|
|
|
|
|
if( !m_lastSelectedRegulatorName.IsEmpty() )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < m_RegulatorList.GetCount(); ii++ )
|
2021-07-18 14:06:48 +00:00
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
if( m_RegulatorList.m_List[ii]->m_Name == m_lastSelectedRegulatorName )
|
|
|
|
{
|
|
|
|
idx = ii;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-18 14:06:48 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_choiceRegulatorSelector->SetSelection( idx );
|
|
|
|
wxCommandEvent event;
|
|
|
|
OnRegulatorSelection( event );
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:17:40 +00:00
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
void PANEL_REGULATOR::OnCopyCB( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
// This data objects are held by the clipboard,
|
|
|
|
// so do not delete them in the app.
|
|
|
|
wxTheClipboard->SetData( new wxTextDataObject( m_textPowerComment->GetValue() ) );
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
void PANEL_REGULATOR::RegulatorsSolve()
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
int id;
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( m_rbRegulR1->GetValue() )
|
2021-07-18 14:06:48 +00:00
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
id = 0; // for R1 calculation
|
2021-07-18 14:06:48 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
else if( m_rbRegulR2->GetValue() )
|
2021-07-18 14:06:48 +00:00
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
id = 1; // for R2 calculation
|
2021-07-18 14:06:48 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
else if( m_rbRegulVout->GetValue() )
|
2021-07-18 14:06:48 +00:00
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
id = 2; // for Vout calculation
|
2021-07-18 14:06:48 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT("Selection error" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
double restol;
|
|
|
|
double r1min, r1typ, r1max;
|
|
|
|
double r2min, r2typ, r2max;
|
|
|
|
double vrefmin, vreftyp, vrefmax;
|
|
|
|
double voutmin, vouttyp, voutmax, voutnom;
|
|
|
|
double toltotalmin, toltotalmax;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
wxString txt;
|
|
|
|
|
|
|
|
m_RegulMessage->SetLabel( wxEmptyString);
|
|
|
|
|
|
|
|
// Convert r1 and r2 in ohms
|
|
|
|
int r1scale = 1000;
|
|
|
|
int r2scale = 1000;
|
|
|
|
|
|
|
|
// Read values from panel:
|
2024-03-20 12:59:36 +00:00
|
|
|
txt = m_resTolVal->GetValue();
|
|
|
|
restol = DoubleFromString( txt ) / 100;
|
|
|
|
|
|
|
|
txt = m_r1TypVal->GetValue();
|
|
|
|
r1typ = DoubleFromString( txt ) * r1scale;
|
|
|
|
|
|
|
|
txt = m_r2TypVal->GetValue();
|
|
|
|
r2typ = DoubleFromString( txt ) * r2scale;
|
|
|
|
|
|
|
|
txt = m_vrefMinVal->GetValue();
|
|
|
|
vrefmin = DoubleFromString( txt );
|
|
|
|
txt = m_vrefTypVal->GetValue();
|
|
|
|
vreftyp = DoubleFromString( txt );
|
|
|
|
txt = m_vrefMaxVal->GetValue();
|
|
|
|
vrefmax = DoubleFromString( txt );
|
|
|
|
|
|
|
|
txt = m_voutTypVal->GetValue();
|
|
|
|
vouttyp = DoubleFromString( txt );
|
|
|
|
voutnom = vouttyp;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
// Some tests:
|
2024-03-20 12:59:36 +00:00
|
|
|
if( ( vouttyp < vrefmin || vouttyp < vreftyp || vouttyp < vrefmax ) && id != 2 )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2023-01-27 22:41:05 +00:00
|
|
|
m_RegulMessage->SetLabel( _( "Vout must be greater than vref" ) );
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
if( vrefmin == 0.0 || vreftyp == 0.0 || vrefmax == 0.0 )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2021-07-18 14:06:48 +00:00
|
|
|
m_RegulMessage->SetLabel( _( "Vref set to 0 !" ) );
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
if( vrefmin > vreftyp || vreftyp > vrefmax )
|
|
|
|
{
|
|
|
|
m_RegulMessage->SetLabel( _( "Vref must VrefMin < VrefTyp < VrefMax" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( r1typ < 0 && id != 0 ) || ( r2typ <= 0 && id != 1 ) )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2023-01-27 22:41:05 +00:00
|
|
|
m_RegulMessage->SetLabel( _( "Incorrect value for R1 R2" ) );
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate
|
|
|
|
if( m_choiceRegType->GetSelection() == 1)
|
|
|
|
{
|
|
|
|
// 3 terminal regulator
|
2024-03-20 12:59:36 +00:00
|
|
|
txt = m_iadjTypVal->GetValue();
|
|
|
|
double iadjtyp = DoubleFromString( txt );
|
|
|
|
txt = m_iadjMaxVal->GetValue();
|
|
|
|
double iadjmax = DoubleFromString( txt );
|
|
|
|
|
|
|
|
if( iadjtyp > iadjmax )
|
|
|
|
{
|
|
|
|
m_RegulMessage->SetLabel( _( "Iadj must IadjTyp < IadjMax" ) );
|
|
|
|
return;
|
|
|
|
}
|
2021-07-18 14:06:48 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
// iadj is given in micro amp, so convert it in amp.
|
2024-03-20 12:59:36 +00:00
|
|
|
iadjtyp /= 1000000;
|
|
|
|
iadjmax /= 1000000;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
2021-07-18 14:06:48 +00:00
|
|
|
case 0:
|
2024-03-20 12:59:36 +00:00
|
|
|
// typical formula
|
|
|
|
r1typ = vreftyp * r2typ / ( vouttyp - vreftyp - ( r2typ * iadjtyp ) );
|
2021-07-18 14:06:48 +00:00
|
|
|
break;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2021-07-18 14:06:48 +00:00
|
|
|
case 1:
|
2024-03-20 12:59:36 +00:00
|
|
|
// typical formula
|
|
|
|
r2typ = ( vouttyp - vreftyp ) / ( iadjtyp + ( vreftyp / r1typ ) );
|
2021-07-18 14:06:48 +00:00
|
|
|
break;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2021-07-18 14:06:48 +00:00
|
|
|
case 2:
|
2024-03-20 12:59:36 +00:00
|
|
|
// typical formula
|
|
|
|
vouttyp = vreftyp * ( r1typ + r2typ ) / r1typ;
|
|
|
|
voutnom = vouttyp;
|
|
|
|
vouttyp += r2typ * iadjtyp;
|
2021-07-18 14:06:48 +00:00
|
|
|
break;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
2024-03-20 12:59:36 +00:00
|
|
|
|
|
|
|
r1min = r1typ - r1typ * restol;
|
|
|
|
r1max = r1typ + r1typ * restol;
|
|
|
|
|
|
|
|
r2min = r2typ - r2typ * restol;
|
|
|
|
r2max = r2typ + r2typ * restol;
|
|
|
|
|
|
|
|
voutmin = vrefmin * ( r1max + r2min ) / r1max;
|
|
|
|
voutmin += r2min * iadjtyp;
|
|
|
|
|
|
|
|
voutmax = vrefmax * ( r1min + r2max ) / r1min;
|
|
|
|
voutmax += r2typ * iadjmax;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Standard 4 terminal regulator
|
|
|
|
switch( id )
|
|
|
|
{
|
2024-03-20 12:59:36 +00:00
|
|
|
case 0:
|
|
|
|
// typical formula
|
|
|
|
r1typ = ( vouttyp / vreftyp - 1 ) * r2typ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
// typical formula
|
|
|
|
r2typ = r1typ / ( vouttyp / vreftyp - 1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
// typical formula
|
|
|
|
vouttyp = vreftyp * ( r1typ + r2typ ) / r2typ;
|
|
|
|
voutnom = vouttyp;
|
|
|
|
break;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
2024-03-20 12:59:36 +00:00
|
|
|
|
|
|
|
r1min = r1typ - r1typ * restol;
|
|
|
|
r1max = r1typ + r1typ * restol;
|
|
|
|
|
|
|
|
r2min = r2typ - r2typ * restol;
|
|
|
|
r2max = r2typ + r2typ * restol;
|
|
|
|
|
|
|
|
voutmin = vrefmin * ( r1min + r2max ) / r2max;
|
|
|
|
voutmax = vrefmax * ( r1max + r2min ) / r2min;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
toltotalmin = voutmin / voutnom * 100.0 - 100.0;
|
|
|
|
toltotalmax = voutmax / voutnom * 100.0 - 100.0;
|
|
|
|
|
2021-07-18 14:06:48 +00:00
|
|
|
// write values to panel:
|
2024-03-20 12:59:36 +00:00
|
|
|
txt.Printf( wxT( "%g" ), round_to( r1min / r1scale ) );
|
|
|
|
m_r1MinVal->SetValue( txt );
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( r1typ / r1scale ) );
|
|
|
|
m_r1TypVal->SetValue( txt );
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( r1max / r1scale ) );
|
|
|
|
m_r1MaxVal->SetValue( txt );
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( r2min / r2scale ) );
|
|
|
|
m_r2MinVal->SetValue( txt );
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( r2typ / r2scale ) );
|
|
|
|
m_r2TypVal->SetValue( txt );
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( r2max / r2scale ) );
|
|
|
|
m_r2MaxVal->SetValue( txt );
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( voutmin ) );
|
|
|
|
m_voutMinVal->SetValue( txt );
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( vouttyp ) );
|
|
|
|
m_voutTypVal->SetValue( txt );
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( voutmax ) );
|
|
|
|
m_voutMaxVal->SetValue( txt );
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( toltotalmin, 0.01 ) );
|
|
|
|
m_tolTotalMin->SetValue( txt );
|
|
|
|
txt.Printf( wxT( "%g" ), round_to( toltotalmax, 0.01 ) );
|
|
|
|
m_TolTotalMax->SetValue( txt );
|
|
|
|
|
|
|
|
txt = wxString::Format( "%gV [%gV .. %gV]", round_to( vouttyp, 0.01 ),
|
|
|
|
round_to( voutmin, 0.01 ), round_to( voutmax, 0.01 ) );
|
|
|
|
m_textPowerComment->SetValue( txt );
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 10:40:38 +00:00
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
void PANEL_REGULATOR::LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg )
|
2020-08-24 10:40:38 +00:00
|
|
|
{
|
2024-03-20 12:59:36 +00:00
|
|
|
m_resTolVal->SetValue( aCfg->m_Regulators.resTol );
|
2020-08-24 10:40:38 +00:00
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
m_r1TypVal->SetValue( aCfg->m_Regulators.r1 );
|
|
|
|
m_r2TypVal->SetValue( aCfg->m_Regulators.r2 );
|
2020-08-24 10:40:38 +00:00
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
m_vrefMinVal->SetValue( aCfg->m_Regulators.vrefMin );
|
|
|
|
m_vrefTypVal->SetValue( aCfg->m_Regulators.vrefTyp );
|
|
|
|
m_vrefMaxVal->SetValue( aCfg->m_Regulators.vrefMax );
|
2021-10-03 16:01:40 +00:00
|
|
|
|
2024-03-20 12:59:36 +00:00
|
|
|
m_voutTypVal->SetValue( aCfg->m_Regulators.voutTyp );
|
|
|
|
|
|
|
|
m_iadjTypVal->SetValue( aCfg->m_Regulators.iadjTyp );
|
|
|
|
m_iadjMaxVal->SetValue( aCfg->m_Regulators.iadjMax );
|
2021-10-08 16:30:36 +00:00
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
SetDataFilename( aCfg->m_Regulators.data_file );
|
|
|
|
m_lastSelectedRegulatorName = aCfg->m_Regulators.selected_regulator;
|
|
|
|
m_choiceRegType->SetSelection( aCfg->m_Regulators.type );
|
|
|
|
|
|
|
|
wxRadioButton* regprms[3] = { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout };
|
|
|
|
|
|
|
|
if( aCfg->m_Regulators.last_param >= 3 )
|
|
|
|
aCfg->m_Regulators.last_param = 0;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 3; ii++ )
|
|
|
|
regprms[ii]->SetValue( aCfg->m_Regulators.last_param == ii );
|
2024-03-20 12:59:36 +00:00
|
|
|
|
|
|
|
RegulatorPageUpdate();
|
2021-10-03 16:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-08 16:30:36 +00:00
|
|
|
void PANEL_REGULATOR::SaveSettings( PCB_CALCULATOR_SETTINGS *aCfg )
|
|
|
|
{
|
2024-03-20 12:59:36 +00:00
|
|
|
aCfg->m_Regulators.resTol = m_resTolVal->GetValue();
|
|
|
|
|
|
|
|
aCfg->m_Regulators.r1 = m_r1TypVal->GetValue();
|
|
|
|
aCfg->m_Regulators.r2 = m_r2TypVal->GetValue();
|
|
|
|
|
|
|
|
aCfg->m_Regulators.vrefMin = m_vrefMinVal->GetValue();
|
|
|
|
aCfg->m_Regulators.vrefTyp = m_vrefTypVal->GetValue();
|
|
|
|
aCfg->m_Regulators.vrefMax = m_vrefMaxVal->GetValue();
|
|
|
|
|
|
|
|
m_voutTypVal->SetValue( aCfg->m_Regulators.voutTyp );
|
|
|
|
|
|
|
|
aCfg->m_Regulators.iadjTyp = m_iadjTypVal->GetValue();
|
|
|
|
aCfg->m_Regulators.iadjMax = m_iadjMaxVal->GetValue();
|
|
|
|
|
2023-04-24 07:11:03 +00:00
|
|
|
aCfg->m_Regulators.data_file = GetDataFilename();
|
|
|
|
aCfg->m_Regulators.selected_regulator = m_lastSelectedRegulatorName;
|
|
|
|
aCfg->m_Regulators.type = m_choiceRegType->GetSelection();
|
|
|
|
|
|
|
|
wxRadioButton* regprms[3] = { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout };
|
|
|
|
|
|
|
|
aCfg->m_Regulators.last_param = 0;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 3; ii++ )
|
|
|
|
{
|
|
|
|
if( regprms[ii]->GetValue() )
|
|
|
|
{
|
|
|
|
aCfg->m_Regulators.last_param = ii;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-08 16:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-03 16:01:40 +00:00
|
|
|
const wxString PANEL_REGULATOR::GetDataFilename()
|
|
|
|
{
|
|
|
|
if( m_regulators_fileNameCtrl->GetValue().IsEmpty() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
wxFileName fn( m_regulators_fileNameCtrl->GetValue() );
|
|
|
|
fn.SetExt( DataFileNameExt );
|
|
|
|
return fn.GetFullPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_REGULATOR::SetDataFilename( const wxString& aFilename )
|
|
|
|
{
|
|
|
|
if( aFilename.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_regulators_fileNameCtrl->SetValue( wxEmptyString );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFileName fn( aFilename );
|
|
|
|
fn.SetExt( DataFileNameExt );
|
|
|
|
m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() );
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 12:59:36 +00:00
|
|
|
|
|
|
|
double PANEL_REGULATOR::round_to( double value, double precision )
|
|
|
|
{
|
|
|
|
return std::round( value / precision ) * precision;
|
|
|
|
}
|