Skip to content

Commit

Permalink
Add NvAPI, ADL, log file switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Demion committed Mar 28, 2019
1 parent 4ca5200 commit b258880
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 19 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Changelog:

- **v0.7** - [NvApiOc v0.7](https://github.com/Demion/nvapioc/releases/download/v0.7/NvApiOc_v0.7.zip)
* Add NVIDIA NvAPI switch option.
* Add AMD ATI ADL switch option.
* Add log file switch option.
- **v0.6** - [NvApiOc v0.6](https://github.com/Demion/nvapioc/releases/download/v0.6/NvApiOc_v0.6.zip)
* Add curve (voltage:frequency) option.
- **v0.5** - [NvApiOc v0.5](https://github.com/Demion/nvapioc/releases/download/v0.5/NvApiOc_v0.5.zip)
Expand Down Expand Up @@ -35,6 +39,9 @@ NvApiOc Open Source NVIDIA NvAPI & AMD ATI ADL Overdrive GPU Overclock
- **-led** gpuBusId type brightness *(type: 0 = logo; 1 = sliBridge)*
- **-curve** gpuBusId count voltageUV frequencyKHz vUV2 fKHz2 vUV3 fKHz3
<br/>*(count: 0 = reset; -1 = save; frequencyKHz: 0 = default; NVIDIA offset)*
- **-nvidia** enable *(enable: 0 = false; 1 = true = default)*
- **-amd** enable *(enable: 0 = false; 1 = true = default)*
- **-log** enable *(enable: 0 = false; 1 = true = default)*
- **-restart**

### Donation:
Expand Down
108 changes: 89 additions & 19 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ enum class PStateLimitType
All = 3
};

bool NvApi = true, Adl = true;
bool LogFileEnable = true;

void *NvApiGpuHandles[128] = {0};

unsigned int AdlGpuIndexes[128] = {0};
Expand Down Expand Up @@ -1285,16 +1288,72 @@ void PrintUsage()
"-led gpuBusId type brightness (type: 0 = logo; 1 = sliBridge)\n"
"-curve gpuBusId count voltageUV frequencyKHz vUV2 fKHz2 vUV3 fKHz3\n"
"(count: 0 = reset; -1 = save; frequencyKHz: 0 = default; NVIDIA offset)\n"
"-nvidia enable (enable: 0 = false; 1 = true = default)\n"
"-amd enable (enable: 0 = false; 1 = true = default)\n"
"-log enable (enable: 0 = false; 1 = true = default)\n"
"-restart\n");
}

void ParseInitArgs(int argc, char *argv[])
{
int arg = 1;

while (arg < argc)
{
if (strcmp(strupr(argv[arg]), "-NVIDIA") == 0)
{
if (arg + 1 < argc)
{
NvApi = (atoi(argv[++arg]) != 0);
}
}
else if (strcmp(strupr(argv[arg]), "-AMD") == 0)
{
if (arg + 1 < argc)
{
Adl = (atoi(argv[++arg]) != 0);
}
}
else if (strcmp(strupr(argv[arg]), "-LOG") == 0)
{
if (arg + 1 < argc)
{
LogFileEnable = (atoi(argv[++arg]) != 0);
}
}

++arg;
}
}

void ParseArgs(int argc, char *argv[])
{
int arg = 1;

while (arg < argc)
{
if (strcmp(strupr(argv[arg]), "-CORE") == 0)
if (strcmp(strupr(argv[arg]), "-NVIDIA") == 0)
{
if (arg + 1 < argc)
{
NvApi = (atoi(argv[++arg]) != 0);
}
}
else if (strcmp(strupr(argv[arg]), "-AMD") == 0)
{
if (arg + 1 < argc)
{
Adl = (atoi(argv[++arg]) != 0);
}
}
else if (strcmp(strupr(argv[arg]), "-LOG") == 0)
{
if (arg + 1 < argc)
{
LogFileEnable = (atoi(argv[++arg]) != 0);
}
}
else if (strcmp(strupr(argv[arg]), "-CORE") == 0)
{
if (arg + 3 < argc)
{
Expand Down Expand Up @@ -1476,49 +1535,60 @@ void ParseArgs(int argc, char *argv[])

int main(int argc, char *argv[])
{
LogFile = fopen("log.txt", "a");

if (argc > 1)
{
bool nvapi = false, adl = false;
ParseInitArgs(argc, argv);

if (LogFileEnable)
LogFile = fopen("log.txt", "a");

if (NvApiLoad() == 0)
if (NvApi)
{
if (NvApiInit() == 0)
NvApi = false;

if (NvApiLoad() == 0)
{
nvapi = true;
if (NvApiInit() == 0)
{
NvApiEnumGpus();
NvApiEnumTccGpus();

NvApiEnumGpus();
NvApiEnumTccGpus();
NvApi = true;
}
}
}

if (AdlLoad() == 0)
if (Adl)
{
if (AdlInit() == 0)
Adl = false;

if (AdlLoad() == 0)
{
adl = true;
if (AdlInit() == 0)
{
AdlEnumGpus();

AdlEnumGpus();
Adl = true;
}
}
}

if ((nvapi) || (adl))
if ((NvApi) || (Adl))
ParseArgs(argc, argv);

if (nvapi)
if (NvApi)
NvApiFree();

if (adl)
if (Adl)
AdlFree();

if (LogFile)
fclose(LogFile);
}
else
{
PrintUsage();
}

if (LogFile)
fclose(LogFile);

return EXIT_SUCCESS;
}

0 comments on commit b258880

Please sign in to comment.