Skip to content

Commit

Permalink
* Now possible to query the RPM value for each fan.
Browse files Browse the repository at this point in the history
* Error status codes are now negative so as not to be confused with possible results from the RPM query.
  • Loading branch information
Aaron A. Kelley committed May 27, 2020
1 parent ed5765f commit f38c4b6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 54 deletions.
Binary file modified DellFanCmd.rc
Binary file not shown.
3 changes: 2 additions & 1 deletion bzh_dell_smm_io_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define DELL_SMM_IO_ENABLE_FAN_CTL2 0x35a3

#define DELL_SMM_IO_SET_FAN_LV 0x01a3
#define DELL_SMM_IO_GET_FAN_RPM 0x02a3

#define DELL_SMM_IO_FAN_LV0 0x0000
#define DELL_SMM_IO_FAN_LV1 0x0001
Expand All @@ -19,6 +20,6 @@
#define DELL_SMM_IO_FAN1 0
#define DELL_SMM_IO_FAN2 1

#define DELL_SMM_IO_NO_ARG 0x0
#define DELL_SMM_IO_NO_ARG 0x0

#endif // BZH_DELL_SMM_IO_CODES
7 changes: 6 additions & 1 deletion bzh_dell_smm_io_drv_fun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ ULONG _stdcall dell_smm_io(ULONG cmd, ULONG data)

ULONG dell_smm_io_set_fan_lv(ULONG fan_no, ULONG lv)
{
ULONG arg = (lv<<8) | fan_no;
ULONG arg = (lv << 8) | fan_no;
return dell_smm_io(DELL_SMM_IO_SET_FAN_LV, arg);
}

ULONG dell_smm_io_get_fan_rpm(ULONG fan_no)
{
return dell_smm_io(DELL_SMM_IO_GET_FAN_RPM, fan_no);
}

#ifdef __cplusplus
}
#endif
1 change: 1 addition & 0 deletions bzh_dell_smm_io_drv_fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void display_error(ULONG errorcode);
ULONG _stdcall dell_smm_io(ULONG cmd, ULONG data);

ULONG dell_smm_io_set_fan_lv(ULONG fan_no, ULONG lv);
ULONG dell_smm_io_get_fan_rpm(ULONG fan_no);

