-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing battery thresholds #29
Comments
@ldan93 I didn't think it was possible! Definitely worth a try ... as soon as I have a moment of time I start studying the material you have shared. Thanks a lot also for the willingness to collaborate, certainly accepted! |
On my macbook pro 16 I use the Al Dente App. https://github.com/davidwernhart/AlDente this way I can keep my battery at 70% since I have it mostly docked to my monitor. I tried this program on the MateBook Pro X. Unfortunately, it doesn't work. |
@wiregen : Hi, the app seems very interesting! |
@profzei It doesn't work :( I tried the changes that you suggested but AlDente still doesn't work. As soon as I change the charge threshold, it returns to 3 immediately (the default value) |
@wiregen Have you got it to work? For the longest time, I have been trying to implement battery charge thresholds on my mbxp hackintosh |
@profzei I hope you can look into this matter at your availability because with everyone now WFH (and for the forseeable future), setting battery charge thresholds is a godsend. I can literally plug my laptop in the whole day somewhere between 30-80% and not worry about battery degradation (albeit temperature is smth to monitor). What I've tried but failed:
Have a merry christmas and happy new year btw! |
In order to implement this feature, we need to find a way to modify the 0xe4 and 0xe5 registries of the EC’s tables from MacOS... From my limited understanding of the documentation I read, an ACPI method could be the way to go, but I don't know how to implement it. About apps such as Aldente or the native MacOS "Battery Health management feature" : I guess they cannot work before we cleanly implement this feature with a dedicated kext. @zhen-zen achieved to implement battery threshold in YogaSMC.kext for some Lenovo laptops. I have no idea how to transpose this work to our Matebook, maybe we could ask him for some advice ? EDIT : (In my example, the battery stops charging between 45 and 55%. Of course you can change these values.) This persists across reboots. However, when the Matebook is unplugged, it tends to "forget" this setting. This is quite annoying... But when the laptop is constantly plugged in, the setting is consistent (from my observations). |
@ldan93 thanks for your reply! unfortunately, i don't have linux installed on my mbxp or any linux machines near me, so I can't do what you suggested me to do. Are there any alternatives? About what you mentioned above that, I am completely clueless as to how that would work 😅 |
You don't need a Linux machine to set up a Linux USB Key. Under Windows, you can use Rufus to create such a key. Then boot to that usb device to access a Linux environnement. |
I found something interesting. So I went into windows and in the Matebook PC Manager I set the battery limit. I restarted into MacOS BigSur and my Mac wouldn't charge past 50%. It seems like this modifies the bios I believe and limits the charging systemwide. Downside is if you restart it goes back to charging to 100% |
@wiregen I tried doing that but it doesn't work most of the time. Did you just boot into windows, set the battery limit in PC Manager and restarted into macos? |
After some digging into the code of Huawei WMI, I can identify the ACPI methods related to Battery Protection : So, reading the thresholds must be done with \GBTT, and setting new thresholds with \SBTT. Indeed, these two methods are present in our DSDT : I will try to see what would be the next steps, i.e. how to call these methods with RehabMan's OS-X-ACPI-Debug, OS-X-ACPI-Poller, and ioio kexts/utilies. |
@ldan93 Great! Please, share your results here! |
Great news : I found a way to trigger battery protection from MacOS. It's not a very elegant implementation, but it works.
From the terminal with ioio (in the "Release" folder), you can call the following commands :
You can check if the commands are effective by reading the logs in Console.app : search for "ACPIDebug" while you use ioio Some remarks :
|
@ldan93 Thank you very much for your work and detailed explanation! Do you think it is possible implement a script? |
@ldan93 Great contribution for our Matebook X Pro! I'll test it asap and probably I'll link it in next release (probably in the weekend) where I share all my under cover work! |
Cool !! Let me know if everything is working as expected on your side. I'm looking forward to seeing it upstreamed in a coming release ! I'm sure there are better ways to implement this. A nice icon in MacOs menu bar would be awesome, but atm this script should do the trick. I'll continue investigating the topic and let you know if I make any progress. |
I may be really wrong here, since I have no experience with MacOS to speak of, but if
then I think making matebook-applet work on MacOS is an endeavour I might be willing to undertake in my spare time... |
@nekr0z This is a great news!
I'm the maintainer of this repo, I'm not a "real" developer, I'm not a student (so I have a job and related duties) but I would like to assist with debugging in my spare time! |
Don't worry, neither am I. Believe it or not, I teach medicine for living. I have opened a specific issue for that so as not to clutter your repo and this issue with tangentially related things. Anybody with any relevant skills/craft/knowledge/time (even if just a little) is welcome to participate. |
Did someone manage to actually implement this? What is currently the best way to set battery protection? Also as this seems to be ACPI setting maybe it would be possible to set it in config.plist. I guess most users just use one scheme most of the time like home (40-70) or office (70-90)? |
@profzei et al. I have just implemented quick and a bit dirty way of activating battery thresholds for MBXP. Using the directions and tips from this thread I created a small ACPI patch to activate battery saving thresholds during system startup. Obviously it is not an interactive solution as changing thresholds is a bit of work, but does not require installing ACPI Debug Kext. From my experience I usually just set family mode (40-70) and use it all the time, hence limited need for changing the setting in my case. In case one wants to use 40-70 thresholds all you have to do is to copy SSDT-BATTHR.aml from SSDT-BATTHR.zip to EFI->OC->ACPI and add it to ACPI -> Add in your config.plist. Next restart the system and thresholds are applied. If you want to change the thresholds grab a copy of MaciASL from here: https://github.com/acidanthera/MaciASL/releases and open SSDT-BATTHR.dsl from the SSDT-BATTHR.zip and change the thresholds here:
Thresholds should be converted to hex i.e. 20-65 would be 0x14-0x41 so it gives 0x41140000 and we put it into code:
Then save it as ACPI Machine Language Binary (aml) and the rest is the same, i.e. copy to EFI -> OC -> ACPI and add to config.plist and the reboot. Let me know if this works for you ;] |
@PLTorrent What you provided is very similar to what I wrote more than one year ago just for myself... A very elegant solution, instead, was proposed by @ldan93 i.e. porting on macOS Matebook-applet project, but, as you said, it is complicated making it very clean! Knowledge for programming in macOS is required... |
Does your code work without reboot ? If that is the case I could make a simple GUI for it. |
First, thank you for your great work !
There is one feature of our Matebook that I miss from Windows/Linux : setting battery thresholds.
What is it ?
When you use your laptop plugged in the AC power for a long time, it’s healthier to keep your battery mid-charged. So, if you rarely use your Matebook in battery mode, setting a threshold greatly increases your battery’s lifespan in the long-run.
How does it work ?
There is a minimum and a maximum values stored inside the Embedded Controller (EC) within the ACPI tables. For example, if you set it to 50 / 60, your battery will charge up to a value between 50% and 60% and then, the computer will only drain power from AC, letting your battery idle.
Under Windows, this feature is handled by Huawei’s built-in « PC Manager ». Under Linux, it has been implemented through scripts writing custom values to the EC tables (https://github.com/nekr0z/linux-on-huawei-matebook-13-2019/blob/master/batpro) or through cleaner ACPI methods (https://github.com/aymanbagabas/Huawei-WMI).
How can we make it work under MacOS ?
From what I understand from nekr0z’s script, to implement this feature, all we have to do it to write the minimum and maximum thresholds to the
0xe4
and0xe5
registries of the EC’s tables (nekr0z/linux-on-huawei-matebook-13-2019#2 (comment)).People successfully implemented this feature for other laptop brands using RehabMan’s kext OS-X-ACPI-Poller (https://github.com/RehabMan/OS-X-ACPI-Poller). An example with Lenovo laptops : https://www.insanelymac.com/forum/topic/342280-battery-charge-thresholds-and-related-controls/
This method seems to be very similar to RehabMan’s approach to controlling fans through custom EC values : https://www.tonymacx86.com/threads/new-fan-control-dsdt-for-silent-fan-at-higher-temps.72043/
I’ve spent some time collecting all of the useful details, but actually implementing this feature for the Matebook X Pro is way beyond my personal abilities… ATM, I use a Linux USB installation to set the threshold from there, and I then reboot to MacOS. But this is far from convenient, and the values get reset from time to time…
I think adding this feature to your guide would be very nice and useful for many users. Would you be interested to have a look at it ? Even though I’m a total beginner with Hackintosh, I would do my best to help you, of course.
The text was updated successfully, but these errors were encountered: