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

📄 gpsapp.c

📁 一个用c写的GPS定位相关的brew应用程序.
💻 C
字号:
/**
***     GPSApp.c
***
***     偙偺僜乕僗僐乕僪偼丄僄儔乕張棟傗僗僩僢僾仌僒僗儁儞僪側偳偺張棟偑敳偗偰偄傑偡丅
***     Copyright (C) 2006 SophiaCradle Incorporated.
***     All rights reserved.
**/

#include "AEEModGen.h"
#include "AEEAppGen.h"
#include "AEEStdLib.h"
#include "AEEShell.h"
#include "Common.h"
#include "GPSApp.bid"
#include "AEEPosDet.h"

typedef struct GPSApp {
    AEEApplet a; // 傾僾儗僢僩峔憿懱偺愭摢儊儞僶偼昁偢 AEEApplet 宆偵偡傞偙偲丅
    Common common; //昤夋梡

    IPosDet* posdet;
    AEEGPSInfo gpsinfo; //  AEEGPSInfo 峔憿懱偺曄悢 ( GPS 偐傜庢摼偟偨僨乕僞傪曐懚)
    AEECallback callback;
} GPSApp;

static boolean GPSApp_HandleEvent(GPSApp* app, AEEEvent eCode, uint16 wParam, uint32 dwParam);
static boolean OnAppStart(GPSApp* app);
static boolean OnAppStop(GPSApp* app);
static boolean OnKey(GPSApp* app, uint16 key);
static void GetGPS(GPSApp* app);
static void OnGPSNotify(GPSApp* app);

int AEEClsCreateInstance(AEECLSID ClsId, IShell* pIShell, IModule* po, void** ppObj)
{
    *ppObj = NULL;
    if (ClsId == AEECLSID_GPSAPP) {
        if (AEEApplet_New(sizeof(GPSApp), ClsId, pIShell, po, (IApplet**)ppObj, (AEEHANDLER)GPSApp_HandleEvent, NULL) == TRUE) {
            return AEE_SUCCESS;
        }
    }
    return EFAILED;
}

static boolean GPSApp_HandleEvent(GPSApp* app, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
    switch (eCode) {
        case EVT_APP_START:
            return OnAppStart(app);

        case EVT_APP_STOP:
            return OnAppStop(app);

        case EVT_KEY:
            return OnKey(app, wParam);
    }
    return FALSE;
}

// 傾僾儗僢僩偑奐巒偟偨偲偒偵屇傃弌偝傟傞丅
static boolean OnAppStart(GPSApp* app)
{
    IDisplay* display = app->a.m_pIDisplay;
    IShell* shell = app->a.m_pIShell;

    // IPosDet 僀儞僞僼僃乕僗偺僀儞僗僞儞僗壔
    app->posdet = NULL;
    ISHELL_CreateInstance(app->a.m_pIShell, AEECLSID_POSDET, (void**)&app->posdet);

    COMMON_Init(&app->common, display, shell, 32768);
    COMMON_WriteString(&app->common, "Push Select Key to get GPS information\n");
    COMMON_Draw(&app->common);
    return TRUE;
}

// 傾僾儗僢僩偑廔椆偟偨偲偒偵屇傃弌偝傟傞丅
static boolean OnAppStop(GPSApp* app)
{
    CALLBACK_Cancel(&app->callback);
	IPOSDET_Release(app->posdet);
    COMMON_Free(&app->common);
    return TRUE;
}

// 僉乕偑墴偝傟偨偲偒偵屇傃弌偝傟傞丅
static boolean OnKey(GPSApp* app, uint16 key)
{
    switch (key) {
        case AVK_SELECT:
            GetGPS(app);
            return TRUE;

        case AVK_DOWN:
            COMMON_NextLine(&app->common);
            COMMON_Draw(&app->common);
            return TRUE;

        case AVK_UP:
            COMMON_PreviousLine(&app->common);
            COMMON_Draw(&app->common);
            return TRUE;
    }
    return FALSE;
}

