⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uimgr.c

📁 he AVRcam source files were built using the WinAVR distribution (version 3.3.1 of GCC). I haven t t
💻 C
📖 第 1 页 / 共 2 页
字号:
		a request has come to dump a frame...this will
		be received by the FrameMgr, which will begin
		dumping the frame...a short delay is needed
		here to keep the Java demo app happy (sometimes
		it wouldn't be able to receive the serial data
		as quickly as AVRcam can provide it). */
		Utility_delay(100);
		PUBLISH_EVENT(EV_DUMP_FRAME);
	}
	else if (receivedCmd == setCameraRegsCmd)
	{
		/* we need to gather the tokens and
		build config cmds to be sent to the camera */
		for (i=1; i<tokenCount; i+=2)  /* starts at 1 since first token
											is the CR cmd */
		{
			CamConfig_setCamReg(tokenBuffer[i],tokenBuffer[i+1]);
		}
		CamConfig_sendFifoCmds();
	}
	else if (receivedCmd == enableTrackingCmd)
	{
		/* publish the event...again with a short delay */
		Utility_delay(100);
		PUBLISH_EVENT(EV_ENABLE_TRACKING);
	}
	else if (receivedCmd == disableTrackingCmd)
	{
		PUBLISH_EVENT(EV_DISABLE_TRACKING);
	}
	else if (receivedCmd == setColorMapCmd)
	{
		/* copy the received tokens into the color map */
		for (i=0; i<tokenCount; i++)
		{
			colorMap[i] = tokenBuffer[i+1];
            
            /* write each colorMap byte to EEPROM, but only those
            that changed...this will help reduce wear on the EEPROM */
            eepromData = eeprom_read_byte( (unsigned char*)(i+1));
            if (eepromData != colorMap[i])
            {
                /* need to actually perform the write because the
                data in eeprom is different than the current colorMap */
                eeprom_write_succeeded = FALSE;
                while(eeprom_write_succeeded == FALSE && num_writes < MAX_EEPROM_WRITE_ATTEMPTS)
                {
                    eeprom_write_byte((unsigned char*)(i+1),colorMap[i]);
                    num_writes++;
                    eepromData = eeprom_read_byte( (unsigned char*)(i+1));
                    if (eepromData == colorMap[i])
                    {
                        eeprom_write_succeeded = TRUE;
                    }
                }
                num_writes = 0;
            }
		}

#if	DEBUG_COLOR_MAP			
            			/* for debugging...send out the entire color map */
        UIMgr_txBuffer("\r\n",2);
		for (i=0; i<NUM_ELEMENTS_IN_COLOR_MAP; i++)
		{
			memset(asciiBuffer,0x00,5);
			itoa(colorMap[i],asciiBuffer,10);
			UIMgr_txBuffer(asciiBuffer,3);
			UIMgr_txBuffer(" ",1);
			if (i==15 || i == 31)
			{
				/* break up the output */
				UIMgr_txBuffer("\r\n",2);
			}
		}
#endif			
	}
}

/***********************************************************
	Function Name: UIMgr_convertTokenToValue
	Function Description: This function is responsible for
	converting a received token to a hex value It will
	access the asciiTokenBuffer directly, and store the
	result in the appropriate token buffer.
	Inputs:  none 
	Outputs: none
***********************************************************/	
static void UIMgr_convertTokenToValue(void)
{
	unsigned int newValue;
	
	newValue = atoi(asciiTokenBuffer);
	if (newValue > 255)
	{
		/* the value is too large */
		receivedCmd = invalidCmd;
		tokenBuffer[tokenCount] = 0xFF;  /* to indicate an error */
	}
	else
	{
		/* copy the value into the tokenBuffer */
		tokenBuffer[tokenCount] = newValue;
	}
	memset(asciiTokenBuffer,0x00,MAX_TOKEN_LENGTH);
	charIndex = 0;
	charCount = 0;
}
/***********************************************************
	Function Name: UIMgr_convertTokenToCmd
	Function Description: This function is responsible for
	parsing a received 2-character command.  It will
	access the asciiTokenBuffer directly.
	Inputs:  none 
	Outputs: none
***********************************************************/	
static void UIMgr_convertTokenToCmd(void)
{
	if ( (asciiTokenBuffer[0] == 'P') &&
		 (asciiTokenBuffer[1] == 'G') )
	{
		/* we got a "ping" command...but we still need to see
		if we are going to get the \r */
		receivedCmd = pingCmd;
	}
	else if ( (asciiTokenBuffer[0] == 'G') &&
			   (asciiTokenBuffer[1] == 'V') )
	{
		/* we got the "get version" command */
		receivedCmd = getVersionCmd;
	}
	else if ( (asciiTokenBuffer[0] == 'D') &&
			   (asciiTokenBuffer[1] == 'F') )
	{
		/* we should go into frame dump mode */
		receivedCmd = dumpFrameCmd;	
	}
	else if ( (asciiTokenBuffer[0] == 'C') &&
	           (asciiTokenBuffer[1] == 'R') )
	{
		/* the user wants to set registers in the OV6620 */
		receivedCmd = setCameraRegsCmd;
	}
	else if ( (asciiTokenBuffer[0] == 'E') &&
			   (asciiTokenBuffer[1] == 'T') )
	{
		/* the user wants to enable tracking */
		receivedCmd = enableTrackingCmd;
	}
	else if ( (asciiTokenBuffer[0] == 'S') &&
			   (asciiTokenBuffer[1] == 'M') )
	{
		/* the user wants to set the color map */
		receivedCmd = setColorMapCmd;
	}
	else if ( (asciiTokenBuffer[0] == 'D') &&
			   (asciiTokenBuffer[1] == 'T') )
	{
		receivedCmd = disableTrackingCmd;
	}
	else if ( (asciiTokenBuffer[0] == 'R') &&
			   (asciiTokenBuffer[1] == 'S') )
	{
		receivedCmd = resetCameraCmd;
	}
	else
	{
		/* don't recognize the cmd */
		receivedCmd = invalidCmd;
	}
	memset(asciiTokenBuffer,0x00,MAX_TOKEN_LENGTH);
	charIndex = 0;
	charCount = 0;
}
/***********************************************************
	Function Name: UIMgr_sendAck
	Function Description: This function is responsible for
	queuing up an ACK to be sent to the user.
	Inputs:  none 
	Outputs: none
***********************************************************/	
static void UIMgr_sendAck(void)
{
	UIMgr_writeTxFifo('A');
	UIMgr_writeTxFifo('C');
	UIMgr_writeTxFifo('K');
	UIMgr_writeTxFifo('\r');
}

