Newer
Older
powermon_manager_sw / gui / gui_device.h
@Razvan Turiac Razvan Turiac on 8 Jul 4 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_H
#define _GUI_DEVICE_H


#include <wx/file.h>

#include <gui_global.h>
#include <gui_app.h>
#include <gui_chart.h>
#include <gui_stats.h>
#include <gui_fg_stats.h>

#include <powermon.h>



class GuiDevice: public wxFrame
{
public:
	GuiDevice(wxWindow* parent, const Powermon::DeviceIdentifier &id, PowermonScanner* scanner);
	~GuiDevice();
	
private:
	enum
	{
		ID_MONITOR_DATA_TIMER = wxID_HIGHEST + 1,
		ID_SYNC_LOG_TIMER,

		ID_MENU_SYNC_LOG,
		ID_MENU_CLEAR_LOCAL_LOG,

		ID_MENU_PAIR,

		ID_MENU_CONFIGURATION,
		ID_MENU_WIFI_SETUP,
		ID_MENU_RESET_FACTORY,

		ID_MENU_UNLOCK,
		ID_MENU_SET_USER_PASSWORD,
		ID_MENU_SET_MASTER_PASSWORD,
		ID_MENU_RENAME,
		ID_MENU_SET_TIME,

		ID_MENU_ZERO_OFFSET,
		ID_MENU_CALIBRATE_CURRENT,

		ID_MENU_RESET_EM,
		ID_MENU_RESET_CM,
		ID_MENU_VIEW_STATS,
		ID_MENU_VIEW_FG_STATS,
		ID_MENU_FORCE_FG_SYNC,

		ID_MENU_POWER_CONTROL,
		
		ID_MENU_DATA_LOG,
		ID_MENU_TIMERS,
	};

	Powermon &mPowermon;

	wxColour mMonitorBackgroundColor;
	wxMenuBar* mMenuBar;
	wxMenu* mDeviceMenu;
	wxMenu* mSettingsMenu;

	GuiChart* mChart;

	wxTimer* mMonitorDataTimer;
	wxTimer* mSyncLogTimer;

	Powermon::MonitorData mMonitorData;
	bool mMonitorDataValid;
	wxPanel* mMonitorPanel;

	bool mSyncEnabled;
	volatile bool mSyncInProgress;

	size_t mSyncTotalSize;
	size_t mSyncCompletedSize;
	size_t mFileSize;
	wxFile mLogFile;
	
	std::vector<Powermon::LogFileDescriptor> mLogFiles;

	GuiStats* mStatsDialog;
	GuiFgStats* mFgStatsDialog;
	
	void enableMenus(bool state);
	void startSync(void);
	void stopSync(void);

	void updateTitle(void);
	void updateStatusBar(void); 

	void deviceUnlock(bool disconnect_on_failure);
	void startDevice(void);

	void readFile(void);
	void readFileBlock(void);
	
	void OnMenuDeviceViewStats(wxCommandEvent &event);
	void OnMenuDeviceViewFgStats(wxCommandEvent &event);

	void OnMenuSettingsZeroCurrentOffset(wxCommandEvent &event);
	void OnMenuSettingsCalibrateCurrent(wxCommandEvent &event);

	void OnMenuDeviceResetEM(wxCommandEvent &event);
	void OnMenuDeviceResetCM(wxCommandEvent &event);

	void OnMenuSettingsUnlock(wxCommandEvent &event);
	void OnMenuSettingsSetUserPassword(wxCommandEvent &event);
	void OnMenuSettingsSetMasterPassword(wxCommandEvent &event);

	void OnMenuDevicePowerControl(wxCommandEvent &event);

	void OnMenuDeviceSyncLog(wxCommandEvent &event);
	void OnMenuDeviceDataLog(wxCommandEvent &event);
	void OnMenuDeviceClearLocalLog(wxCommandEvent &event);
	
	void OnMenuDevicePair(wxCommandEvent &event);
	void OnMenuDeviceDisconnect(wxCommandEvent &event);

	void OnMenuDeviceTimers(wxCommandEvent &event);	
	void OnMenuSettingsConfiguration(wxCommandEvent &event);
	void OnMenuSettingsWifiSetup(wxCommandEvent &event);
	void OnMenuSettingsResetFactory(wxCommandEvent &event);
	void OnMenuSettingsSetTime(wxCommandEvent &event);
	void OnMenuSettingsRename(wxCommandEvent &event);
	void OnMenuSettingsForceFgSync(wxCommandEvent &event);

	void OnMenuHelpAbout(wxCommandEvent &event);

	void OnClose(wxCloseEvent &event);

	void OnGuiEvent(GuiEvent &event);

	void OnMonitorDataTimerEvent(wxTimerEvent &event);
	void OnSyncLogTimerEvent(wxTimerEvent &event);

	void OnMonitorPaint(wxPaintEvent &event);
	void OnEraseBackGround(wxEraseEvent& event){}
	
	DECLARE_EVENT_TABLE()
};

#endif