⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mybattery.c

📁 高通 BREW 培训 实用例子
💻 C
📖 第 1 页 / 共 2 页
字号:
                        DisplayText(pMe);
                        return(TRUE);
                    } 
                    SPRINTF(szBuf, "Cancle Noitfier ok");
                    STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUF_SIZE);
                    DisplayText(pMe);
                    return(TRUE);
                }

                case RT_QUERYINT_IMODEL:
                {
                    char szBuf[512];
                    DBGPRINTF("RT_QUERYINT_IMODEL");

                    STRTOWSTR("IMODEL command", pMe->m_szTitle,sizeof(pMe->m_szTitle));

                    nErr = IBATTERY_QueryInterface(pMe->m_pIBattery, AEEIID_MODEL, (void **) (&(pMe->m_pIModel)));
                    if ( nErr != SUCCESS)
                    {
                        DBGPRINTF("IBATTERY_QueryInterface failure");
                        return (TRUE);
                    }

                    LISTENER_Init(&pMe->myModelListerner, mybattery_EventProcess, pMe);

                    nErr = IModel_AddListener(pMe->m_pIModel, &pMe->myModelListerner); 
                    if(nErr != AEE_SUCCESS)
                    {
                        DBGPRINTF("IModel_AddListener failure");
                        SPRINTF(szBuf, "IModel_AddListener failure\n");
                        STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUF_SIZE);
                    }
                    else
                    {
                        DBGPRINTF("IModel_AddListener ok");
                        SPRINTF(szBuf, "IModel_AddListener ok\n");
                        STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUF_SIZE);

                    }
                    DisplayText(pMe);
                    return (TRUE);
                }

                case RT_QUERYINT_IMODEL_CANCEL:
                {
                    char szBuf[512];
                    boolean isRegisted;
                    STRTOWSTR("Cancle imodel", pMe->m_szTitle,sizeof(pMe->m_szTitle));

                    isRegisted = LISTENER_IsRegistered(&(pMe->myModelListerner));
                    DBGPRINTF("Imodel reg listener? %d", isRegisted);
                    
                    if ( isRegisted)
                    {
                        LISTENER_Cancel(&(pMe->myModelListerner));
                        SPRINTF(szBuf, "Cancel registed IModel ok\n");
                        STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUF_SIZE);
                        DisplayText(pMe);
                    }
                    else
                    {
                        SPRINTF(szBuf, "No IModel registed\n");
                        STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUF_SIZE);
                        DisplayText(pMe);
                    }
                    return(TRUE);
                }
    
                case SOFTMENU_BACK:
                {
                  DBGPRINTF("SOFTMENU_BACK");
                  if (pMe->m_pIStatic != NULL)
                  {
                    ISTATIC_Release(pMe->m_pIStatic);
                    pMe->m_pIStatic = NULL;
                  }
                  IMENUCTL_SetActive(pMe->m_pISoftMenu, FALSE);
                  IMENUCTL_SetActive(pMe->m_pIMainMenu, TRUE);
                  IDISPLAY_ClearScreen(pMe->m_pIDisplay);
                  IMENUCTL_Redraw(pMe->m_pIMainMenu);
                  return (TRUE);
                }
                      

                default:
                    return TRUE;
              }
              return(TRUE);


        case EVT_NOTIFY:
            {
                    uint32 uIsExtPowerExist;
                    AEENotify* pNotify = (AEENotify*) dwParam;
                    char szBuf[80];
                    AECHAR wszText[80];

                    // notifer monitor status of battery
                    if (pNotify && (pNotify->cls == AEECLSID_BATTERYNOTIFIER)) // event sender
                    {
                        DBGPRINTF("AEECLSID_BATTERYNOTIFIER sender");

                        if ((pNotify->dwMask & NMASK_BATTERY_EXTPWR_CHANGE)) 
                        {
                            DBGPRINTF("Notify mask ok");
                            uIsExtPowerExist = (uint32 )pNotify->pData;

                            SPRINTF(szBuf, "Notify ext pow: %d \n", uIsExtPowerExist);
                            STRTOWSTR(szBuf, wszText, sizeof(wszText));
                            WSTRCAT(pMe->m_pszText, wszText);
                            
                            DisplayText(pMe);
                        }
                    }
                    
                    return(TRUE);
            }

