Ai-Thinker-Open / GPRS_C_SDK

Ai-Thinker A9/A9G GPRS (with GPS(A9G)) module C development SDK
https://ai-thinker-open.github.io/GPRS_C_SDK_DOC
MIT License
448 stars 234 forks source link

How to use this API_EVENT_ID_POWER_INFO #382

Open stbungaof opened 4 years ago

stbungaof commented 4 years ago

//power API_EVENT_ID_POWER_INFO , //param1: (PM_Charger_State_t<<16|charge_level(%)) , param2: (PM_Battery_State_t<<16|battery_voltage(mV))

form https://github.com/Ai-Thinker-Open/GPRS_C_SDK/blob/master/include/api_inc/api_event.h

stbungaof commented 4 years ago

How to get data form param1 and param2

allejp commented 4 years ago

Hi, you can extract info in this way:

        uint8_t percentage = 0xFFFF & pEvent->param1;
        uint16_t voltage = 0xFFFF & pEvent->param2;

        PM_Charger_State_t cs = 0xFFFF & (pEvent->param1 >> 16);
        PM_Battery_State_t bs = 0xFFFF & (pEvent->param2 >> 16);

I noticed that the values are not updated quickly, the most updated value is obtained in this way:

        uint8_t percentage = 0;
        uint16_t voltage = PM_Voltage(&percent);