Exemplo n.º 1
0
Msg const *MainState_top(MainState *me, Msg *msg)
{
	struct APPLICATION_STATE *pState;
	switch (msg->evt)
	{
	case START_EVT:
		/* initialize the whole stuff - is this the right place ? */
		STATE_START(me, &me->showgray);
		data.ipc.state.enAppMode = APP_CAPTURE_ON;
		data.pCurRawImg = data.u8FrameBuffers[0];
		data.nExposureTimeChanged = true;
		data.ipc.state.nExposureTime = 25;
		data.ipc.state.nStepCounter = 0;
		data.ipc.state.nThreshold = 30;
		return 0;
	case IPC_GET_APP_STATE_EVT:
		/* Fill in the response and schedule an acknowledge for the request. */
		pState = (struct APPLICATION_STATE*)data.ipc.req.pAddr;
		memcpy(pState, &data.ipc.state, sizeof(struct APPLICATION_STATE));

		data.ipc.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	case FRAMESEQ_EVT:
		/* Timestamp the capture of the image. */
		data.ipc.state.imageTimeStamp = OscSupCycGet();
		data.ipc.state.bNewImageReady = TRUE;
		/* Sleep here for a short while in order not to violate the vertical
		 * blank time of the camera sensor when triggering a new image
		 * right after receiving the old one. This can be removed if some
		 * heavy calculations are done here. */
		usleep(4000);
		return 0;
	case FRAMEPAR_EVT:
	{
		/* we have a new image increase counter: here and only here! */
		data.ipc.state.nStepCounter++;
		/* debayer the image first -> to half size*/
		OscVisDebayerGreyscaleHalfSize( data.pCurRawImg, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT, ROW_BGBG, data.u8TempImage[GRAYSCALE]);
		/* Process the image. */
		/* the parameter is not really required */
		ProcessFrame(data.u8TempImage[GRAYSCALE]);

		return 0;
	}
	case IPC_SET_IMAGE_TYPE_EVT:
	{
		if(data.ipc.state.nImageType == GRAYSCALE) {
			STATE_TRAN(me, &me->showgray);
		}
		else if(data.ipc.state.nImageType == THRESHOLD) {
			STATE_TRAN(me, &me->showthresh);
		}
		else if(data.ipc.state.nImageType == EROSION) {
			STATE_TRAN(me, &me->showerosion);
		}
    else if(data.ipc.state.nImageType == DILATION) {
      STATE_TRAN(me, &me->showdilation);
    }
    else if(data.ipc.state.nImageType == LABELIMG) {
      STATE_TRAN(me, &me->showlabel);
    }
		else {
			data.ipc.enReqState = REQ_STATE_NACK_PENDING;
		}
		data.ipc.enReqState = REQ_STATE_ACK_PENDING;
		return 0;
	}
	case IPC_GET_NEW_IMG_EVT:
		/* If the IPC event is not handled in the actual substate, a negative acknowledge is returned by default. */
		data.ipc.enReqState = REQ_STATE_NACK_PENDING;
	return 0;
	}
	return msg;
}
Exemplo n.º 2
0
Msg const *MainState_top(MainState *me, Msg *msg)
{
        struct APPLICATION_STATE *pState;
        switch (msg->evt) {
        case START_EVT:
                /* initialize the whole stuff - is this the right place ? */
                STATE_START(me, &me->showGray);
                data.ipc.state.enAppMode = APP_CAPTURE_ON;
                data.pCurRawImg = data.u8FrameBuffers[0];
                data.nExposureTimeChanged = true;
                data.nResetProcessing = false;
                data.AddBufSize = 0;
                data.ipc.state.nExposureTime = 25;
                data.ipc.state.nStepCounter = 0;
                data.ipc.state.nThreshold = 0;
                return 0;
        case IPC_GET_APP_STATE_EVT:
                /* Fill in the response and schedule an acknowledge for the request. */
                pState = (struct APPLICATION_STATE*)data.ipc.req.pAddr;
                memcpy(pState, &data.ipc.state, sizeof(struct APPLICATION_STATE));

                data.ipc.enReqState = REQ_STATE_ACK_PENDING;
                return 0;
        case FRAMESEQ_EVT:
                /* Timestamp the capture of the image. */
                data.ipc.state.imageTimeStamp = OscSupCycGet();
                data.ipc.state.bNewImageReady = TRUE;
                /* Sleep here for a short while in order not to violate the vertical
                 * blank time of the camera sensor when triggering a new image
                 * right after receiving the old one. This can be removed if some
                 * heavy calculations are done here. */
                //usleep(4000);
                return 0;
        case FRAMEPAR_EVT: {
                /* we have a new image increase counter: here and only here! */
                data.ipc.state.nStepCounter++;
                /* debayer the image first -> to half size*/
#if NUM_COLORS == 1
                OscVisDebayerGreyscaleHalfSize(data.pCurRawImg, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT, ROW_YUYV, data.u8TempImage[SENSORIMG]);
#else
                memcpy(data.u8TempImage[SENSORIMG], data.pCurRawImg, NUM_COLORS*OSC_CAM_MAX_IMAGE_HEIGHT*OSC_CAM_MAX_IMAGE_WIDTH);
#endif
                /* Process the image. */
                //set data buffer to zero before each step
                data.AddBufSize = 0;
                ProcessFrame();

                return 0;
        }
        case IPC_SET_IMAGE_TYPE_EVT: {
                if(data.ipc.state.nImageType == SENSORIMG) {
                        STATE_TRAN(me, &me->showGray);
                } else if(data.ipc.state.nImageType == THRESHOLD) {
                        STATE_TRAN(me, &me->showThreshold);
                } else if(data.ipc.state.nImageType == BACKGROUND) {
                        STATE_TRAN(me, &me->showBackground);
                } else {
                        data.ipc.enReqState = REQ_STATE_NACK_PENDING;
                }
                data.ipc.enReqState = REQ_STATE_ACK_PENDING;
                return 0;
        }
        case IPC_GET_NEW_IMG_EVT:
                /* If the IPC event is not handled in the actual substate, a negative acknowledge is returned by default. */
                data.ipc.enReqState = REQ_STATE_NACK_PENDING;
                return 0;
        }
        return msg;
}