#if 0
            
            case EVT_NOTIFY: // example for battery level change event
            {
                char szBuf[512];
                uint16 nScale = 0;  // battery scale
                uint16 nLevel = 0;  // battery level
                AEENotify* pNotify = (AEENotify*)(dwParam);
                uint32 dwData = (uint32 ) (pNotify->pData); // for new battery level
                nScale = GETBATTERYSCALE(dwData);
                nLevel = GETBATTERYLEVEL(dwData);
        
                //if(pMe->m_pISoftMenu && IMENUCTL_IsActive(pMe->m_pISoftMenu))
                //{
                //  ISTATIC_Release(pMe->m_pIStatic);
                //}
                DBGPRINTF("UNIBREW: EVT_NOTIFY received for battery level change!");
                DBGPRINTF("Scale=%d, Level=%d", nScale, nLevel);
                
                STRTOWSTR("New Battery Level Info", pMe->m_szTitle, sizeof(pMe->m_szTitle));
                SPRINTF(szBuf, "Scale = %d, Level = %d\n", nScale, nLevel);
                STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUF_SIZE);
                DisplayText(pMe);
                IMENUCTL_Redraw(pMe->m_pISoftMenu);
                return TRUE;
              }
#endif            
              // If nothing fits up to this point then we'll just break out
              default:
                  break;
           }
        
           return FALSE;
}


// this function is called when your application is starting up
static boolean mybattery_InitAppData(mybattery* pMe)
{
    int nErr = SUCCESS;
    AECHAR szBuf[15];
  
    // Get the device information for this handset.
    // Reference all the data by looking at the pMe->DeviceInfo structure
    // Check the API reference guide for all the handy device info you can get
    pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
    ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);

    // Insert your code here for initializing or allocating resources...
    pMe->m_pIDisplay = pMe->a.m_pIDisplay;
    pMe->m_pIShell = pMe->a.m_pIShell;
    if ( ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_MENUCTL, (void **) (&(pMe->m_pIMainMenu))) != SUCCESS)
    {
        return FALSE;
    }

    if ( ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_SOFTKEYCTL, (void **) (&(pMe->m_pISoftMenu))) != SUCCESS)
    {
        return FALSE;
    }

    STRTOWSTR("Back", szBuf, sizeof(szBuf));
    if (!IMENUCTL_AddItem(pMe->m_pISoftMenu, 0, 0, SOFTMENU_BACK, szBuf, 0))
    {
        return FALSE;
    }

    if ( (pMe->m_pszText = (AECHAR *) MALLOC(TEXT_BUF_SIZE)) == NULL)
    {
        return FALSE;
    }
  
    if ( (nErr = ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_BATTERY, (void **) (&(pMe->m_pIBattery)))) != SUCCESS)
    {
        DBGPRINTF("UNIBREW: ERR%d, failed to create IBattery obj!", nErr);
        return FALSE;
    }

    // if there have been no failures up to this point then return success
    return TRUE;
}

// this function is called when your application is exiting
static void mybattery_FreeAppData(mybattery* pMe)
{
    // insert your code here for freeing any resources you have allocated...

    // example to use for releasing each interface:
    // if ( pMe->pIMenuCtl != NULL )         // check for NULL first
    // {
    //    IMENUCTL_Release(pMe->pIMenuCtl)   // release the interface
    //    pMe->pIMenuCtl = NULL;             // set to NULL so no problems trying to free later
    // }
    //

  if( pMe->m_pIStatic != NULL)
  {
    ISTATIC_Release(pMe->m_pIStatic);
    pMe->m_pIStatic = NULL;
  }

  if( pMe->m_pIMainMenu != NULL)
  {
    IMENUCTL_Release(pMe->m_pIMainMenu);
    pMe->m_pIMainMenu = NULL;
  }

  if( pMe->m_pISoftMenu != NULL)
  {
    IMENUCTL_Release(pMe->m_pISoftMenu);
    pMe->m_pISoftMenu = NULL;
  }
  
  if( pMe->m_pIBattery != NULL)
  {
    IBATTERY_Release(pMe->m_pIBattery);
    pMe->m_pIBattery = NULL;
  }

  FREEIF(pMe->m_pszText);
}

