Skip to content

Commit

Permalink
Fixed issue where erroring SMULoop would cause App crash & Added 1 se…
Browse files Browse the repository at this point in the history
…cond delay to ryzenadj settings to make sure they get applied.
  • Loading branch information
aredden committed Jan 16, 2021
1 parent 915bf2f commit 80e2835
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 63 deletions.
3 changes: 2 additions & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "g14controlv2-main",
"productName": "G14ControlV2-Main",
"version": "0.2.0",
"version": "0.2.1",
"description": "",
"main": "./build/electron.js",
"scripts": {
Expand All @@ -11,6 +11,7 @@
"tsc": "tsc --project ./tsconfig.dev.json",
"watch": "nodemon -e ts --ignore /build --ignore /node_modules --exec \"tsc --project ./tsconfig.dev.json && electron . || exit 1\" || exit 1"
},
"types": "./src/g14controlv2-main.d.ts",
"author": "Alex Redden",
"license": "ISC",
"dependencies": {
Expand Down
91 changes: 42 additions & 49 deletions electron/src/IPCEvents/G14ControlPlans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ export const switchWindowsPlanToActivateSettings = async (
}
};

export const setRyzenadjWithDelay = async (
ryzenadj: RyzenadjConfig | RyzenadjConfigNamed | undefined
) => {
if (ryzenadj) {
let { fastLimit, slowLimit, stapmLimit } = ryzenadj;
ryzenadj = Object.assign(ryzenadj, {
fastLimit: fastLimit % 1000 === 0 ? fastLimit : fastLimit * 1000,
slowLimit: slowLimit % 1000 === 0 ? slowLimit : slowLimit * 1000,
stapmLimit: stapmLimit % 1000 === 0 ? stapmLimit : stapmLimit * 1000,
});
}
let ryzn = ryzenadj ? await setRyzenadj(ryzenadj) : true;
if (!ryzn) {
let final = await keepAttemptRyzenADJ(ryzenadj, 6);
if (!final) {
return false;
}
}
return true;
};

/**
* 1. Set Boost & Graphics at target windows plan since they are sensitive to changes.
* 2. Switch to target windows plan
Expand Down Expand Up @@ -197,63 +218,35 @@ export const setG14ControlPlan = async (plan: FullG14ControlPlan) => {
armPlan ? armPlan.toLowerCase() : undefined
);
if (result) {
LOGGER.info('Sucessfully applied G14ControlPlan');
if (ryzenadj) {
let { fastLimit, slowLimit, stapmLimit } = ryzenadj;
ryzenadj = Object.assign(ryzenadj, {
fastLimit:
fastLimit % 1000 === 0
? fastLimit
: fastLimit * 1000,
slowLimit:
slowLimit % 1000 === 0
? slowLimit
: slowLimit * 1000,
stapmLimit:
stapmLimit % 1000 === 0
? stapmLimit
: stapmLimit * 1000,
});
}
let ryzn = ryzenadj ? await setRyzenadj(ryzenadj) : true;
if (!ryzn) {
let final = await keepAttemptRyzenADJ(ryzenadj, 6);
if (!final) {
resolve(false);
return;
LOGGER.info('Sucessfully applied fancurve');
setTimeout(async () => {
let ryadjResult = await setRyzenadjWithDelay(ryzenadj);
if (ryadjResult) {
LOGGER.info('Sucessfully applied G14ControlPlan');
} else {
LOGGER.info(
'Failed to apply ryzenadj plan & therefore G14ControlPlan'
);
}
}
LOGGER.info('Sucessfully applied G14ControlPlan');
resolve(true);
resolve(ryadjResult);
}, 1000);
} else {
LOGGER.error('Failed to modify fan curve.');
resolve(false);
}
}
} else {
if (ryzenadj) {
let { fastLimit, slowLimit, stapmLimit } = ryzenadj;
ryzenadj = Object.assign(ryzenadj, {
fastLimit:
fastLimit % 1000 === 0 ? fastLimit : fastLimit * 1000,
slowLimit:
slowLimit % 1000 === 0 ? slowLimit : slowLimit * 1000,
stapmLimit:
stapmLimit % 1000 === 0
? stapmLimit
: stapmLimit * 1000,
});
}
let ryzn = ryzenadj ? await setRyzenadj(ryzenadj) : true;
if (!ryzn) {
let final = await keepAttemptRyzenADJ(ryzenadj, 6);
if (!final) {
resolve(false);
return;
setTimeout(async () => {
let ryadjResult = await setRyzenadjWithDelay(ryzenadj);
if (ryadjResult) {
LOGGER.info('Sucessfully applied G14ControlPlan');
} else {
LOGGER.info(
'Failed to apply ryzenadj plan & therefore G14ControlPlan'
);
}
}
LOGGER.info('Sucessfully applied G14ControlPlan');
resolve(true);
resolve(ryadjResult);
}, 1000);
}
} else {
LOGGER.error('Failed to switch windows plan to target plan.');
Expand Down
18 changes: 6 additions & 12 deletions electron/src/IPCEvents/renoir-mobile/SMULoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,18 @@ export class SMULoop extends EventEmitter {
private handleData = (data: Buffer) => {
let arr = data.toString();
if (arr.indexOf('StapmTimeConstant') !== -1) {
try{
let smuresponse: {values:SMUData[]} = JSON.parse(arr);
try {
let smuresponse: { values: SMUData[] } = JSON.parse(arr);
this.emit('smuData', smuresponse.values);
}catch(e){
LOGGER.info(`Error parsing SMU data. ${e}`)
} catch (e) {
LOGGER.info(`Error parsing SMU data. ${e}`);
}


}
};

private handleError = (chunk: Buffer) => {
LOGGER.error(
`Error from renoir-mobile:\n${JSON.stringify(
JSON.parse(chunk.toString('utf-8'))
)}`
);
this.emit('smuError', chunk.toString());
LOGGER.error(`Error from renoir-mobile:\n${chunk.toString('utf-8')}`);
this.emit('smuError', chunk.toString('utf-8'));
};

alive = () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "g14controlv2",
"productName": "G14ControlV2",
"version": "v0.2.0",
"version": "v0.2.1",
"description": "Management Tools for the Zephyrus G14",
"author": {
"name": "Alex Redden",
Expand Down

0 comments on commit 80e2835

Please sign in to comment.