Re: How to get Laptop battery level

2021-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 22, 2021 at 08:59:01PM +, Greatsam4sure via Digitalmars-d-learn 
wrote:
> Dlang is a system programming language. How do I access the battery
> level of my system using code in dlang? I will appreciate vide sample

There is no universal API for this.  It depends on which OS you're
using.  For that, you need to consult your OS's documentation. Most
likely there will be some kind of C API or system library that could
give you this information.

D can't possibly provide a universal API for something like this because
it varies too widely -- some platforms do not have any meaningful
notion of "battery level", whereas other systems may well have multiple
"battery levels" and it would be ambiguous which one is meant.  If you
want to do systems programming you have to know the system you're
programming, and be prepared to call OS APIs yourself.


T

-- 
The irony is that Bill Gates claims to be making a stable operating system and 
Linus Torvalds claims to be trying to take over the world. -- Anonymous


Re: How to get Laptop battery level

2021-02-22 Thread Dukc via Digitalmars-d-learn

On Monday, 22 February 2021 at 21:14:48 UTC, Dukc wrote:
Note that DGame seems to be currently unmaintained - it might 
have some bits that do not compile anymore. SDL2 is a commonly 
used library though - you should be able to find more examples 
about it if you need to.


Plus, the example I linked is not really the simple minimalistic 
one you want if battery level is all you want to figure out. 
Probably the derelict-sdl2 front page is what you're looking for 
that instead:


https://code.dlang.org/packages/derelict-sdl2


Re: How to get Laptop battery level

2021-02-22 Thread Dukc via Digitalmars-d-learn

On Monday, 22 February 2021 at 20:59:01 UTC, Greatsam4sure wrote:
Dlang is a system programming language. How do I access the 
battery level of my system using code in dlang?


As a systems language, D could access the hardware interface 
directly, if you knew it and loaded your program as a kernel 
driver - if your operating system lets you do that.


Now, I don't think that was the most practical way to approach 
the problem :-). Instead, I recommend you use the SDL2 multimedia 
library to give you a more portable interface. Usage example in D 
here: 
https://github.com/Dgame/Dgame/blob/master/source/Dgame/System/Battery.d


Note that the D module I linked does not contain the machinery to 
initialize SDL2. This module seems to contain that:

https://github.com/Dgame/Dgame/blob/master/source/Dgame/Window/Window.d

Note that DGame seems to be currently unmaintained - it might 
have some bits that do not compile anymore. SDL2 is a commonly 
used library though - you should be able to find more examples 
about it if you need to.


Re: How to get Laptop battery level

2021-02-22 Thread Greatsam4sure via Digitalmars-d-learn

On Monday, 22 February 2021 at 20:59:01 UTC, Greatsam4sure wrote:
Dlang is a system programming language. How do I access the 
battery level of my system using code in dlang? I will 
appreciate code sample


Sorry I mean to say code sample