📄 framemgr.c
字号:
CamConfig_sendFifoCmds();
}
else
{
/* we have more lines to acquire in this frame, so keep on truckin...*/
PUBLISH_FAST_EVENT(FEV_PROCESS_LINE_COMPLETE);
}
}
else if (currentState == ST_FrameMgr_TrackingFrame)
{
#ifdef DEBUG_TRACKED_LINE
/* send the received line over serial...this should only send
until a pixelCount == 176 */
pSendData = currentLineBuffer;
itoa(trackedLineCount,asciiBuffer,10);
UIMgr_txBuffer(asciiBuffer,3);
UIMgr_txBuffer(" ",1);
while(pixelCount < ACTUAL_NUM_PIXELS_IN_A_LINE)
{
memset(asciiBuffer,0x00,5);
itoa(*pSendData++,asciiBuffer,10); /* color is first byte */
UIMgr_txBuffer(asciiBuffer,3); /* 3 ascii bytes for data */
UIMgr_txBuffer(" ",1);
pixelCount += *pSendData; /* run-length is second byte */
memset(asciiBuffer,0x00,5);
itoa(*pSendData++,asciiBuffer,10);
UIMgr_txBuffer(asciiBuffer,3);
UIMgr_txBuffer(" ",1);
}
UIMgr_txBuffer("\n\r",2);
trackedLineCount++;
if (trackedLineCount == 144)
{
UIMgr_txBuffer(" FC \n\r",8);
trackedLineCount = 0;
PUBLISH_EVENT(EV_PROCESS_FRAME_COMPLETE);
}
else
{
PUBLISH_EVENT(EV_PROCESS_LINE_COMPLETE);
}
#else
/* determine if any of the RLE blocks overlap */
FrameMgr_findConnectedness();
trackedLineCount++;
if (trackedLineCount == ACTUAL_NUM_LINES_IN_A_FRAME)
{
/* an entire frame of tracking data has been acquired, so
publish an event letting the system know this fact */
PUBLISH_EVENT(EV_ACQUIRE_FRAME_COMPLETE);
/* disable the PCLK counting overflow interrupt */
TIMSK &= DISABLE_PCLK_TIMER1_OVERFLOW_BITMASK;
trackedLineCount = 0;
}
else
{
PUBLISH_FAST_EVENT(FEV_PROCESS_LINE_COMPLETE);
}
#endif
}
else
{
/* ...and here? */
}
}
/***********************************************************
Function Name: FrameMgr_processFrame
Function Description: This function is responsible for
parsing the completed frame and performing all actions
needed at this level.
Inputs: none
Outputs: none
***********************************************************/
void FrameMgr_processFrame(void)
{
unsigned char i,k,color;
#if DEBUG_FRAME_DATA
unsigned char asciiBuffer[5];
unsigned char j;
#endif
unsigned char *pTableData = (unsigned char *)pCurrentTrackedObjectTable;
unsigned char tmpUpperLeftX,tmpUpperLeftY,tmpLowerRightX,tmpLowerRightY;
#if DEBUG_FRAME_DATA
/* we want to send all of the currently tracked table out
the serial port for debugging */
for (i=0; i<numCurrTrackedObjects; i++)
{
UIMgr_txBuffer("----------\r\n",12);
for (j=0; j<SIZE_OF_TRACKED_OBJECT; j++)
{
memset(asciiBuffer,0x00,5);
itoa(*pTableData++,asciiBuffer,10);
UIMgr_txBuffer(asciiBuffer,3); /* 3 ascii bytes for data
+ 1 space */
UIMgr_txBuffer("\r\n",2);
}
/* skip the fill byte in each tracked object structure */
pTableData++;
}
/* finally, send a new line */
UIMgr_txBuffer("\r\n",2);
memset(asciiBuffer,0x00,5);
itoa(numCurrTrackedObjects,asciiBuffer,10);
UIMgr_txBuffer(asciiBuffer,3);
UIMgr_txBuffer(" PFC\r\n",5);
#else
/* we only send tracking packets if there are tracked objects */
if (numCurrTrackedObjects > 0)
{
UIMgr_writeTxFifo(0x0A); /* header byte for a tracking packet */
UIMgr_writeTxFifo(numCurrTrackedObjects); /* num of objects tracked */
for (i=0; i<numCurrTrackedObjects; i++)
{
/* convert the color from bit position to value...remember, each
bit in the "color" byte corresponds to a color */
k=0;
color = *pTableData++;
if (color == 128) k=0;
else if (color == 64) k=1;
else if (color == 32) k=2;
else if (color == 16) k=3;
else if (color == 8) k=4;
else if (color == 4) k=5;
else if (color == 2) k=6;
else if (color == 1) k=7;
UIMgr_writeTxFifo(k); /* send the color */
pTableData += 2; /* skip the last line data */
tmpUpperLeftX = *pTableData++; /* get the upper left X */
tmpUpperLeftY = *pTableData++; /* get the upper left Y */
tmpLowerRightX = *pTableData++; /* get the lower right X */
tmpLowerRightY = *pTableData++; /* get the lower right Y */
/* skip the fill byte */
pTableData++;
/* calculate the center point and send it */
UIMgr_writeTxFifo( (tmpLowerRightX+tmpUpperLeftX)>>1); /* send the X center point */
UIMgr_writeTxFifo( (tmpLowerRightY+tmpUpperLeftY)>>1); /* send the Y center point */
UIMgr_writeTxFifo(tmpUpperLeftX);
UIMgr_writeTxFifo(tmpUpperLeftY);
UIMgr_writeTxFifo(tmpLowerRightX);
UIMgr_writeTxFifo(tmpLowerRightY);
}
/* all done...send the end of tracking packets char */
UIMgr_writeTxFifo(0xFF);
}
#endif
/* schedule the next action to acquire a new frame */
PUBLISH_EVENT(EV_PROCESS_FRAME_COMPLETE);
}
/***********************************************************
Function Name: FrameMgr_findConnectedness
Function Description: This function is responsible for
finding the connectedness between two particular run-
length encoded lines of pixel data. It updates the
trackingTable as needed.
Inputs: none
Outputs: none
***********************************************************/
static void FrameMgr_findConnectedness(void)
{
trackedColor_t currColor;
unsigned char *pCurrLineColorInfo = currentLineBuffer;
unsigned char *pTrackedObjectData;
register unsigned char currPixelRunStart=0;
register unsigned char currPixelRunFinish=0;
register unsigned char lastLineXStart=0;
register unsigned char lastLineXFinish=0;
register unsigned char runLength=1;
unsigned char i;
bool_t colorConnected;
do
{
/* grab both the current color and the number of pixels
in the run...remember, pixels start at 1, not 0! */
colorConnected = FALSE;
currColor = *pCurrLineColorInfo++;
currPixelRunStart += runLength;
runLength = *pCurrLineColorInfo++;
currPixelRunFinish += runLength;
if (currColor != notTracked)
{
/* this run contains a color we care about, so
either it will begin a new tracked object, or it
is connected to a currently tracked object...
compare it with each object in the tracking
table */
for (i=0; i<numCurrTrackedObjects; i++)
{
/* The pTrackedObject pointer is used to move around within each
trackedObject_t structure to access and update its fields. This
is done instead of accessing each element in the structures through
the more traditional way (using the 'i' index to access a structure
in the trackingTable, followed by accessing the particular field
of interest) for efficiency reasons. */
pTrackedObjectData = (unsigned char *)&pCurrentTrackedObjectTable[i];
if (currColor == *pTrackedObjectData)
{
/* found a color match...check to see if there is
connectedness */
pTrackedObjectData++; /* move the pointer to the lastLineX/Y data of the structure*/
lastLineXStart = *pTrackedObjectData;
lastLineXFinish = *(pTrackedObjectData+1);
/* Check for the 5 following types of line connectedness:
---------------------
| |
---------------------
-------------------------
| |
------------------------- */
if ( ( (currPixelRunStart >= lastLineXStart) &&
(currPixelRunStart <= lastLineXFinish) ) ||
/* ---------------------
| |
---------------------
-------------------
| |
-------------------
OR
------------------------------
| |
------------------------------
---------
| |
--------- */
( (currPixelRunFinish >= lastLineXStart) &&
(currPixelRunFinish <= lastLineXFinish) ) ||
/* -------------------------------
| |
-------------------------------
-------------------------------
| |
-------------------------------
OR
-------------
| |
-------------
-------------------------------
| |
------------------------------- */
( (currPixelRunStart <= lastLineXStart) &&
(currPixelRunFinish >= lastLineXFinish) ) )
{
/* THERE IS CONNECTEDNESS...update the lastLineXStart and lastLineXFinish
data pointed to by pTrackedObjectData */
*pTrackedObjectData++ = currPixelRunStart;
*pTrackedObjectData++ = currPixelRunFinish;
/* check if the bounding box needs to be updated */
if (*pTrackedObjectData > currPixelRunStart)
{
/* need to update the bounding box for the upper left point to
enclose this new left-most point...we never have to update the
upper left Y point, since each scan line we process moves from
top to bottom */
*pTrackedObjectData = currPixelRunStart;
}
pTrackedObjectData += 2; /* move the pointer up to the lowerRight data */
if (*pTrackedObjectData < currPixelRunFinish)
{
/* need to update the bounding box for the lower right X point to
enclose this new right-most point */
*pTrackedObjectData = currPixelRunFinish;
}
/* the lower right 'y' point always gets updated when connectedness is found */
*(pTrackedObjectData+1) = trackedLineCount;
/* set a flag indicating that that color run is part of another
object and thus doesn't need to be added as a new entry into the
tracking table */
colorConnected = TRUE;
break;
}
}
}
if (colorConnected == FALSE)
{
/* a new entry needs to be made to the tracking table, since we have
a run-length with a color, and it isn't connected to anything...but we
can only do this if there is space left in the trackedObject table */
if (numCurrTrackedObjects < MAX_TRACKED_OBJECTS)
{
/* space is available...add the object */
pTrackedObjectData = (unsigned char *)&pCurrentTrackedObjectTable[numCurrTrackedObjects];
/* now that we have a pointer to the tracked object to be updated, update all
the fields */
*pTrackedObjectData++ = currColor; /* color */
*pTrackedObjectData++ = currPixelRunStart; /* lastLineXStart */
*pTrackedObjectData++ = currPixelRunFinish; /* lastLineXFinish */
*pTrackedObjectData++ = currPixelRunStart; /* x_upperLeft */
*pTrackedObjectData++ = trackedLineCount; /* y_upperLeft */
*pTrackedObjectData++ = currPixelRunFinish; /* x_lowerRight */
*pTrackedObjectData++ = trackedLineCount; /* y_lowerRight */
/* we'll calculate the center point for each tracked object when
the frame is done, instead of wasting the precious clock cycles doing
it now */
numCurrTrackedObjects++;
}
}
}
} while(currPixelRunFinish < ACTUAL_NUM_PIXELS_IN_A_LINE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -