-
Notifications
You must be signed in to change notification settings - Fork 0
/
wyvern.cpp
272 lines (252 loc) · 9.51 KB
/
wyvern.cpp
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#include <iostream>
#include <Windows.h>
#include "control.hpp"
#include "structs.hpp"
#include "ascii/asciiplotter.h"
#include "CLI11.hpp"
using namespace std;
void print_system_info(Control ctrl) {
cout << "Wyvern v. master\n";
cout << "System firmware: " << ctrl.firmware_name() << '\n';
cout << "EC dump:\n";
ctrl.dump_ec();
}
void print_fan_info(Control ctrl, bool pretty = false) {
cout << "CPU fan speed: current " << ctrl.cpu_fan_rpm() << " RPM, target " << ctrl.cpu_fan_percent() << "%" << endl;
cout << "GPU fan speed: current " << ctrl.gpu_fan_rpm() << " RPM, target " << ctrl.gpu_fan_percent() << "%" << endl;
if (pretty) {
cout << "Current mode: ";
}
if (ctrl.coolerboost_get()) {
cout << "coolerboost\n";
}
else if (ctrl.silent_get()) {
cout << "silent\n";
}
else if (!ctrl.custom_curve_get()) {
cout << "auto\n";
}
else {
cout << "custom\n";
if (pretty) {
FanCurve cur_cpu = ctrl.cpu_fan_curve_get();
FanCurve cur_gpu = ctrl.gpu_fan_curve_get();
vector<double> cpu_temp;
vector<double> cpu_speed;
vector<double> gpu_temp;
vector<double> gpu_speed;
for (int i = 0; i < 6; i++) {
cpu_temp.push_back(cur_cpu.point[i].temp);
cpu_speed.push_back(cur_cpu.point[i].speed);
gpu_temp.push_back(cur_gpu.point[i].temp);
gpu_speed.push_back(cur_gpu.point[i].speed);
}
AsciiPlotter plotter("Fan speeds", 40, 15);
plotter.addPlot(vector<double>{100}, vector<double>{150}, " ", ' ');
plotter.addPlot(cpu_temp, cpu_speed, "CPU", 'c');
plotter.addPlot(gpu_temp, gpu_speed, "GPU", 'g');
plotter.legend();
plotter.xlabel("Deg (C)");
plotter.show();
}
}
}
int main(int argc, char** argv)
{
CLI::App app{ "Wyvern" };
app.require_subcommand(0, 1);
CLI::App* version_app = app.add_subcommand("version", "Information about system and program");
CLI::App* fan_app = app.add_subcommand("fan", "Fan management");
CLI::Option* fan_set = fan_app->add_flag("--set", "Set fans mode");
string desired_fan_mode;
fan_app->add_option("fan_mode", desired_fan_mode, "Selected fan mode")->check(CLI::IsMember({ "coolerboost", "silent", "auto", "custom" }));
vector<pair<int, int>> desired_fan_curve;
CLI::Option* fan_curve_points = fan_app->add_option("-p,--point", desired_fan_curve, "Fan curve points in format [temp,speed %]")->expected(0, 7)->needs(fan_set);
bool ignore_cpu{ false };
bool ignore_gpu{ false };
fan_app->add_flag("--no-cpu", ignore_cpu, "Disables CPU curve setting");
fan_app->add_flag("--no-gpu", ignore_gpu, "Disables GPU curve setting");
CLI::App* webcam_app = app.add_subcommand("webcam", "Webcam lock management");
string desired_webcam_state;
webcam_app->add_option("state", desired_webcam_state, "Webcam state")->check(CLI::IsMember({ "enabled", "disabled" }));
int webcam_first_second_lock{ 0 };
webcam_app->add_flag("-1{1},-2{2}", webcam_first_second_lock, "Lock selection");
CLI::App* battery_app = app.add_subcommand("battery", "Battery charging limit");
int battery_percent{ 0 };
battery_app->add_option("percent", battery_percent, "Percent to end charge at")->check(CLI::Range(10,100));
CLI::App* fn_app = app.add_subcommand("fn", "FN key position");
string desired_fn_position;
fn_app->add_option("position", desired_fn_position, "Keyboard side")->check(CLI::IsMember({ "left", "right" }));
// superbattery handled as shift mode eco. SB switch appears to do nothing on it's own?
CLI::App* shift_mode_app = app.add_subcommand("shift", "System performance mode selection");
string desired_shift_mode;
shift_mode_app->add_option("mode", desired_shift_mode, "Shift mode")->check(CLI::IsMember({ "turbo", "sport", "balanced", "eco" }));
CLI11_PARSE(app, argc, argv);
Control ctrl = Control();
if (*version_app) {
print_system_info(ctrl);
return 0;
}
if (!ctrl.offsets_available()) {
cout << "No offsets found for your firmware. Can't continue working. Please, report your firmware version and EC dump with \"version\".\n";
return 1;
}
if (*fan_app) {
if (!desired_fan_curve.empty()) {
FanCurve cur = ctrl.cpu_fan_curve_get();
int i = 0;
// fill with user input
for (; i < desired_fan_curve.size(); i++) {
cur.point[i].temp = desired_fan_curve[i].first;
cur.point[i].speed = desired_fan_curve[i].second;
}
// finish with repeating last one
for (; i < 6; i++) {
cur.point[i].temp = desired_fan_curve.back().first;
cur.point[i].speed = desired_fan_curve.back().second;
}
if (!ignore_gpu) {
ctrl.gpu_fan_curve_set(cur);
}
if (!ignore_cpu) {
ctrl.cpu_fan_curve_set(cur);
}
}
if (!desired_fan_mode.empty()) {
if (*fan_set) {
switch (fan_state.at(desired_fan_mode)) {
case FAN_STATE::COOLERBOOST:
ctrl.coolerboost_set(true);
ctrl.silent_set(false);
ctrl.custom_curve_set(false);
break;
case FAN_STATE::SILENT:
ctrl.coolerboost_set(false);
ctrl.silent_set(true);
ctrl.custom_curve_set(false);
break;
case FAN_STATE::AUTO:
ctrl.coolerboost_set(false);
ctrl.silent_set(false);
ctrl.custom_curve_set(false);
break;
case FAN_STATE::CUSTOM:
ctrl.coolerboost_set(false);
ctrl.silent_set(false);
ctrl.custom_curve_set(true);
break;
}
return 0;
}
else {
switch (fan_state.at(desired_fan_mode)) {
case FAN_STATE::COOLERBOOST:
cout << ctrl.coolerboost_get();
break;
case FAN_STATE::SILENT:
cout << ctrl.silent_get();
break;
case FAN_STATE::AUTO:
cout << !ctrl.custom_curve_get();
break;
case FAN_STATE::CUSTOM:
cout << ctrl.custom_curve_get();
break;
}
return 0;
}
}
print_fan_info(ctrl, true);
return 0;
}
if (*webcam_app) {
if (!desired_webcam_state.empty()) {
switch (state.at(desired_webcam_state)) {
case STATE::ENABLED:
if (webcam_first_second_lock == 0 || webcam_first_second_lock == 1) {
ctrl.webcam_first_set(true);
}
if (webcam_first_second_lock == 0 || webcam_first_second_lock == 2) {
ctrl.webcam_second_set(true);
}
break;
case STATE::DISABLED:
if (webcam_first_second_lock == 0 || webcam_first_second_lock == 1) {
ctrl.webcam_first_set(false);
}
if (webcam_first_second_lock == 0 || webcam_first_second_lock == 2) {
ctrl.webcam_second_set(false);
}
break;
}
return 0;
}
switch (webcam_first_second_lock) {
case 0:
cout << "First webcam state: " << ctrl.webcam_first_get() << "\n";
cout << "Second webcam state: " << ctrl.webcam_second_get() << "\n";
break;
case 1:
cout << ctrl.webcam_first_get() << "\n";
break;
case 2:
cout << ctrl.webcam_second_get() << "\n";
break;
}
return 0;
}
if (*battery_app) {
if (battery_percent > 0) {
ctrl.battery_threshold_set(battery_percent);
}
else {
cout << "Battery charge threshold: ";
cout << ctrl.battery_threshold_get() << "\n";
}
return 0;
}
if (*fn_app) {
if (!desired_fn_position.empty()) {
switch (fn_side.at(desired_fn_position)) {
case FN_SIDE::LEFT:
ctrl.fn_on_the_left_set(true);
break;
case FN_SIDE::RIGHT:
ctrl.fn_on_the_left_set(false);
break;
}
return 0;
}
cout << "FN key position: ";
if (ctrl.fn_on_the_left_get()) {
cout << "left\n";
}
else {
cout << "right\n";
}
return 0;
}
if (*shift_mode_app) {
if (!desired_shift_mode.empty()) {
ctrl.shift_mode_set(shift_mode.at(desired_shift_mode));
return 0;
}
cout << "Current mode: ";
SHIFT_MODE mode = ctrl.shift_mode_get();
switch (mode) {
case SHIFT_MODE::TURBO:
cout << "turbo\n";
break;
case SHIFT_MODE::SPORT:
cout << "sport\n";
break;
case SHIFT_MODE::BALANCED:
cout << "balanced";
break;
case SHIFT_MODE::ECO:
cout << "eco\n";
break;
}
return 0;
}
}