// 埵抲忣曬偺庢摼
static void GetGPS(GPSApp* app)
{
    int ret;
    char buffer[80];

    // 僐乕儖僶僢僋娭悢偺愝掕
    CALLBACK_Init(&app->callback, (PFNNOTIFY)OnGPSNotify, (void*)app);
    // 埵抲忣曬偺庢摼
    ret = IPOSDET_GetGPSInfo(app->posdet, AEEGPS_GETINFO_LOCATION, AEEGPS_ACCURACY_LEVEL6, &app->gpsinfo, &app->callback);
    // 忋婰娭悢偺栠傝抣傪僠僃僢僋
    switch (ret) {
        case EPRIVLEVEL:
            STRCPY(buffer, "EPRIVLEVEL");
            break;

        case EBADPARM:
            STRCPY(buffer, "EBADPARM");
            break;

        case EUNSUPPORTED:
            STRCPY(buffer, "EUNSUPPORTED");
            break;

        case EFAILED:
            STRCPY(buffer, "EFAILED");
            break;

        case SUCCESS:
            STRCPY(buffer, "SUCCESS");
            break;

        default:
            STRCPY(buffer, "DEFAULT");
            break;
    }
    // 幐攕偟偰偄偨傜僐乕儖僶僢僋傪僉儍儞僙儖
    if (ret != SUCCESS) {
        CALLBACK_Cancel(&app->callback);
    }

    // 埵抲忣曬庢摼娭悢偺栠傝抣傪弌椡
    COMMON_WriteString(&app->common, buffer);
    COMMON_WriteString(&app->common, "\n");
    COMMON_Draw(&app->common);
    return;
}

// 埵抲忣曬傪庢摼屻偺張棟
static void OnGPSNotify(GPSApp* app)
{
    char szLat[32];
    char szLon[32];
    char szBuf[64];
    char latchar[64];
    char lonchar[64];
    AECHAR latwchar[64];
    AECHAR lonwchar[64];
    double lat;
    double lon;

    lat = WGS84_TO_DEGREES(app->gpsinfo.dwLat);
    lon = WGS84_TO_DEGREES(app->gpsinfo.dwLon);
    FLOATTOWSTR(lat, latwchar, 64);
    FLOATTOWSTR(lon, lonwchar, 64);
    WSTRTOSTR(latwchar, latchar, 64);
    WSTRTOSTR(lonwchar, lonchar, 64);

    // 堒搙偺庢摼
    SPRINTF(szLat, "Latitude = %d", app->gpsinfo.dwLat);
    // 宱搙偺庢摼
    SPRINTF(szLon, "Longitude = %d", app->gpsinfo.dwLon);
    // 堒搙偺昤夋
    COMMON_WriteString(&app->common, szLat);
    COMMON_WriteString(&app->common, "\n");
    COMMON_WriteString(&app->common, latchar);
    COMMON_WriteString(&app->common, "\n");
    // 宱搙偺昤夋
    COMMON_WriteString(&app->common, szLon);
    COMMON_WriteString(&app->common, "\n");
    COMMON_WriteString(&app->common, lonchar);
    COMMON_WriteString(&app->common, "\n");
    // 儗僗億儞僗偺僄儔乕僠僃僢僋
    switch (app->gpsinfo.status) {
        case AEEGPS_ERR_NO_ERR:
            STRCPY(szBuf, "SUCCESS !");
            break;

        case AEEGPS_ERR_GENERAL_FAILURE:
            STRCPY(szBuf, "AEEGPS_ERR_GENERAL_FAILURE");
            break;

        case AEEGPS_ERR_TIMEOUT:
            STRCPY(szBuf, "AEEGPS_ERR_TIMEOUT");
            break;

        case AEEGPS_ERR_ACCURACY_UNAVAIL:
            STRCPY(szBuf, "AEEGPS_ERR_ACCURACY_UNAVAIL");
            break;

        case AEEGPS_ERR_INFO_UNAVAIL:
            STRCPY(szBuf, "AEEGPS_ERR_INFO_UNAVAIL");
            break;

        default:
            STRCPY(szBuf, "DEFAULT");
            break;
    }
    // 儗僗億儞僗偺僗僥乕僞僗傪昤夋
    COMMON_WriteString(&app->common, szBuf);
    COMMON_WriteString(&app->common, "\n");
    COMMON_Draw(&app->common);
    return;
}

⌨️ 快捷键说明

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