Exemple #1
0
int main(void)
{
#ifdef _MY_UNIT_TEST_
	SetupHardware();
	TestIrTxRxInit();
	TestUARTBasicAPI();
	//TestReadWriteExternalEEPROM();
	//TestReadWriteInternalEEPROM();

	for (;; ) {
		EchoCharacter();				// Read and write back to Virtual Serial Port
		USB_task_in_main_loop();
//		if(show_message_off==1)
//		{
//			UARTputstr("123\r\n");
//			show_message_off=0;
//		}
//		if(show_message_on==1)
//		{
//			UARTputstr("987\r\n");
//			show_message_on=0;
//		}

		TestIrRx();
		TestUARTRxTx();
		//TestADC_CH0();

		USB_task_in_main_loop();
	}
#else
	app_main();
#endif
	return 0;
}
/*= InsertCharacter =========================================================
Purpose: Inserts and echoes an printable character into the command line at the
         cursor location.

Inputs:  c  -- char to insert

Returns: none
============================================================================*/
static void InsertCharacter(INT8 c)
{
   UINT8 len;

   UINT8 i;
   UINT8 orig_cursor_index = GET_CURSOR();
   UINT8 count;

   /* throw away characters if exceeded cmd line length */
   if (GET_LEN_RX_CMD_STRING() >= sizeof(g_ConsoleContext.rxBuf)-1)
   {
      return;
   }

   len = GET_LEN_RX_CMD_STRING() + gCmdLinePromptLength;

   /* if inserting a character at end of cmd line */
   if (GET_CURSOR() == len)
   {
      g_ConsoleContext.rxBuf[GET_CURSOR() - gCmdLinePromptLength] = c;
      SET_CURSOR(GET_CURSOR() + 1);
      EchoCharacter(c);
   }
   /* inserting a character somewhere before the end of command line */
   else
   {
      /* Null out tmp cmd line */
      memset(gTmpCmdLine, 0x00, sizeof(gTmpCmdLine));

      /* copy up to the point of insertion */
      strncpy( (char *) gTmpCmdLine, (const char *) g_ConsoleContext.rxBuf, GET_CURSOR() - gCmdLinePromptLength);

      /* insert the new character */
      gTmpCmdLine[GET_CURSOR() - gCmdLinePromptLength] = c;

      /* copy the chars after the new character */
      strncpy( (char *) &gTmpCmdLine[GET_CURSOR() - gCmdLinePromptLength + 1],
               (const char *) &g_ConsoleContext.rxBuf[GET_CURSOR() - gCmdLinePromptLength],
               len - GET_CURSOR());

      /* put the first part of new string in the cmd line buffer */
      strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) gTmpCmdLine);

      /* erase entire line, put the cursor at index 0 */
      EraseEntireLine();

      /* output the prompt */
      putrsUART( (ROM FAR char *) gCmdLinePrompt);

      /* Output the updated command line */
      putsUART( (char *) &g_ConsoleContext.rxBuf[0]);

      /* move the cursor to the next insert location */
      count = (len + 1) - orig_cursor_index - 1;
      for (i = 0; i < count; ++i)
      {
         putrsUART( (ROM FAR char *) cursorLeftEscapeSequence);
      }

      SET_CURSOR(orig_cursor_index + 1);
   }
}