bool Camera::setShutterWidth(uint32 width) { this->lastError = OscCamSetShutterWidth(width); if(this->lastError == SUCCESS) { this->setAutoExposure(false); return true; } else { return false; } }
OSC_ERR SetConfigRegister(void *pMainState, struct CBP_PARAM *pReg) { OSC_ERR err; struct CFG_KEY configKey; struct CFG_VAL_STR strCfg; struct MainState *pHsm = (struct MainState *)pMainState; #ifdef HAS_CPLD uint8 cpldReg; int exposureDelay; #endif /* HAS_CPLD */ #ifdef UNSUPPORTED int i; #endif /* UNSUPPORTED */ switch(pReg->id) { case REG_ID_AQUISITION_MODE: if(pReg->val == 0) { ThrowEvent(pHsm, CMD_GO_IDLE_EVT); break; } if(pReg->val == 1) { ThrowEvent(pHsm, CMD_GO_ACQ_EVT); break; } return -EUNSUPPORTED; case REG_ID_TRIGGER_MODE: if(pReg->val == 0) { ThrowEvent(pHsm, CMD_USE_INTERN_TRIGGER_EVT); break; } if(pReg->val == 1) { ThrowEvent(pHsm, CMD_USE_EXTERN_TRIGGER_EVT); break; } return -EUNSUPPORTED; case REG_ID_EXP_TIME: /* Apply exposure time and store to configuration. */ data.exposureTime = pReg->val; /* Apply value */ err = OscCamSetShutterWidth( data.exposureTime); if( err != SUCCESS) { OscLog(ERROR, "%s: Failed to modify exposure time! (%d)\n", __func__, err); break; } OscLog(INFO, "%s: Exposure time stored and applied to %d us\n", __func__, data.exposureTime); /* Store to configuration. */ configKey.strSection = NULL; configKey.strTag = "EXP"; sprintf(strCfg.str, "%ld", data.exposureTime); err = OscCfgSetStr( data.hConfig, &configKey, strCfg.str); err |= OscCfgFlushContent(data.hConfig); return err; #ifdef UNSUPPORTED /* This code is not yet ported to the new communication scheme and thus unsupported. */ case REG_ID_MAC_ADDR: /* Store Mac/Ip persistent. Applied on next reboot. */ for (i=0; i<6; i++) { macAddr[i] = (uint8)data.cmdpkt.data[i]; } /* Compose strings */ sprintf(strMac, "%02x:%02x:%02x:%02x:%02x:%02x", macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]); OscLog(INFO, "Set MAC addr environment variable: %s (one time programmable)\n",strMac); /* Write to persistent u-boot environment ethaddr. */ pF = fopen("/tmp/mac", "w"); fprintf(pF, "%s", strMac); fflush(pF); fclose(pF); system("fw_setenv ethaddr `more /tmp/mac`"); case CmdPerspective: /* Apply perspective setting and store to configuration */ data.perspective = (enum EnOscCamPerspective)data.cmdpkt.data[0]; /* Apply to sensor */ err = OscCamSetupPerspective( data.perspective); /* Store to configuration */ configKey.strSection = NULL; configKey.strTag = "PER"; err = OscCamPerspectiveEnum2Str( data.perspective, strCfg.str); err = OscCfgSetStr( data.hConfig, &configKey, strCfg.str); err |= OscCfgFlushContent(data.hConfig); break; #endif /* UNSUPPORTED */ return -EUNSUPPORTED; #ifdef HAS_CPLD case REG_ID_EXP_DELAY: /* Apply exposure delay to CPLD. Keep enable bit as currently set. */ exposureDelay = pReg->val; if (exposureDelay > 99) { OscLog(ERROR, "Invalid exposure delay value (%d). Valid range: 0..99\n", exposureDelay); return -EINVALID_PARAMETER; } /* Store to data struct */ data.exposureDelay = exposureDelay; /* Apply to CPLD. Preserve current enable bit state. */ err = OscCpldRget(OSC_LGX_CLKDELAY, &cpldReg); cpldReg = OSC_LGX_CLKDELAY_ENABLE; if( cpldReg & OSC_LGX_CLKDELAY_ENABLE) { cpldReg = exposureDelay | OSC_LGX_CLKDELAY_ENABLE; } else { cpldReg = exposureDelay; } err |= OscCpldRset(OSC_LGX_CLKDELAY, cpldReg); if( err != SUCCESS) { OscLog(ERROR, "%s: Failed to apply exposure delay to CPLD!\n", __func__); return err; } OscLog(INFO, "%s: Exposure applied to CPLD: %d fine clocks.\n", __func__, data.exposureDelay); return SUCCESS; case REG_ID_STORE_CUR_EXP_DELAY: /* Read current fine clock position from CPLD. Store this offset in * configuration and apply to CPLD exposure delay. */ err = OscCpldRget(OSC_LGX_FASTCLKCOUNT, &cpldReg); exposureDelay = cpldReg; /* Value 0 is reserved with the current CPLD version */ if( 0 == exposureDelay) { exposureDelay++; } OscLog(INFO, "%s: Read current fine clock position from CPLD: %d\n", __func__, exposureDelay); /* Store exposure delay to configuration. */ configKey.strSection = NULL; configKey.strTag = "DEL"; sprintf(strCfg.str, "%d", exposureDelay); err = OscCfgSetStr( data.hConfig, &configKey, strCfg.str); err |= OscCfgFlushContent(data.hConfig); if( err != SUCCESS) { OscLog(ERROR, "%s: Failed to store exposure delay to configuration!\n", __func__); break; } OscLog(INFO, "%s: Exposure delay stored to configuration: %d fine clocks.\n", __func__, exposureDelay); /* Apply delay to CPLD. Preserve the current enable bit state */ err = OscCpldRget(OSC_LGX_CLKDELAY, &cpldReg); cpldReg = OSC_LGX_CLKDELAY_ENABLE; if( cpldReg & OSC_LGX_CLKDELAY_ENABLE) { cpldReg = exposureDelay | OSC_LGX_CLKDELAY_ENABLE; } else { cpldReg = exposureDelay; } err |= OscCpldRset(OSC_LGX_CLKDELAY, cpldReg); if( err != SUCCESS) { OscLog(ERROR, "%s: Failed to apply exposure delay to CPLD!\n", __func__); break; } OscLog(INFO, "%s: Exposure applied to CPLD: %d fine clocks.\n", __func__, exposureDelay); break; #endif /* HAS_CPLD */ default: OscLog(WARN, "%s: Invalid register (%#x)!\n", __func__, pReg->id); return -EUNSUPPORTED; } /* Evaluate the success or failure of the commands that invoked the state machine. */ if(data.comm.enReqState == REQ_STATE_ACK_PENDING) { /* Success. */ return SUCCESS; } else if(data.comm.enReqState == REQ_STATE_NACK_PENDING) { return -EDEVICE; } else { OscLog(ERROR, "%s: Change of register %d was not handled by the state machine!\n", __func__, pReg->id); return -EDEVICE; } }
/*********************************************************************//*! * @brief Program entry. * * @param argc Command line argument count. * @param argv Command line argument string. * @return 0 on success *//*********************************************************************/ int main(const int argc, const char * argv[]) { /* Handle to framework instance. */ void *hFramework; #if defined(OSC_HOST) || defined(OSC_SIM) /* Handle to file name reader, if compiled for host platform. */ void *hFileNameReader; #endif /* Camera parameters */ uint32 shutterWidth; uint16 x, y, width, height; uint16 blackOffset; uint8 bufferIDs[2]; /* Frame buffers. */ uint8 frameBuffer0[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT]; uint8 frameBuffer1[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT]; /* Pointer to captured picture */ void *pic; struct OSC_PICTURE p; OSC_ERR err = SUCCESS; /* Create framework */ OscCreate(&hFramework); /* Load camera module */ OscCamCreate(hFramework); /* Load GPIO module */ OscGpioCreate(hFramework); p.width = OSC_CAM_MAX_IMAGE_WIDTH; p.height = OSC_CAM_MAX_IMAGE_HEIGHT; p.type = OSC_PICTURE_GREYSCALE; /* Get camera settings */ OscCamGetShutterWidth(&shutterWidth); OscCamGetAreaOfInterest(&x, &y, &width, &height); OscCamGetBlackLevelOffset(&blackOffset); printf("ShutterWidth=%lu\n",shutterWidth); printf("AreaOfInterest: x=%u y=%u width=%u height=%u\n", x, y, width, height); printf("BlackLevelOffset=%u\n",blackOffset); /* Process settings */ /* ---------------- */ /* Set new camera settings */ shutterWidth = 50000; /* set shutter to 50ms, 0 => automatic */ OscCamSetShutterWidth(shutterWidth); OscCamSetAreaOfInterest(0,0,OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT); OscCamSetBlackLevelOffset(blackOffset); OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR); #if defined(OSC_HOST) || defined(OSC_SIM) /* Setup file name reader if compiled for host platform */ OscFrdCreateConstantReader(&hFileNameReader, "imgCapture.bmp"); OscCamSetFileNameReader(hFileNameReader); #endif /* Setup framebuffers - double buffering */ OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer0, TRUE); OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer1, TRUE); bufferIDs[0] = 0; bufferIDs[1] = 1; OscCamCreateMultiBuffer(2, bufferIDs); /* Setup capture to first frame buffer */ err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER); if(err != SUCCESS){ printf("%s: Unable to setup initial capture (%d)!\n", __func__, err); return err; } /* Trigger image capturing */ err = OscGpioTriggerImage(); if(err != SUCCESS){ printf("%s: Unable to trigger capture (%d)!\n", __func__, err); return err; } /* Do something ... */ /* ---------------- */ /* Read Picture */ err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0); if(err != SUCCESS){ printf("%s: Unable to read picture (%d)!\n", __func__, err); return err; } /* Process picture */ /* --------------- */ /* Capture picture to second frame buffer */ err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER); if(err != SUCCESS){ printf("%s: Unable to setup initial capture (%d)!\n", __func__, err); return err; } /* Do something ... */ /* ---------------- */ err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0); if(err != SUCCESS){ printf("%s: Unable to read picture (%d)!\n", __func__, err); return err; } /* Process picture */ /* --------------- */ /* Unload camera module */ OscCamDestroy(hFramework); /* Unload GPIO module */ OscGpioDestroy(hFramework); /* Destroy framework */ OscDestroy(hFramework); return 0; }