#ifdef __cplusplus
}
Expand Down
91 changes: 39 additions & 52 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void unloadDriver();
// Main program begins here.
int main(int argc, char* argv[])
{
cout << "DellFanCmd 1.0.1\n";
cout << "DellFanCmd 1.1\n";
cout << "By Aaron Kelley\n";
cout << "Licensed under GPLv3\n";
cout << "Source code available at https://github.com/AaronKelley/DellFanCmd\n\n";
Expand All @@ -21,6 +21,8 @@ int main(int argc, char* argv[])
cout << "Derived from \"Dell fan utility\" by 424778940z\n";
cout << "https://github.com/424778940z/dell-fan-utility\n\n";

int returnCode = 0;

if (argc != 2)
{
usage();
Expand All @@ -33,6 +35,7 @@ int main(int argc, char* argv[])
bool setFansTo100 = false;
bool useAlternateCommand = false;
bool setFanLevel = false;
bool getFanRpm = false;
ULONG fanSelection = 0;
ULONG fanLevel = 0;

Expand Down Expand Up @@ -102,52 +105,20 @@ int main(int argc, char* argv[])
fanSelection = DELL_SMM_IO_FAN2;
fanLevel = DELL_SMM_IO_FAN_LV2;
}
else if (strcmp(argv[1], "fan1-level0-alt") == 0)
{
setFanLevel = true;
fanSelection = DELL_SMM_IO_FAN1;
fanLevel = DELL_SMM_IO_FAN_LV0;
useAlternateCommand = true;
}
else if (strcmp(argv[1], "fan1-level1-alt") == 0)
{
setFanLevel = true;
fanSelection = DELL_SMM_IO_FAN1;
fanLevel = DELL_SMM_IO_FAN_LV1;
useAlternateCommand = true;
}
else if (strcmp(argv[1], "fan1-level2-alt") == 0)
{
setFanLevel = true;
fanSelection = DELL_SMM_IO_FAN1;
fanLevel = DELL_SMM_IO_FAN_LV2;
useAlternateCommand = true;
}
else if (strcmp(argv[1], "fan2-level0-alt") == 0)
{
setFanLevel = true;
fanSelection = DELL_SMM_IO_FAN2;
fanLevel = DELL_SMM_IO_FAN_LV0;
useAlternateCommand = true;
}
else if (strcmp(argv[1], "fan2-level1-alt") == 0)
{
setFanLevel = true;
fanSelection = DELL_SMM_IO_FAN2;
fanLevel = DELL_SMM_IO_FAN_LV1;
useAlternateCommand = true;
}
else if (strcmp(argv[1], "fan2-level2-alt") == 0)
{
setFanLevel = true;
fanSelection = DELL_SMM_IO_FAN2;
fanLevel = DELL_SMM_IO_FAN_LV2;
useAlternateCommand = true;
}
else
else if (strcmp(argv[1], "rpm-fan1") == 0)
{
getFanRpm = true;
fanSelection = DELL_SMM_IO_FAN1;
}
else if (strcmp(argv[1], "rpm-fan2") == 0)
{
getFanRpm = true;
fanSelection = DELL_SMM_IO_FAN2;
}
else
{
usage();
exit(3);
exit(-3);
}

// Execute request.
Expand All @@ -166,7 +137,7 @@ int main(int argc, char* argv[])
{
cerr << "Failed.\n";
unloadDriver();
exit(1);
exit(-1);
}

cout << " ...Success.\n";
Expand Down Expand Up @@ -203,31 +174,44 @@ int main(int argc, char* argv[])
{
cerr << "Failed.\n";
unloadDriver();
exit(1);
exit(-1);
}

cout << " ...Success.\n";
}
else if (setFanLevel)
{
cout << "Attempting to set the fan level...\n";
ULONG command = !useAlternateCommand ? DELL_SMM_IO_ENABLE_FAN_CTL1 : DELL_SMM_IO_ENABLE_FAN_CTL2;
int result = dell_smm_io_set_fan_lv(fanSelection, fanLevel);
if (result == -1)
{
cerr << "Failed.\n";
unloadDriver();
exit(1);
exit(-1);
}

cout << " ...Success.\n";
}
else if (getFanRpm)
{
cout << "Attempting to query the fan RPM...\n";
int result = dell_smm_io_get_fan_rpm(fanSelection);
if (result == -1)
{
cerr << "Failed.\n";
unloadDriver();
exit(-1);
}

cout << " Result: " << result << "\n";
returnCode = result;
}

// Unload driver.
unloadDriver();
}

return 0;
return returnCode;
}

// Print out basic usage information.
Expand All @@ -238,7 +222,10 @@ void usage()
cout << " ec-disable Turn EC fan control off (fan goes to manual control)\n";
cout << " ec-disable-nofanchg Turn EC fan control off and don't change the fan speed\n";
cout << " ec-enable Turn EC fan control on (fan goes to automatic control)\n";
cout << "\n";
cout << " fan1-rpm Report RPM for fan 1\n";
cout << " fan2-rpm Report RPM for fan 2\n";
cout << " (RPMs are reported via status/error code)\n";
cout << "\n";
cout << "After EC fan control is off, you may use:\n";
cout << " fan1-level0 Set fan 1 to level 0 (0%)\n";
cout << " fan1-level1 Set fan 1 to level 1 (50%)\n";
Expand All @@ -247,7 +234,7 @@ void usage()
cout << " fan2-level1 Set fan 2 to level 1 (50%)\n";
cout << " fan2-level2 Set fan 2 to level 2 (100%)\n";
cout << "\n";
cout << "Append \"-alt\" to any command to attempt alternate fan control method.\n";
cout << "Append \"-alt\" to EC disable or enable commands to attempt alternate method.\n";
cout << "(Example: ec-disable-alt)\n";
}

Expand Down

0 comments on commit f38c4b6

Please sign in to comment.