Skip to content

Commit 15de45c

Browse files
committed
Fixed boost switching.
1 parent e6f4516 commit 15de45c

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

G14Control.pyw

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ showFlash = False
3131
config_loc: str
3232
current_boost_mode = 0
3333
current_windows_plan = "Balanced"
34-
active_plan_map: dict
34+
active_plan_map: dict = {}
3535

3636

3737
def readData(data):
@@ -51,12 +51,27 @@ def get_power_plans():
5151
app_GUID = i.split(' ')[3]
5252

5353
def get_windows_plans():
54-
global win_plans, config, active_plan_map
54+
global win_plans, config, active_plan_map, current_windows_plan
5555
windows_power_options = re.findall(r"([0-9a-f\-]{36}) *\((.*)\) *\*?\n", os.popen("powercfg /l").read())
5656
active_plan_map = {x[1]:False for x in windows_power_options}
5757
active_plan_map[current_windows_plan] = True
5858
return windows_power_options
5959

60+
"""
61+
Cannot be run before @get_windows_plans()
62+
"""
63+
def get_active_plan_map():
64+
global windows_plans, active_plan_map
65+
try:
66+
active_plan_map["Balanced"]
67+
return active_plan_map
68+
except Exception:
69+
active_plan_map = {x[1]:False for x in windows_plans}
70+
active_plan_map[current_windows_plan] = True
71+
return active_plan_map
72+
73+
74+
6075
def get_app_path():
6176
global G14dir
6277
G14Dir = ""
@@ -253,12 +268,12 @@ def get_current():
253268
def apply_plan(plan):
254269
global current_plan, main_cmds, icon_app
255270
current_plan = plan['name']
271+
main_cmds.set_windows_and_active_plans(windows_plans,active_plan_map)
256272
main_cmds.set_atrofac(plan['plan'], plan['cpu_curve'], plan['gpu_curve'])
257273
main_cmds.set_boost(plan['boost'], False)
258274
main_cmds.set_dgpu(plan['dgpu_enabled'], False)
259275
main_cmds.set_screen(plan['screen_hz'], False)
260276
main_cmds.set_ryzenadj(plan['cpu_tdp'])
261-
262277
notify("Applied plan " + plan['name'])
263278

264279

@@ -284,15 +299,18 @@ def quit_app():
284299

285300

286301
def apply_plan_deactivate_switching(plan):
287-
apply_plan(plan)
302+
global current_plan
303+
main_cmds.apply_plan(plan)
288304
deactivate_powerswitching()
289305

290306

291307
def set_windows_plan(plan):
292-
global active_plan_map, current_windows_plan
308+
global active_plan_map, current_windows_plan, windows_plans
309+
print(plan)
293310
active_plan_map[current_windows_plan]=False
294311
current_windows_plan = plan[1]
295312
active_plan_map[current_windows_plan]=True
313+
main_cmds.set_windows_and_active_plans(windows_plans,active_plan_map)
296314
main_cmds.set_power_plan(plan[0])
297315

298316
def power_options_menu():
@@ -409,6 +427,7 @@ def startup_checks():
409427

410428

411429
if __name__ == "__main__":
430+
412431
device = None
413432
frame = []
414433
G14dir = None
@@ -430,8 +449,10 @@ if __name__ == "__main__":
430449
ac = psutil.sensors_battery().power_plugged # Set AC/battery status on start
431450
resources.extract(config['temp_dir'])
432451
startup_checks()
452+
453+
active_plan_map = get_active_plan_map()
433454
# A process in the background will check for AC, autoswitch plan if enabled and detected
434-
main_cmds = RunCommands(config,G14dir,app_GUID,dpp_GUID,notify) #Instantiate command line tasks runners in G14RunCommands.py
455+
main_cmds = RunCommands(config,G14dir,app_GUID,dpp_GUID,notify,windows_plans,active_plan_map) #Instantiate command line tasks runners in G14RunCommands.py
435456
power_thread = power_check_thread()
436457
power_thread.start()
437458

G14RunCommands.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66

77
class RunCommands():
88

9-
def __init__(self,config, G14dir, app_GUID, dpp_GUID, notify):
9+
def __init__(self,config, G14dir, app_GUID, dpp_GUID, notify, windows_plans, active_plan_map):
1010
self.config = config
1111
self.G14dir = G14dir
1212
self.app_GUID = app_GUID
1313
self.dpp_GUID = dpp_GUID
1414
self.notify = notify
15+
self.windows_plans = windows_plans
16+
self.active_plan_map = active_plan_map
17+
self.windows_plan_map = {name:guid for guid,name in iter(windows_plans)}
1518

