camera/QCamera2/util/QCameraFlash.cpp
/*===========================================================================
 * FUNCTION   : initFlash
 *
 * DESCRIPTION: Reserve and initialize the flash unit associated with a
 *              given camera id. This function is blocking until the
 *              operation completes or fails. Each flash unit can be "inited"
 *              by only one process at a time.
 *
 * PARAMETERS :
 *   @camera_id : Camera id of the flash.
 *
 * RETURN     :
 *   0        : success
 *   -EBUSY   : The flash unit or the resource needed to turn on the
 *              the flash is busy, typically because the flash is
 *              already in use.
 *   -EINVAL  : No flash present at camera_id.
 *==========================================================================*/
FUNCTION   : initFlash
DESCRIPTION: Reserve and initialize the flash unit associated with a
given camera id. This function is blocking until the
operation completes or fails. Each flash unit can be "inited"
by only one process at a time.

PARAMETERS :
@camera_id : Camera id of the flash.

RETURN     :
0        : success
-EBUSY   : The flash unit or the resource needed to turn on the
the flash is busy, typically because the flash is
already in use.
-EINVAL  : No flash present at camera_id.
FUNCTION : initFlash DESCRIPTION : Reserve and initialize the flash unit associated with a given camera id . This function is blocking until the operation completes or fails . Each flash unit can be " inited " by only one process at a time . PARAMETERS : @camera_id : Camera id of the flash . RETURN : 0 : success - EBUSY : The flash unit or the resource needed to turn on the the flash is busy typically because the flash is already in use . - EINVAL : No flash present at camera_id .
int32_t QCameraFlash::initFlash(const int camera_id)
{
    int32_t retVal = 0;
    if (camera_id < 0 || camera_id >= MM_CAMERA_MAX_NUM_SENSORS) {
        LOGE("Invalid camera id: %d", camera_id);
        return -EINVAL;
    }
    if (camera_id != 0) {
        LOGE("No flash available for camera id: %d",
                camera_id);
        retVal = -EINVAL;
    } else if (m_cameraOpen[camera_id]) {
        LOGE("Camera in use for camera id: %d",
                camera_id);
        retVal = -EBUSY;
    }
    if (retVal < 0) {
        return retVal;
    }
    if (m_flashFds[camera_id].first >= 0) {
        LOGD("First flash led is already inited for camera id: %d",
                camera_id);
    } else {
        m_flashFds[camera_id].first = open(FLASH_PATH_FIRST, O_RDWR);
        if (m_flashFds[camera_id].first < 0) {
            LOGE("Unable to open node '%s'",
                    FLASH_PATH_FIRST);
            retVal = -EBUSY;
        }
    }
    if (m_flashFds[camera_id].second >= 0) {
        LOGD("Second flash led is already inited for camera id: %d",
                camera_id);
    } else {
        m_flashFds[camera_id].second = open(FLASH_PATH_SECOND, O_RDWR);
        if (m_flashFds[camera_id].second < 0) {
            LOGE("Unable to open node '%s'",
                    FLASH_PATH_SECOND);
            retVal = -EBUSY;
        }
    }
    usleep(5000);
    LOGD("X, retVal = %d", retVal);
    return retVal;
}
int32_t QCameraFlash :: initFlash ( const int camera_id ) { int32_t retVal = 0 ; if ( camera_id < 0 || camera_id >= MM_CAMERA_MAX_NUM_SENSORS ) { LOGE ( " " , camera_id ) ; return - EINVAL ; } if ( camera_id != 0 ) { LOGE ( " " , camera_id ) ; retVal = - EINVAL ; } else if ( m_cameraOpen [ camera_id ] ) { LOGE ( " " , camera_id ) ; retVal = - EBUSY ; } if ( retVal < 0 ) { return retVal ; } if ( m_flashFds [ camera_id ] . first >= 0 ) { LOGD ( " " , camera_id ) ; } else { m_flashFds [ camera_id ] . first = open ( FLASH_PATH_FIRST , O_RDWR ) ; if ( m_flashFds [ camera_id ] . first < 0 ) { LOGE ( " " , FLASH_PATH_FIRST ) ; retVal = - EBUSY ; } } if ( m_flashFds [ camera_id ] . second >= 0 ) { LOGD ( " " , camera_id ) ; } else { m_flashFds [ camera_id ] . second = open ( FLASH_PATH_SECOND , O_RDWR ) ; if ( m_flashFds [ camera_id ] . second < 0 ) { LOGE ( " " , FLASH_PATH_SECOND ) ; retVal = - EBUSY ; } } usleep ( 5000 ) ; LOGD ( " " , retVal ) ; return retVal ; }
FUNCTION   : initFlash
 DESCRIPTION: Reserve and initialize the flash unit associated with a
              given camera id.
FUNCTION : initFlash DESCRIPTION : Reserve and initialize the flash unit associated with a given camera id .
/* wait for PMIC to init */