コード例 #1
0
ファイル: Camera.cpp プロジェクト: hilaris/hilaris
bool Camera::presetRegisters()
{
	//set registers to default values
	this->lastError = OscCamPresetRegs();
	
	/*
	 * enables continuous capturing, no sleep between readpicture and setupcapture needed
	 * about 10ms shorter capturing time in average
	 */
	this->lastError = OscCamSetRegisterValue(0x07, 0x388);
	return  this->lastError == SUCCESS;
}
コード例 #2
0
ファイル: leanXmain.c プロジェクト: scs/leanXalarm
/*********************************************************************//*!
 * @brief Initialize framework and system parameters
 *
 * @param s Pointer to the system state 
 *//*********************************************************************/
void initSystem(struct SYSTEM *s)
{
	OscCreate(&s->hFramework);
	
	/******* Load the framework module dependencies. **********/
	OscLoadDependencies(s->hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));

	OscLogSetConsoleLogLevel(WARN);
	OscLogSetFileLogLevel(WARN);
	
	#if defined(OSC_HOST)
		/* Setup file name reader (for host compiled version); read constant image */
		OscFrdCreate(s->hFramework);
		OscFrdCreateConstantReader(&s->hFileNameReader, "EAN13Example.bmp");
		OscCamSetFileNameReader(s->hFileNameReader);
	#endif
	
	/* Configure camera */
	OscCamPresetRegs();
	/* Set AGC and AEC */
	OscCamSetRegisterValue(REG_AEC_AGC_ENABLE, 0x3);
        /* Turn on continuous capture for this application. */
        OscCamSetRegisterValue(CAM_REG_CHIP_CONTROL, 0x388);
        /* Set the undocumented reserved almighty Micron register to the
           "optimal" value. */
        OscCamSetRegisterValue(CAM_REG_RESERVED_0x20, 0x3d5);

	OscCamSetAreaOfInterest(0, 0, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT);
	OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_180DEG_ROTATE);

	OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT, s->frameBuffer1, TRUE); 
	OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT, s->frameBuffer2, TRUE); 

	s->doubleBufferIDs[0] = 0;
	s->doubleBufferIDs[1] = 1;
	OscCamCreateMultiBuffer(2, s->doubleBufferIDs); 

	OscCamSetupCapture(OSC_CAM_MULTI_BUFFER); 

} /* initSystem */
コード例 #3
0
ファイル: main.c プロジェクト: Ikem/udgasser
/*********************************************************************//*!
 * @brief Initialize everything so the application is fully operable
 * after a call to this function.
 *
 * @return SUCCESS or an appropriate error code.
 *//*********************************************************************/
static OSC_ERR init(const int argc, const char * argv[])
{
	OSC_ERR err = SUCCESS;
	uint8 multiBufferIds[2] = {0, 1};

	memset(&data, 0, sizeof(struct TEMPLATE));

	/******* Create the framework **********/
	err = OscCreate(&data.hFramework);
	if (err < 0)
	{
		fprintf(stderr, "%s: Unable to create framework.\n", __func__);
		return err;
	}

	/******* Load the framework module dependencies. **********/
	err = OscLoadDependencies(data.hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));

	if (err != SUCCESS)
	{
		fprintf(stderr, "%s: ERROR: Unable to load dependencies! (%d)\n", __func__, err);
		goto dep_err;
	}

	/********* Seed the random generator *************/
	srand(OscSupCycGet());

#if defined(OSC_HOST) || defined(OSC_SIM)
	err = OscFrdCreateConstantReader(&data.hFileNameReader, TEST_IMAGE_FN);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to create constant file name reader for %s! (%d)\n", __func__, TEST_IMAGE_FN, err);
		goto frd_err;
	}
	err = OscCamSetFileNameReader(data.hFileNameReader);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set file name reader for camera! (%d)\n", __func__, err);
		goto frd_err;
	}
