-
Notifications
You must be signed in to change notification settings - Fork 2
/
blusb_gui.h
141 lines (123 loc) · 5.01 KB
/
blusb_gui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*****************************************************************************/
/* blusb_gui.h : main program definitions */
/*****************************************************************************/
/*
Copyright (C) 2019 Hermann Seib
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, version 3.
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.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _blusb_gui_h__included_
#define _blusb_gui_h__included_
#include "BlUsbDev.h"
#include "MainFrm.h"
#include "KbdGuiLayout.h"
/*****************************************************************************/
/* CBlusbGuiApp : main program class */
/*****************************************************************************/
class CBlusbGuiApp : public wxApp
{
public:
CBlusbGuiApp();
virtual bool OnInit() wxOVERRIDE;
virtual int OnExit() wxOVERRIDE;
virtual void OnInitCmdLine(wxCmdLineParser& parser) wxOVERRIDE;
virtual bool OnCmdLineParsed(wxCmdLineParser& parser) wxOVERRIDE;
CMainFrame *GetMain() { return pMain; }
bool IsDevOpen() { return dev.IsOpen(); }
int EnableServiceMode()
{
int rc = dev.EnableServiceMode();
if (GetFwVersion() >= 0x0105) /* in V1.5++, it's always on. */
rc = BLUSB_SUCCESS;
inServiceMode = (rc >= BLUSB_SUCCESS);
return rc;
}
int DisableServiceMode()
{
inServiceMode = false;
return dev.DisableServiceMode();
}
bool InServiceMode() { return inServiceMode; }
int ReadVersion(wxUint8 *buffer, int buflen)
{ return dev.ReadVersion(buffer, buflen); }
int GetFwMajorVersion()
{ return dev.GetFwMajorVersion(); }
int GetFwMinorVersion()
{ return dev.GetFwMinorVersion(); }
int GetFwVersion()
{ return dev.GetFwVersion(); }
int ReadMatrixLayout(int &rows, int &cols);
int ReadMatrixPos(wxUint8 *buffer, int buflen)
{ return dev.ReadMatrix(buffer, buflen); }
int ReadPWM(wxUint8 &pwmUSB, wxUint8 &pwmBT)
{ return dev.ReadPWM(pwmUSB, pwmBT); }
int WritePWM(wxUint8 pwmUSB, wxUint8 pwmBT)
{ return dev.WritePWM(pwmUSB, pwmBT); }
KbdLayout &GetLayout() { return layout; }
void SetLayout(KbdLayout const &org) { layout = org; bCtlLayoutRead = false; }
KbdLayout &GetDefaultLayout(int nNum = -1) { return defaultLayout[nNum < 0 ? curDefaultLayout : nNum]; }
void SetDefaultLayout(int nNum = 0) { curDefaultLayout = nNum; }
void SetDefaultLayout(KbdGui const &gui);
int GetDefaultLayouts() { return _countof(defaultLayout); }
int ReadLayout(KbdLayout *p = NULL);
int ReadLayout(wxString const &filename, KbdLayout *p = NULL);
int WriteLayout(KbdLayout *p = NULL);
int WriteLayout(wxString const &filename, bool bNative = true, KbdLayout *p = NULL);
bool IsCtlLayoutRead() { return bCtlLayoutRead; }
bool IsLayoutModified() { return layout.IsModified(); }
void SetLayoutModified(bool bOn = true) { layout.SetModified(bOn); }
int ReadDebounce() { return dev.ReadDebounce(); }
int WriteDebounce(int nDebounce) { return dev.WriteDebounce(nDebounce); }
public:
bool ReadConfig(wxString const &key, wxString *str, wxString const &defval = "")
{ return pConfig->Read(key, str, defval); }
bool ReadConfig(wxString const &key, long *l, long const defval = 0)
{ return pConfig->Read(key, l, defval); }
bool WriteConfig(wxString const &key, wxString const &str)
{ return pConfig->Write(key, str); }
bool WriteConfig(wxString const &key, long const l)
{ return pConfig->Write(key, l); }
private:
wxDECLARE_EVENT_TABLE();
private:
void OnActivateApp(wxActivateEvent& event);
private:
BlUsbDev dev;
bool inServiceMode;
KbdLayout layout, defaultLayout[2];
int curDefaultLayout;
CMainFrame *pMain;
wxConfigBase *pConfig;
bool bCtlLayoutRead; // flag whether current layout read from keyboard
int nDevMatrixRows, nDevMatrixCols; // attached device's matrix layout
};
wxDECLARE_APP(CBlusbGuiApp);
CBlusbGuiApp *GetApp();
/*****************************************************************************/
/* CNoServiceMode : little helper class to inhibit service mode */
/*****************************************************************************/
class CNoServiceMode
{
public:
CNoServiceMode()
{
bInServiceMode = GetApp()->InServiceMode();
if (bInServiceMode)
GetApp()->DisableServiceMode();
}
~CNoServiceMode()
{
if (bInServiceMode)
GetApp()->EnableServiceMode();
}
protected:
bool bInServiceMode;
};
#endif // !defined(_blusb_gui_h__included_)