Skip to content
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

To those wanting to check the battery level on their 3DS #206

Open
LexiBigCheese opened this issue Jan 19, 2025 · 0 comments
Open

To those wanting to check the battery level on their 3DS #206

LexiBigCheese opened this issue Jan 19, 2025 · 0 comments

Comments

@LexiBigCheese
Copy link

pub struct Mcuhwc(());

impl Mcuhwc {
    pub fn new() -> ctru::Result<Mcuhwc> {
        unsafe {
            ctru::error::ResultCode(ctru_sys::mcuHwcInit())?;
            Ok(Mcuhwc(()))
        }
    }
    pub fn batt(&self) -> u8 {
        let mut out = 0u8;
        unsafe {
            let _ = ctru_sys::MCUHWC_GetBatteryLevel(&mut out);
        }
        out
    }
}

impl Drop for Mcuhwc {
    fn drop(&mut self) {
        unsafe {
            ctru_sys::mcuHwcExit();
        }
    }
}

I don't know what the values are between, but I'm pretty sure you can treat it as a percentage (as in, 88u8 is 88% battery)
There's also a function in ctru_sys to get the Charging State, but you can implement that yourself, right? I believe in you, programmer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant