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

📄 cmapi.c

📁 MATSNL is a package of MATLAB M-files for computing wireless sensor node lifetime/power budget and
💻 C
📖 第 1 页 / 共 2 页
字号:
    return status;}/* * Function: cmImageSnap * * Description: Take an image * * Inputs: *          ImageType       Currently not implemented, but to be used to *                          setup all of the properties and attributes before *                          taking the image. *                          If the parameter is NULL, the current image  *                          settings are used. * Outputs: * * Returns: *      < 0     Error */int cmImageSnap (Image_t *ImageType){	int status = 0;    int counter = 0;    unsigned int flag = 0;    int cmStatusGet(unsigned int  *flag_p);    int cmVideoEnable (void);    cmVideoEnable();    while (cmStatusGet (&flag) == 1) {        ++counter;        if (counter > 100) {            printf ("Not good image..");            status = -1;            break;        }//        cmAbort();//        cmVideoEnable();        Sleep (3);            }    if (status == 0) {        status = cmRegisterWrite (CM_CMD_2, CM_CMD_2_STILL);    }	return status;}int cmImageVid (void){    int status = 0;    int counter = 0;    unsigned int flag = 0;    int cmStatusGet(unsigned int  *flag_p);    int cmVideoEnable (void);    cmVideoEnable();    while (cmStatusGet (&flag) == 1) {        ++counter;        if (counter > 100) {            printf ("Not good image..");            status = -1;            break;        }//        cmAbort();//        cmVideoEnable();        Sleep (3);            }        return status;}/* * Function: cmWrite2File * * Description: Write the jpeg data to a file * * Inputs: *      buffer      Buffer containing the full jpg data *      bufferLen   Number of bytes of data *      filename    Name of the output file * * Outputs: * * Returns: * *      < 0         Error */void cmWrite2File (unsigned char *whole_jpg, int whole_jpg_len, char *filename){    HANDLE fileh;           /* output file handle */    unsigned long  written;            /* number of bytes written */    BOOL bResult;    /* Open file */    fileh = CreateFile (filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);    if (fileh == INVALID_HANDLE_VALUE) {        printf ("Error opening file %s\n", filename);        return;    }    bResult = WriteFile (fileh, whole_jpg, whole_jpg_len , &written, NULL);    if (!bResult) {     /* for now, ignore the # bytes written */        printf ("Error writing file %d\n", GetLastError());    }    printf ("%d bytes written to %s\n", written, filename);    /* close file */    CloseHandle (fileh);}/* * Function: cmAbort * * Description: Abort any active image in the buffer * * Inputs: void * * Outputs: * * Returns: void */void cmAbort(void){    cmRegisterWrite (CM_CMD_2, CM_CMD_2_ABORT);}  /* * Function: cmApiSet * * Description: Set parameters within the API * * Input parameters: * * Output parameters: * * Returns: */int cmApiSet (int tag, int value) {    int status = 0;    switch (tag) {        case CM_TAG_BAUDRATE:            cmComSet (CMCOM_TAG_BAUDRATE, value);            break;        case CM_TAG_PACKETCODE:            g_getImageMode = value;            break;        case CM_TAG_IMAGE_TIMEOUT:            g_image_timeout = value;        default:            break;      // ignore the rest    }    return status;}/* * Function: gcmGetStatus * * Description: Return the status of the frame buffer and image capture * * Returns: *      0 = OK *      1 = Not OK, wait before reading image. */int cmStatusGet (unsigned int *flag_p) {    int status = 0;    cmRegisterRead (CM_REG_STATUS_FLAGS, flag_p);    if (!(*flag_p & CM_STATUS_FLAGS_AEWB_C)) {         // AE AWB not converged        if (g_debug > 0) {            printf ("AE/AWB not converged.\n");            fflush (NULL);        }        status = 1;    } else if (!(*flag_p & CM_STATUS_FLAGS_FB_C_OK)) { // good frame        if (g_debug > 0) {            printf ("Bad Frame\n");            fflush (NULL);        }        status = 1;    }    return status;}/* * Function: cmVideoEnable * * Description: Enable the video mode * */int cmVideoEnable (void){    int status = 0;    cmRegisterWrite (CM_REG_CMD_1, 0x0001);    return status;}/* * Function: cmImageTypeSet * * Description: Set the format of the output type. * *      This function sets the output format on the imager for both the *      video and still mode. *      Implementation note: the enumeration type corresponds to the  *      2670 "Final/Snapshot" values, Start of Packet Code (SOP). * * Input Parameters: * * Output Parameters: * * Returns: */int cmImageTypeSet (ImageType_t type){    int status = 0;    switch (type) {        case CM_TYPE_DEFAULT:            break;        case CM_TYPE_RGB888:            break;        case CM_TYPE_RGB666A:            break;        case CM_TYPE_RGB666B:            break;        case CM_TYPE_RGB565:            break;        case CM_TYPE_RGB444A:            break;        case CM_TYPE_RGB444B:            break;        case CM_TYPE_RGB444C:            break;        case CM_TYPE_RGB332:            break;        case CM_TYPE_YUV422A:            break;        case CM_TYPE_YUV422B:            break;        case CM_TYPE_YUV422C:            break;        case CM_TYPE_YUV422D:            break;        case CM_TYPE_YUV444:            break;        case CM_TYPE_GREY:            break;        case CM_TYPE_RAWBPA:            break;        case CM_TYPE_RAW:            break;        default:             break;    }    return status;}/* * convert from the values in bits 8-11 of either the VIDEO_CONFIG * or the STILL_CONFIG to the API Type. * * The 1670 type must be a mask of bits 8-11:  config & 0x0F00 * * JPEG types are handled differently. */int Type1670ToApi (unsigned int type1670, ImageType_t *type_p){    int status = 0;    switch (type1670) {        case CM_CONFIG_O_FORMAT_RGB888:            *type_p = CM_TYPE_RGB888;            break;        case CM_CONFIG_O_FORMAT_RGB666A:            *type_p = CM_TYPE_RGB666A;            break;        case CM_CONFIG_O_FORMAT_RGB666B:            *type_p = CM_TYPE_RGB666B;            break;        case CM_CONFIG_O_FORMAT_RGB565:            *type_p = CM_TYPE_RGB565;            break;        case CM_CONFIG_O_FORMAT_RGB444A:            *type_p = CM_TYPE_RGB444A;            break;        case CM_CONFIG_O_FORMAT_RGB444B:            *type_p = CM_TYPE_RGB444B;            break;        case CM_CONFIG_O_FORMAT_RGB444C:            *type_p = CM_TYPE_RGB444C;            break;        case CM_CONFIG_O_FORMAT_RGB332:            *type_p = CM_TYPE_RGB332;            break;        case CM_CONFIG_O_FORMAT_YUV422A:            *type_p = CM_TYPE_YUV422A;            break;        case CM_CONFIG_O_FORMAT_YUV422B:            *type_p = CM_TYPE_YUV422B;            break;        case CM_CONFIG_O_FORMAT_YUV422C:            *type_p = CM_TYPE_YUV422C;            break;        case CM_CONFIG_O_FORMAT_YUV422D:            *type_p = CM_TYPE_YUV422D;            break;        case CM_CONFIG_O_FORMAT_YUV444:            *type_p = CM_TYPE_YUV444;            break;        case CM_CONFIG_O_FORMAT_GREY:            *type_p = CM_TYPE_GREY;            break;        case CM_CONFIG_O_FORMAT_RAWBPA:            *type_p = CM_TYPE_RAWBPA;            break;        case CM_CONFIG_O_FORMAT_RAW:            *type_p = CM_TYPE_RAW;            break;        default:            status = -1;            break;    }    return status;}int cmImageTypeGet (ImageType_t *type_p){    int status = 0;    unsigned int data = 0;    /* currently default it to reading the STILL */    cmRegisterRead (CM_REG_STILL_CONFIG, &data);    /* check if JPEG format */    if (data & CM_CONFIG_JPEG) {        /* jpeg format */        if ((data & CM_CONFIG_JPEG_DS) == CM_CONFIG_JPEG_DS_422) {            *type_p = CM_TYPE_JPEG422;        } else if ((data & CM_CONFIG_JPEG_DS) == CM_CONFIG_JPEG_DS_444) {            *type_p = CM_TYPE_JPEG444;        } else if ((data & CM_CONFIG_JPEG_DS) == CM_CONFIG_JPEG_DS_GREY) {            *type_p = CM_TYPE_JPEGGREY;        }    } else {        /* other format */        if (Type1670ToApi ((data & CM_CONFIG_O_FORMAT_MASK), type_p) < 0) {            /* error case */            *type_p = -1;            status = -1;        }    }    if (status == 0) {        g_defaultStill.type = *type_p;    }    return status;}

⌨️ 快捷键说明

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