diff --git a/HuaweiBatteryControl/.editorconfig b/HuaweiBatteryControl/.editorconfig new file mode 100644 index 0000000..6b34dcf --- /dev/null +++ b/HuaweiBatteryControl/.editorconfig @@ -0,0 +1,72 @@ +# Visual Studio 生成了具有 C++ 设置的 .editorconfig 文件。 +root = true + +[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] + +# Visual C++ 代码样式设置 + +cpp_generate_documentation_comments = xml + +# Visual C++ 格式设置 + +cpp_indent_braces = false +cpp_indent_multi_line_relative_to = innermost_parenthesis +cpp_indent_within_parentheses = indent +cpp_indent_preserve_within_parentheses = true +cpp_indent_case_contents = true +cpp_indent_case_labels = false +cpp_indent_case_contents_when_block = false +cpp_indent_lambda_braces_when_parameter = true +cpp_indent_goto_labels = one_left +cpp_indent_preprocessor = leftmost_column +cpp_indent_access_specifiers = false +cpp_indent_namespace_contents = true +cpp_indent_preserve_comments = false +cpp_new_line_before_open_brace_namespace = ignore +cpp_new_line_before_open_brace_type = ignore +cpp_new_line_before_open_brace_function = ignore +cpp_new_line_before_open_brace_block = ignore +cpp_new_line_before_open_brace_lambda = ignore +cpp_new_line_scope_braces_on_separate_lines = false +cpp_new_line_close_brace_same_line_empty_type = false +cpp_new_line_close_brace_same_line_empty_function = false +cpp_new_line_before_catch = true +cpp_new_line_before_else = true +cpp_new_line_before_while_in_do_while = false +cpp_space_before_function_open_parenthesis = remove +cpp_space_within_parameter_list_parentheses = false +cpp_space_between_empty_parameter_list_parentheses = false +cpp_space_after_keywords_in_control_flow_statements = true +cpp_space_within_control_flow_statement_parentheses = false +cpp_space_before_lambda_open_parenthesis = false +cpp_space_within_cast_parentheses = false +cpp_space_after_cast_close_parenthesis = false +cpp_space_within_expression_parentheses = false +cpp_space_before_block_open_brace = true +cpp_space_between_empty_braces = false +cpp_space_before_initializer_list_open_brace = false +cpp_space_within_initializer_list_braces = true +cpp_space_preserve_in_initializer_list = true +cpp_space_before_open_square_bracket = false +cpp_space_within_square_brackets = false +cpp_space_before_empty_square_brackets = false +cpp_space_between_empty_square_brackets = false +cpp_space_group_square_brackets = true +cpp_space_within_lambda_brackets = false +cpp_space_between_empty_lambda_brackets = false +cpp_space_before_comma = false +cpp_space_after_comma = true +cpp_space_remove_around_member_operators = true +cpp_space_before_inheritance_colon = true +cpp_space_before_constructor_colon = true +cpp_space_remove_before_semicolon = true +cpp_space_after_semicolon = true +cpp_space_remove_around_unary_operator = true +cpp_space_around_binary_operator = insert +cpp_space_around_assignment_operator = insert +cpp_space_pointer_reference_alignment = left +cpp_space_around_ternary_operator = insert +cpp_wrap_preserve_blocks = one_liners + +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/HuaweiBatteryControl/HuaweiBatteryControl.cpp b/HuaweiBatteryControl/HuaweiBatteryControl.cpp index 05022af..ab54949 100644 --- a/HuaweiBatteryControl/HuaweiBatteryControl.cpp +++ b/HuaweiBatteryControl/HuaweiBatteryControl.cpp @@ -25,19 +25,46 @@ unsigned int copyArr(void* dst, size_t dstlength, const void* src, size_t srclen int main(int argc, char* argv[]) { - cout << "\nCommand-line arguments:\n"; + cout << "Command-line arguments:\n"; for (int count = 0; count < argc; count++) cout << " argv[" << count << "] " << argv[count] << "\n"; unsigned long long data = 0x46281003; if (argc == 2) { - data = strtoul(argv[1], NULL, 10); + if (strcmp(argv[1], "--help") == 0) { + printf_s( +"\nUsage:\n\nHuaweiBatteryControl.exe [--new] \n\ + --new Using new methods, new devices or BIOS may require this option \n\ +\n\ +HuaweiBatteryControl.exe \n\ + Raw data explain: \n\ + 0x < lower limit>1003 \n\ + 0x < lower limit>48011503 (for new devices or BIOS) \n\ + Then convert hex to decimal"); + return 0; + } + else { + data = strtoull(argv[1], NULL, 10); + } } else if (argc == 3) { - data = strtoul(argv[1], NULL, 10) * 0x1000000 | strtoul(argv[2], NULL, 10) * 0x10000 | 0x1003; + data = strtoull(argv[1], NULL, 10) * 0x1000000 | strtoull(argv[2], NULL, 10) * 0x10000 | 0x1003; } - printf("data:%llu(0x%llx)\n", data, data); + else if (argc == 4) { + if (strcmp(argv[3], "--new") == 0) { + data = strtoull(argv[1], NULL, 10) * 0x10000000000 | strtoull(argv[2], NULL, 10) * 0x100000000 | 0x48011503; + } + else { + printf_s("Unknown option\nTry 'HuaweiBatteryControl.exe --help' for more information"); + return 0; + } + } + else { + printf_s("Unknown option\nTry 'HuaweiBatteryControl.exe --help' for more information"); + return 0; + } + printf_s("data:%llu(0x%llx)\n", data, data); HRESULT hres; @@ -218,7 +245,7 @@ int main(int argc, char* argv[]) &varReturnValue, NULL, 0); unsigned long long(*returnData)[64] = (unsigned long long(*)[64])(varReturnValue.parray->pvData); - printf("u8Output:%llu\n", *returnData[0]); + printf_s("u8Output:%llu\n", *returnData[0]); // Clean up diff --git a/README.md b/README.md index 3cfaacd..b7aa0ef 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Control charge threshold for Huawei laptop in Windows. Tested on: - Huawei Matebook 14 2020 +- Huawei Matebook D 14 (BIOS 1.17 with --new) - Huawei Matebook E GO - Honor Hunter v700 @@ -14,31 +15,32 @@ Tested on: Tips: Make sure you are using Admin permission. ``` +HuaweiBatteryControl.exe [--new] + --new Using new methods, new devices or BIOS may require this option + HuaweiBatteryControl.exe + Raw data explain: + 0x1003 + 0x48011503 (for new devices or BIOS) + Then convert hex to decimal +``` Example: -PS D:\> HuaweiBatteryControl-x64.exe 1177030659 +``` +PS D:\> HuaweiBatteryControl-x64.exe 70 40 Command-line arguments: argv[0] d:\cli-tools\HuaweiBatteryControl-x64.exe - argv[1] 1177030659 + argv[1] 70 + argv[2] 40 data:1177030659(0x46281003) Connected to ROOT\WMI WMI namespace u8Output:0 -``` - -or -``` -HuaweiBatteryControl.exe - -Example: - -PS D:\> HuaweiBatteryControl-x64.exe 70 40 +PS D:\> HuaweiBatteryControl-x64.exe 1177030659 Command-line arguments: argv[0] d:\cli-tools\HuaweiBatteryControl-x64.exe - argv[1] 70 - argv[2] 40 + argv[1] 1177030659 data:1177030659(0x46281003) Connected to ROOT\WMI WMI namespace u8Output:0