/***********************************************************
	Function Name: UIMgr_sendNck
	Function Description: This function is responsible for
	queueing up an NCK to be sent to the user.
	Inputs:  none 
	Outputs: none
***********************************************************/	
static void UIMgr_sendNck(void)
{
		UIMgr_writeTxFifo('N');
		UIMgr_writeTxFifo('C');
		UIMgr_writeTxFifo('K');
		UIMgr_writeTxFifo('\r');
}


/***********************************************************
	Function Name: UIMgr_writeBufferToTxFifo
	Function Description: This function is responsible for
	placing "length" bytes into the tx FIFO.
	Inputs:  pData -  a pointer to the data to send
	         length - the number of bytes to send
	Outputs: none
***********************************************************/	
void UIMgr_writeBufferToTxFifo(unsigned char *pData, unsigned char length)
{
	unsigned char tmpHead;
	if (length == 0)
	{
		return;
	}
	
	DISABLE_INTS();
	while(length-- != 0)
	{
		UIMgr_txFifo[UIMgr_txFifoHead] = *pData++;
	
		/* now move the head up */
		tmpHead = (UIMgr_txFifoHead + 1) & (UI_MGR_TX_FIFO_MASK);
		UIMgr_txFifoHead = tmpHead;
	}
	ENABLE_INTS();
}

/***********************************************************
	Function Name: UIMgr_txBuffer
	Function Description: This function is responsible for
	sending 'length' bytes out using the UartInterface 
	module.
	Inputs:  pData -  a pointer to the data to send
	         length - the number of bytes to send
	Outputs: none
***********************************************************/	
void UIMgr_txBuffer(unsigned char *pData, unsigned char length)
{
	while(length-- != 0)
	{
		UartInt_txByte(*pData++); 
	}
}

/***********************************************************
	Function Name: UIMgr_flushTxBuffer
	Function Description: This function is responsible for
	sending all data currently in the serial tx buffer
	to the user.
	Inputs:  none
	Outputs: none
***********************************************************/	
void UIMgr_flushTxBuffer(void)
{
	while(IS_DATA_IN_TX_FIFO() == TRUE)
	{
		UartInt_txByte(UIMgr_readTxFifo() );
	}
}

/***********************************************************
	Function Name: UIMgr_readRxFifo
	Function Description: This function is responsible for
	reading a single byte of data from the rx fifo, and
	updating the appropriate pointers.
	Inputs:  none 
	Outputs: unsigned char-the data read
***********************************************************/	
static unsigned char UIMgr_readRxFifo(void)
{
	unsigned char dataByte, tmpTail;
	
	/* just return the current tail from the rx fifo */
	DISABLE_INTS();
	dataByte = UIMgr_rxFifo[UIMgr_rxFifoTail];	
	tmpTail = (UIMgr_rxFifoTail+1) & (UI_MGR_RX_FIFO_MASK);
	UIMgr_rxFifoTail = tmpTail;
	ENABLE_INTS();
	
	return(dataByte);
}

/***********************************************************
	Function Name: UIMgr_readTxFifo
	Function Description: This function is responsible for
	reading a single byte of data from the tx fifo, and
	updating the appropriate pointers.
	Inputs:  none 
	Outputs: unsigned char-the data read
***********************************************************/	
static unsigned char UIMgr_readTxFifo(void)
{
	unsigned char dataByte, tmpTail;
	
	/* just return the current tail from the tx fifo */
	DISABLE_INTS();
	dataByte = UIMgr_txFifo[UIMgr_txFifoTail];	
	tmpTail = (UIMgr_txFifoTail+1) & (UI_MGR_TX_FIFO_MASK);
	UIMgr_txFifoTail = tmpTail;
	ENABLE_INTS();
	
	return(dataByte);
}

/***********************************************************
	Function Name: UIMgr_writeTxFifo
	Function Description: This function is responsible for
	writing a single byte to the TxFifo and
	updating the appropriate pointers.
	Inputs:  data - the byte to write to the Fifo 
	Outputs: none
***********************************************************/	
void UIMgr_writeTxFifo(unsigned char data)
{
	unsigned char tmpHead;

	DISABLE_INTS();
	UIMgr_txFifo[UIMgr_txFifoHead] = data;

    /* now move the head up */
    tmpHead = (UIMgr_txFifoHead + 1) & (UI_MGR_TX_FIFO_MASK);
    UIMgr_txFifoHead = tmpHead;
	ENABLE_INTS();
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -