How do I check if the 3ds charger is plugged in?

43 views Asked by At

I am writting a function to know wether or not the charger is plugged in my 3ds however my function keep returning false while the charger is plugged in.

I expect my function to return true if the charger is plugged in my 3ds.

Here is the function:

bool isChargerPluggedin() {
    bool chargeState;
    PTMU_GetAdapterState(&chargeState);
    return chargeState == 1;
}

My first attempt to solve my problem was to allocate memory to the chargeState variable:

bool isChargerPluggedin() {
    bool *chargeState = new bool;
    PTMU_GetAdapterState(chargeState);
    bool state = *chargeState == 1;
    delete chargeState;
    return state;
}

My second attempt was by using an global variable to chargeState instead of a local variable :

bool chargeState;
bool isChargerPluggedin() {
    PTMU_GetAdapterState(&chargeState);
    return chargeState == 1;
}
1

There are 1 answers

0
The epic face 007 On BEST ANSWER

To fix this, you must initialize first the libraries in your main function using the function ptmuInit. You must deinitialize the library before your program exitHere is a example:

int main() {
  ptmuInit();
  // program loop
  while (true) {
    bool isPlugged = isChargerPluggedin();
    ...
  }
  ptmuExit();
}