英文:
How do I check if the 3ds charger is plugged in?
问题
I am writing a function to know whether or not the charger is plugged in my 3DS. However, my function keeps returning false while the charger is plugged in.
I expect my function to return true if the charger is plugged into 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 a global variable for chargeState
instead of a local variable:
bool chargeState;
bool isChargerPluggedin() {
PTMU_GetAdapterState(&chargeState);
return chargeState == 1;
}
英文:
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
得分: 0
为了解决这个问题,你必须在你的主函数中首先使用函数 ptmuInit
初始化库。在程序退出之前,你必须反初始化这个库。以下是一个示例:
int main() {
ptmuInit();
// 程序循环
while (true) {
bool isPlugged = isChargerPluggedin();
...
}
ptmuExit();
}
英文:
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();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论