00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <wx/config.h>
00010 #include <wx/confbase.h>
00011
00012 #include "ApplicationSettings.h"
00013
00014 const wxString& BASE_CONFIG_SETTINGS= _T( "/APPLICATION_SETTINGS");
00015 const wxString& SETTINGS_FILENAME= _T( "N1568Demo");
00016
00017
00018 ApplicationSettings::ApplicationSettings() {
00019 #if defined(__WXMSW__)
00020 this->m_communication_device_id= _T("COM1");
00021 #elif defined(__WXMAC__)
00022 this->m_communication_device_id= _T("???");
00023 #elif defined(__UNIX__)
00024 this->m_communication_device_id= _T("/dev/ttyUSB0");
00025 #endif
00026 this->m_first_visible_channel= 0;
00027 this->m_last_visible_channel= MAX_CHANNELS- 1;
00028 this->m_default_module_address= 0;
00029 this->m_default_mux_out= 0;
00030 this->m_is_logger_enabled= true;
00031 this->m_is_logger_visible= true;
00032
00033 }
00034
00035 ApplicationSettings::~ApplicationSettings() {
00036
00037 }
00038
00039 bool ApplicationSettings::ReadSettings( ) {
00040
00041 wxConfig *config = new wxConfig( SETTINGS_FILENAME);
00042
00043
00044
00045 wxString section= BASE_CONFIG_SETTINGS+ _T( "COMMUNICATION/");
00046 this->m_communication_device_id= config->Read( section+ _T( "DEVICE_ID"), _T(""));
00047
00048
00049 section= BASE_CONFIG_SETTINGS+ _T( "BOARD/");
00050 this->m_first_visible_channel= config->Read( section+ _T( "FIRST_VISIBLE_CHANNEL"), 0L);
00051 this->m_last_visible_channel= config->Read( section+ _T( "LAST_VISIBLE_CHANNEL"), (long)( MAX_CHANNELS- 1));
00052 this->m_default_module_address= config->Read( section+ _T( "DEFAULT_MODULE_ADDRESS"), 0L);
00053 this->m_default_mux_out= config->Read( section+ _T( "DEFAULT_MUX_OUT"), 0L);
00054
00055
00056 section= BASE_CONFIG_SETTINGS+ _T( "APPLICATION/");
00057 this->m_is_logger_enabled= config->Read( section+ _T( "IS_LOGGER_ENABLED"), 1L)!= 0;
00058 this->m_is_logger_visible= config->Read( section+ _T( "IS_LOGGER_VISIBLE"), 1L)!= 0;
00059
00060 delete config;
00061 return true;
00062 }
00063
00064 bool ApplicationSettings::WriteSettings( ) {
00065
00066 wxConfig *config = new wxConfig( SETTINGS_FILENAME);
00067
00068
00069
00070 wxString section= BASE_CONFIG_SETTINGS+ _T( "COMMUNICATION/");
00071 config->Write( section+ _T( "DEVICE_ID"), this->m_communication_device_id);
00072
00073
00074 section= BASE_CONFIG_SETTINGS+ _T( "BOARD/");
00075 config->Write( section+ _T( "FIRST_VISIBLE_CHANNEL"), this->m_first_visible_channel);
00076 config->Write( section+ _T( "LAST_VISIBLE_CHANNEL"), this->m_last_visible_channel);
00077 config->Write( section+ _T( "DEFAULT_MODULE_ADDRESS"), this->m_default_module_address);
00078 config->Write( section+ _T( "DEFAULT_MUX_OUT"), this->m_default_mux_out);
00079
00080
00081 section= BASE_CONFIG_SETTINGS+ _T( "APPLICATION/");
00082 config->Write( section+ _T( "IS_LOGGER_ENABLED"), this->m_is_logger_enabled? 1: 0);
00083 config->Write( section+ _T( "IS_LOGGER_VISIBLE"), this->m_is_logger_visible? 1: 0);
00084
00085 delete config;
00086 return true;
00087 }