如何获取 Mac(Cocoa 或 C)的电池电量(以 mWh(而非百分比)为单位)
标题几乎解释了一切。我正在创建一个 Mac 应用程序,我需要电池电量具体以 mWh 为单位(而不是百分比)。最好用 C 或 Objective C 来做。
谢谢!
The title pretty much explains it all. I'm creating a mac app and I need the battery charge level specifically in mWh (not percentage). Would like to do it in C or Objective C preferably.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,这里有一些代码可以直接回答我的问题,即获取以 mWh 为单位的电池充电水平。它并不完美,但它可以完成工作。
So here is a bit of code that directly answers my question which is getting the Battery Charge Level in mWh. It's not perfect, but it does the job.
这可能对您没有帮助,但我确实知道 ioreg 命令行程序可以转储有关计算机电池的各种精彩统计数据,包括设计容量、当前容量和当前充电水平毫安时。 (
ioreg -l
为您提供了非常详细的输出,所有这些)如果您能弄清楚该程序使用什么 API,您也可以做同样的事情。或者您可以从您的应用程序调用该程序并捕获输出。
This probably doesn't help you, but I do know that the
ioreg
command line program can dump out all kinds of wonderful stats about your computer's battery, including design capacity, current capacity, and current charge level in mAh. (ioreg -l
gives you really verbose output with all of this) If you can figure out what API that program uses, you could do the same.Or you could just call the program from your app and capture the output.
抱歉,但我认为硬件没有办法报告这一点。随着电池进入其生命周期,它会随着时间的推移而发生变化,而您一开始所能知道的只是电池安装时的标称容量。
Sorry, but I don't think the hardware has a way to report that. It's going to change over time as the battery gets on in its life cycle, and all you could know at the outset is the nominal capacity of the battery when it was installed.