#endif /* OSC_HOST or OSC_SIM */

	/* Set the camera registers to sane default values. */
	err = OscCamPresetRegs();
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to preset camera registers! (%d)\n", __func__, err);
		goto fb_err;
	}

	/* Set up two frame buffers with enough space for the maximum
	 * camera resolution in cached memory. */
	err = OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, data.u8FrameBuffers[0], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up first frame buffer!\n", __func__);
		goto fb_err;
	}
	err = OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, data.u8FrameBuffers[1], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up second frame buffer!\n", __func__);
		goto fb_err;
	}

	/* Create a double-buffer from the frame buffers initilalized above.*/
	err = OscCamCreateMultiBuffer(2, multiBufferIds);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up multi buffer!\n", __func__);
		goto mb_err;
	}

	/* Register an IPC channel to the CGI for the user interface. */
	err = OscIpcRegisterChannel(&data.ipc.ipcChan, USER_INTERFACE_SOCKET_PATH, F_IPC_SERVER | F_IPC_NONBLOCKING);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to initialize IPC channel to web interface! (%d)\n", __func__, err);
		goto ipc_err;
	}

	err |= OscCamPerspectiveStr2Enum("DEFAULT", &data.perspective);
	if ( err != SUCCESS)
	{
		OscLog(ERROR, "%s: Invalid camera perspective.\n", __func__);
		goto per_err;
	}
	OscCamSetupPerspective( data.perspective);

	return SUCCESS;

per_err:
ipc_err:
mb_err:
fb_err:
#if defined(OSC_HOST) || defined(OSC_SIM)
frd_err:
#endif
	OscUnloadDependencies(data.hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));
dep_err:
	OscDestroy(&data.hFramework);

	return err;
}
コード例 #4
0
ファイル: main.c プロジェクト: scs/rich-view
/*********************************************************************//*!
 * @brief Initialize everything so the application is fully operable
 * after a call to this function.
 * 
 * @return SUCCESS or an appropriate error code.
 *//*********************************************************************/
static OSC_ERR init(const int argc, const char * argv[])
{
    OSC_ERR err = SUCCESS;
    uint8 multiBufferIds[2] = {0, 1};
    char strVersion[15]; 
    struct CFG_KEY configKey;
    struct CFG_VAL_STR strCfg;
#ifdef HAS_CPLD
    uint16 exposureDelay;
#endif /* HAS_CPLD */	
    memset(&data, 0, sizeof(struct DATA));
	
    /* Print software version */
    GetVersionString( strVersion); 
	fprintf(stderr, "Software rich-view version: %s\n", strVersion); 	
	
    /******* Create the framework **********/
    err = OscCreate(&data.hFramework);
    if (err < 0)
    {
    	fprintf(stderr, "%s: Unable to create framework.\n", __func__);
    	return err;
    }
	
    /******* Load the framework module dependencies. **********/
    err = OscLoadDependencies(data.hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));
    
    if (err != SUCCESS)
    {
    	fprintf(stderr, "%s: ERROR: Unable to load dependencies! (%d)\n", __func__, err);
    	goto dep_err;
    }

    /* Set logging levels */
    OscLogSetConsoleLogLevel(INFO);
    OscLogSetFileLogLevel(DEBUG);

    /* Print framework version */
    OscGetVersionString( strVersion);    
    OscLog(INFO, "Oscar framework version: %s\n", strVersion);

	/* Disable watchdog (probably activated from previous application) */
	OscSupWdtInit();
	OscSupWdtClose();
	
	/* Set LED to green, util the idle state is entered */
	OscGpioSetTestLed( TRUE);       
	OscGpioSetTestLedColor(FALSE, TRUE); /* R, G*/ 	

    /* Register configuration file */
    err = OscCfgRegisterFile(&data.hConfig, CONFIG_FILE_NAME, CONFIG_FILE_SIZE);
    if (err != SUCCESS)
    {
    	OscLog(ERROR, "Cannot access config file.\n");
    	goto cfg_err;
    } 
    

    /* Get perspective setting from config file- */
    configKey.strSection = NULL;
    configKey.strTag = "PER";
   
    strcpy( strCfg.str, "");    
    err = OscCfgGetStr( data.hConfig, 
            &configKey, 
            &strCfg);    

    err |= OscCamPerspectiveStr2Enum( strCfg.str, &data.perspective);  
    if( err != SUCCESS)
    {
        OscLog(WARN, 
                 "%s: No (valid) camera-scene perspective configured (%s). "
                 "Use default (%s).\n",
                 __func__, strCfg.str, OSC_CAM_PERSPECTIVE_DEFAULT);
		data.perspective = OSC_CAM_PERSPECTIVE_DEFAULT;
    }             


    /* Get exposure time setting from configuration. */            
    configKey.strSection = NULL;
    configKey.strTag = "EXP";
    err = OscCfgGetUInt32( data.hConfig,
            &configKey, 
            &data.exposureTime);    
    
    if( err != SUCCESS)
    {
        OscLog(WARN, 
                "%s: No (valid) Exposure Time defined in configuration (%d). "
                "Use default (%d).\n",
                __func__, data.exposureTime, DEFAULT_EXPOSURE_TIME);
        data.exposureTime = DEFAULT_EXPOSURE_TIME;
    }  

