diff --git a/DellFanCmd.rc b/DellFanCmd.rc index 4c484d1..8fb1476 100644 Binary files a/DellFanCmd.rc and b/DellFanCmd.rc differ diff --git a/bzh_dell_smm_io_codes.h b/bzh_dell_smm_io_codes.h index 3b41d33..cb67161 100644 --- a/bzh_dell_smm_io_codes.h +++ b/bzh_dell_smm_io_codes.h @@ -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 @@ -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 diff --git a/bzh_dell_smm_io_drv_fun.cpp b/bzh_dell_smm_io_drv_fun.cpp index 6db60d4..6393502 100644 --- a/bzh_dell_smm_io_drv_fun.cpp +++ b/bzh_dell_smm_io_drv_fun.cpp @@ -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 diff --git a/bzh_dell_smm_io_drv_fun.h b/bzh_dell_smm_io_drv_fun.h index 5de85a2..b4b010a 100644 --- a/bzh_dell_smm_io_drv_fun.h +++ b/bzh_dell_smm_io_drv_fun.h @@ -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 } diff --git a/main.cpp b/main.cpp index 555cb99..3ee0cea 100644 --- a/main.cpp +++ b/main.cpp @@ -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"; @@ -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(); @@ -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; @@ -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. @@ -166,7 +137,7 @@ int main(int argc, char* argv[]) { cerr << "Failed.\n"; unloadDriver(); - exit(1); + exit(-1); } cout << " ...Success.\n"; @@ -203,7 +174,7 @@ int main(int argc, char* argv[]) { cerr << "Failed.\n"; unloadDriver(); - exit(1); + exit(-1); } cout << " ...Success.\n"; @@ -211,23 +182,36 @@ int main(int argc, char* argv[]) 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. @@ -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"; @@ -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"; }