19+
def set_windows_and_active_plans(self,winplns,activeplns):
20+
self.active_plan_map = activeplns
21+
self.windows_plans = winplns
22+
1623

1724
# noinspection PyBroadException
1825
def parse_boolean(self, parse_string): # Small utility to convert windows HEX format to a boolean.
@@ -25,7 +32,6 @@ def parse_boolean(self, parse_string): # Small utility to convert windows HEX f
2532
return None # Just in case™
2633

2734

28-
2935
def get_boost(self):
3036
current_pwr = os.popen("powercfg /GETACTIVESCHEME") # I know, it's ugly, but no other way to do that from py.
3137
pwr_guid = current_pwr.readlines()[0].rsplit(": ")[1].rsplit(" (")[0].lstrip("\n") # Parse the GUID
@@ -54,10 +60,22 @@ def do_boost(self, state):
5460
print(SET_AC_VAL)
5561
print(SET_DC_VAL)
5662

63+
5764
def set_boost(self, state, notification=True):
5865
current_boost_mode = state
59-
(dpp_GUID, app_GUID) = (self.app_GUID,self.dpp_GUID)
60-
# self.set_power_plan(dpp_GUID)
66+
win_plans = self.windows_plans
67+
active_plans = self.active_plan_map
68+
windows_plan_map = self.windows_plan_map
69+
CURRENT_SCHEME = os.popen("powercfg /GETACTIVESCHEME")
70+
pwr_guid = CURRENT_SCHEME.readlines()[0].rsplit(": ")[1].rsplit(" (")[0].lstrip("\n").replace(" ","") # Parse the GUID
71+
switch_to = list({val for key,val in windows_plan_map.items() if val!=pwr_guid})[0]
72+
switch_to_guid = win_plans
73+
print(switch_to, "switch to guid")
74+
print(pwr_guid, "power guid")
75+
print(self.active_plan_map)
76+
self.set_power_plan(switch_to)
77+
time.sleep(.25)
78+
self.set_power_plan(pwr_guid)
6179
if state is True: # Activate boost
6280
self.do_boost(state)
6381
if notification is True:
@@ -78,9 +96,9 @@ def set_boost(self, state, notification=True):
7896
self.do_boost(state)
7997
if notification is True:
8098
self.notify("Boost set to Aggressive") # Inform the user
81-
# self.set_power_plan(app_GUID)
99+
self.set_power_plan(switch_to)
82100
time.sleep(0.25)
83-
# self.set_power_plan(dpp_GUID)
101+
self.set_power_plan(pwr_guid)
84102

85103

86104
def get_dgpu(self):
@@ -96,6 +114,7 @@ def get_dgpu(self):
96114
else:
97115
return True
98116

117+
99118
def set_dgpu(self, state, notification=True):
100119
config = self.config
101120
G14dir = self.G14dir

data/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ plans:
4848
dgpu_enabled: true
4949
screen_hz: 120
5050
- name: Performance
51-
plan: windows
51+
plan: performance
5252
cpu_curve: "30c:0%,40c:5%,50c:8%,60c:10%,70c:31%,80c:49%,90c:56%,100c:56%"
5353
gpu_curve: "30c:0%,40c:5%,50c:8%,60c:10%,70c:34%,80c:51%,90c:61%,100c:61%"
5454
cpu_tdp: 38000
5555
boost: 4
5656
dgpu_enabled: true
5757
screen_hz: 120
5858
- name: Performance Plus
59-
plan: windows
59+
plan: performance
6060
cpu_curve: "30c:0%,40c:5%,50c:15%,60c:24%,70c:31%,80c:49%,90c:56%,100c:56%"
6161
gpu_curve: "30c:0%,40c:5%,50c:15%,60c:24%,70c:34%,80c:51%,90c:61%,100c:61%"
6262
cpu_tdp: 40000
6363
boost: 4
6464
dgpu_enabled: true
6565
screen_hz: 120
6666
- name: Extreme
67-
plan: windows
67+
plan: turbo
6868
cpu_curve: "30c:20%,40c:50%,50c:50%,60c:50%,70c:70%,80c:70%,90c:80%,100c:90%"
6969
gpu_curve: "30c:20%,40c:50%,50c:50%,60c:50%,70c:70%,80c:70%,90c:80%,100c:90%"
7070
cpu_tdp: 45000

0 commit comments

Comments
 (0)