#ifdef HAS_CPLD		
    /* Get exposure delay setting from configuration. */            
    configKey.strSection = NULL;
    configKey.strTag = "DEL";
    err = OscCfgGetUInt16Range( data.hConfig,
            &configKey, 
            &exposureDelay, 
            0, 
            FINECLK2CLK_RATIO-1);    
    data.exposureDelay = exposureDelay & 0x00ff;
    if( err != SUCCESS)
    {
        OscLog(WARN, 
                "%s: No (valid) Exposure Delay defined in configuration (%d). "
                "Use default (%d).\n",
                __func__, data.exposureDelay, DEFAULT_EXPOSURE_DELAY);
        data.exposureDelay = DEFAULT_EXPOSURE_DELAY;
    }  
#endif /* HAS_CPLD */	
	
	
#ifdef HAS_CPLD	
	/* Get firmware version */
	err = OscCpldRget(OSC_LGX_FWREV, &data.firmwareRevision);	
	if(err != SUCCESS)
	{
	        OscLog(ERROR, "Cannot read firmware version. (%d)\n", err);
		goto cpld_err;
	}	

	/* Apply exposure delay to CPLD and disable. */
	err = OscCpldRset(OSC_LGX_CLKDELAY, 
		(const uint8)(data.exposureDelay & !OSC_LGX_CLKDELAY_ENABLE));		
	if(err != SUCCESS)
	{
		OscLog(ERROR, "Cannot disable clock-delay in CPLD.\n");
		goto cpld_err;
	}
	/* Set CPLD to synchronous mode. */
	err = OscCpldFset(OSC_LGX_VARCTRL, OSC_LGX_VARCTRL_SYNCOUT, OSC_LGX_VARCTRL_SYNCOUT);	
	if(err != SUCCESS)
	{
		OscLog(ERROR, "Cannot set CPLD to synchronous mode.\n");
		goto cpld_err;
	}
#endif /* HAS_CPLD */	
	
	

	/* Set the camera registers to sane default values. */
	err = OscCamPresetRegs();
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to preset camera registers! (%d)\n", __func__, err);
		goto cam_err;
	}
	
	/* Set up two frame buffers with enough space for the maximum
	 * camera resolution in cached memory. */
	err = OscCamSetFrameBuffer(0, IMAGE_AERA, data.u8FrameBuffers[0], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up first frame buffer!\n", __func__);
		goto cam_err;
	}
	err = OscCamSetFrameBuffer(1, IMAGE_AERA, data.u8FrameBuffers[1], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up second frame buffer!\n", __func__);
		goto cam_err;
	}
	
	/* Create a double-buffer from the frame buffers initilalized above.*/
	err = OscCamCreateMultiBuffer(2, multiBufferIds);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up multi buffer!\n", __func__);
		goto mb_err;
	}
	
	OscCamSetupPerspective( data.perspective);

	/* Make the register file known to the communication protocol. */
	data.comm.pRegFile = regfile;
	data.comm.nRegs = (sizeof(regfile)/sizeof(struct CBP_PARAM));

	/* Init communication sockets. */
	err = Comm_Init(&data.comm);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "Communication initialization failed.\n");
		goto comm_err;		
	}	
	
	return SUCCESS;
	
comm_err:    
cfg_err:
#ifdef HAS_CPLD	
cpld_err:
#endif /* HAS_CPLD */
mb_err:
cam_err:
    OscUnloadDependencies(data.hFramework,
            deps,
            sizeof(deps)/sizeof(struct OSC_DEPENDENCY));
dep_err:
	OscDestroy(&data.hFramework);
	
	return err;
}