Newer
Older
powermon_manager_sw / gui / gui_device_config.h
@Razvan Turiac Razvan Turiac on 8 Jul 6 KB Initial import
/* Copyright (C) 2020 - 2024, Thornwave Labs Inc
 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 * documentation files (the “Software”), to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * Attribution shall be given to Thornwave Labs Inc. and shall be made visible to the final user. 
 * 
 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef _GUI_DEVICE_CONFIG_H
#define _GUI_DEVICE_CONFIG_H


#include <gui_global.h>
#include <gui_parser.h>

#include <wx/listbook.h>

#include <powermon_config.h>



class GuiDeviceConfig: public wxDialog
{
public:
	GuiDeviceConfig(wxWindow* parent, wxWindowID id, const PowermonConfig &config, const Powermon &powermon);
	
	bool AcceptsFocus(void) const 
	{ 
		return false; 
	}

	const PowermonConfig& getConfiguration(void) const
	{
		return mConfig;
	}

private:
	enum
	{
		ID_CHOICE_SHUNT = wxID_HIGHEST + 1,
		ID_CHECKBOX_DISABLE_V2,
		ID_CHECKBOX_ENABLE_FEATURE,
		ID_CHECKBOX_ENABLE_GENERATOR,
		ID_CHOICE_FG_VOLTAGE,
		ID_TEXT_FG_CAPACITY,
		ID_TEXT_FG_CELLS,
		ID_CHOICE_FG_CHEMISTRY,
		ID_CHECK_MANUAL_DETECTION,
		ID_CHECK_VON_GENERATOR,
		ID_CHECKBOX_ENABLE_LIFEPO_CM,
		ID_CHOICE_LIFEPO_CM_VOLTAGE,
		ID_CHOICE_LIFEPO_CM_CELLS
	};

	const Powermon &mPowermon;
	PowermonConfig mConfig;

	wxListbook* mListBook;

	wxCheckBox* mWifiKeepApOnCheckBox;

	wxChoice* mShuntChoice;
	wxTextCtrl* mMaxShuntCurrentText;

	wxCheckBox* mAdcDisableV2CheckBox;
	wxCheckBox* mMeterVoltageSourceCheckBox;

	wxCheckBox* mAdcFlipCurrentSignCheckBox;

	wxCheckBox* mOcInitialStateCheckBox;
	wxCheckBox* mOcLatchRelayOnCheckBox;
	wxCheckBox* mOcInvertOutputCheckBox;

	wxTextCtrl* mOcConnectFilterText;

	wxChoice* mMfTerminalFunctionChoice;
	wxChoice* mLoggingModeChoice;

	wxCheckBox* mOcLvdEnableCheckBox;
	wxCheckBox* mOcLvdVoltageSourceCheckBox;
	wxTextCtrl* mOcLvdDisconnectThresholdText;
	wxTextCtrl* mOcLvdConnectThresholdText;
	wxTextCtrl* mOcLvdDisconnectFilterText;

	wxCheckBox* mOcOcdEnableCheckBox;
	wxTextCtrl* mOcOcdTripThresholdText;
	wxTextCtrl* mOcOcdTripFilterText;

	wxCheckBox* mOcHvdEnableCheckBox;
	wxCheckBox* mOcHvdVoltageSourceCheckBox;
	wxTextCtrl* mOcHvdDisconnectThresholdText;
	wxTextCtrl* mOcHvdConnectThresholdText;
	wxTextCtrl* mOcHvdDisconnectFilterText;

	wxCheckBox* mOcAutoOffEnableCheckBox;
	wxTextCtrl* mOcAutoOffHoursText;
	wxTextCtrl* mOcAutoOffMinutesText;
	wxTextCtrl* mOcAutoOffSecondsText;

	wxCheckBox* mOcAutoOnEnableCheckBox;
	wxTextCtrl* mOcAutoOnHoursText;
	wxTextCtrl* mOcAutoOnMinutesText;
	wxTextCtrl* mOcAutoOnSecondsText;

	wxCheckBox* mOcLtdEnableCheckBox;
	wxTextCtrl* mOcLtdDisconnectThresholdText;
	wxTextCtrl* mOcLtdConnectThresholdText;
	wxTextCtrl* mOcLtdDisconnectFilterText;

	wxCheckBox* mOcHtdEnableCheckBox;
	wxTextCtrl* mOcHtdDisconnectThresholdText;
	wxTextCtrl* mOcHtdConnectThresholdText;
	wxTextCtrl* mOcHtdDisconnectFilterText;


	wxCheckBox* mFgEnableCheckBox;
	wxCheckBox* mFgVoltageSourceCheckBox;
	wxChoice* mFgChemistryChoice;
	wxChoice* mFgBatteryVoltageChoice;
	wxBoxSizer* mFgCellCountSizer;
	wxTextCtrl* mFgCellCountText;
	wxTextCtrl* mFgCapacityText;

	wxCheckBox* mFgManualSyncCheckBox;

	wxBoxSizer* mFgSyncManualSizer;
	wxTextCtrl* mFgSyncVoltageThresholdText;
	wxTextCtrl* mFgSyncCurrentThresholdText;
	wxTextCtrl* mFgSyncFilterText;
	
	wxCheckBox* mOcFgDisconnectEnableCheckBox;
	wxTextCtrl* mOcFgDisconnectThresholdText;
	wxCheckBox* mOcFgConnectEnableCheckBox;
	wxTextCtrl* mOcFgConnectThresholdText;

	wxCheckBox* mOcGenEnableCheckBox;
	wxCheckBox* mOcGenVonEnableCheckBox;
	wxCheckBox* mOcGenVoltageSourceCheckBox;
	wxTextCtrl* mOcGenVonThresholdText;
	wxTextCtrl* mOcGenVonFilterText;
	wxCheckBox* mOcGenVoffEnableCheckBox;
	wxTextCtrl* mOcGenVoffThresholdText;
	wxCheckBox* mOcGenSoconEnableCheckBox;
	wxTextCtrl* mOcGenSoconThresholdText;
	wxCheckBox* mOcGenSocoffEnableCheckBox;
	wxTextCtrl* mOcGenSocoffThresholdText;
	wxTextCtrl* mOcGenTurnOffDelayText;

	wxBoxSizer* mOcGenVonSizer;
	wxBoxSizer* mOcGenVoffSizer;
	wxBoxSizer* mOcGenSoconSizer;
	wxBoxSizer* mOcGenSocoffSizer;

	wxCheckBox* mOcLiFePOEnableCheckBox;
	wxChoice* mOcLiFePOBatteryVoltageChoice;
	wxBoxSizer* mOcLiFePOCellCountSizer;
	wxTextCtrl* mOcLiFePOCellCountText;
	wxTextCtrl* mOcLiFePOBatteryCapacityText;

	wxButton* mSaveButton;
	wxButton* mCancelButton;

	
	void OnChoiceShuntChanged(wxCommandEvent &event);

	void OnChoiceBatteryVoltageChanged(wxCommandEvent &event);
	void OnChoiceBatteryChemistryChanged(wxCommandEvent &event);

	void OnTextBatteryCapacityChanged(wxCommandEvent &event);
	void OnTextBatteryCellsChanged(wxCommandEvent &event);
	
	void OnDisableV2CheckBoxClicked(wxCommandEvent &event);
	void OnManualCheckBoxClicked(wxCommandEvent &event);

	void OnOcGenCheckBoxClicked(wxCommandEvent &event);
	
	void OnButtonSaveClicked(wxCommandEvent &event);

	void OnOcFeatureEnableCheckBoxClicked(wxCommandEvent &event);
	void OnOcGenEnableCheckBoxClicked(wxCommandEvent &event);

	void OnOcLiFePOEnableCheckBoxClicked(wxCommandEvent &event);
	void OnChoiceLiFePOBatteryVoltageChanged(wxCommandEvent &event);
	void OnTextLiFePOCellsChanged(wxCommandEvent &event);
	
	void OnClose(wxCloseEvent &event);

	void checkCellCount(uint32_t cells, uint32_t chemistry_index)
	{
		uint32_t max_cells = 0;
		switch(chemistry_index)
		{
			case 0:
			case 1: max_cells = 24; break;

			case 2:
			case 3:
			case 4: max_cells = 16; break;
		}

		if ((cells == 0) || (cells > max_cells))
			throw ParserException(wxString::Format(wxT("Battery Cell Count should be between 1 and %u"), max_cells));
	}

	void updateBatteryCellCount(void);
	void updateFullChargeDetection(void);

	DECLARE_EVENT_TABLE()
};


#endif