static void BuildMainMenu(mybattery *pMe) 
{

    AECHAR szBuf[40];
    AEERect rect;

    SETAEERECT(&rect, 0, 0, pMe->DeviceInfo.cxScreen, pMe->DeviceInfo.cyScreen);

    IMENUCTL_SetRect(pMe->m_pIMainMenu, &rect);

    // Set Title
    STR_TO_WSTR("MyBattery charge demo", szBuf, sizeof(szBuf));
    IMENUCTL_SetTitle(pMe->m_pIMainMenu, NULL, 0, szBuf);

    //Add individual entries to the Menu

    STR_TO_WSTR("1. Battery Status Info", szBuf, sizeof(szBuf));
    IMENUCTL_AddItem(pMe->m_pIMainMenu, 0, 0, RT_BATTERY_INFO, szBuf, 0);

    STR_TO_WSTR("2. Add Notify Listener", szBuf, sizeof(szBuf));
    IMENUCTL_AddItem(pMe->m_pIMainMenu, 0, 0, RT_BATTERY_NOTIFY, szBuf, 0);

    STR_TO_WSTR("3. Cancle Notify Listener", szBuf, sizeof(szBuf));
    IMENUCTL_AddItem(pMe->m_pIMainMenu, 0, 0, RT_BATTERY_NOTIFY_CANCEL, szBuf, 0);

    STR_TO_WSTR("4. IModel Register", szBuf, sizeof(szBuf));
    IMENUCTL_AddItem(pMe->m_pIMainMenu, 0, 0, RT_QUERYINT_IMODEL, szBuf, 0);

    STR_TO_WSTR("5. Cancle IModel Reg", szBuf, sizeof(szBuf));
    IMENUCTL_AddItem(pMe->m_pIMainMenu, 0, 0, RT_QUERYINT_IMODEL_CANCEL, szBuf, 0);

    if(pMe->m_pISoftMenu)
    {
        IMENUCTL_SetActive(pMe->m_pISoftMenu,FALSE);
    }
    IMENUCTL_SetActive(pMe->m_pIMainMenu,TRUE);
}

static void DisplayText(mybattery *pMe)
{
  int nErr = SUCCESS;
  AEERect rect;

  if ( (nErr = ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_STATIC, (void **)(&(pMe->m_pIStatic)))) != SUCCESS)
  {
    DBGPRINTF("UNIBREW: ERR%d, failed to create IStatic instance!", nErr); 
    return;
  }
  
  //SETAEERECT(&rect, 0, 0, pMe->DeviceInfo.cxScreen, pMe->DeviceInfo.cyScreen);
    SETAEERECT(&rect, 2, 2, pMe->DeviceInfo.cxScreen - 4, pMe->DeviceInfo.cyScreen - BOTTOM_TEXT_HEIGHT);
  
  IMENUCTL_SetActive(pMe->m_pIMainMenu, FALSE);
  IDISPLAY_ClearScreen(pMe->m_pIDisplay);
  
  
  ISTATIC_SetRect(pMe->m_pIStatic, &rect);
  if (ISTATIC_SetText(pMe->m_pIStatic, pMe->m_szTitle, pMe->m_pszText, AEE_FONT_BOLD, AEE_FONT_NORMAL) == FALSE)
    {
        ISTATIC_Release (pMe->m_pIStatic);
        pMe->m_pIStatic = NULL;
        return;
    }

    ISTATIC_Redraw(pMe->m_pIStatic);

    IMENUCTL_SetActive(pMe->m_pISoftMenu,TRUE);
    IDISPLAY_Update(pMe->m_pIDisplay);

}

static void     mybattery_EventProcess (void *pUserData, ModelEvent *pEvent)
{
    char szBuf[80];
    AECHAR wszText[80];
    mybattery *pMe=(mybattery *)pUserData;
    uint32 uIsExtPowerExist;

    if(pMe==NULL)
    {
        return;
    }
    
    switch (pEvent->evCode) 
    {
        case EVT_MDL_BATTERY_EXTPWR_CHANGE:
               DBGPRINTF("EVT_MDL_BATTERY_EXTPWR_CHANGE");
               uIsExtPowerExist = (uint32 )pEvent->dwParam;

               SPRINTF(szBuf, "IModel ext pow: %d \n", uIsExtPowerExist);
               STRTOWSTR(szBuf, wszText, sizeof(wszText));
               WSTRCAT(pMe->m_pszText, wszText);
               DisplayText(pMe);

            break;

        default:
            break;

    }
    
    return;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -