Example #1
0
void pattern_transition_function(int previous_state, int event, int new_state)
{
    switch (event) {
        case PATTERN_DOT:
            GLCD_Clear(White);
            GLCD_DisplayString(0, 0, 1, "DOT");

            break;
        case PATTERN_DASH:
            GLCD_Clear(White);
            GLCD_DisplayString(0, 0, 1, "DASH");

            break;
        default:
            break;
    }

    switch (new_state) {
        case PATTERN_S7_DOT:
            GLCD_Clear(White);
            GLCD_DisplayString(0, 0, 1, "CORRECT");

            break;
        default:
            break;
    }
}
void main() 
{
    int num = 1234;
    GLCD_Init();

    while (1) 
    {
        GLCD_Clear();
        GLCD_DisplayLogo(LogoBitMap);
        DELAY_ms(DELAY_TIME);

        GLCD_Clear();
        GLCD_Printf("Dec:%d \nHex:%x \nBin:%b \nFloat:%f", num, num, num, 4567.89);
        DELAY_ms(DELAY_TIME);

        GLCD_Clear();
        GLCD_HorizontalGraph(0, 45);
        GLCD_HorizontalGraph(1, 50);
        GLCD_HorizontalGraph(2, 82);
        GLCD_HorizontalGraph(3, 74);
        DELAY_ms(DELAY_TIME);

        GLCD_Clear();
        GLCD_VerticalGraph(0, 45);
        GLCD_VerticalGraph(1, 50);
        GLCD_VerticalGraph(2, 82);
        GLCD_VerticalGraph(3, 74);
        DELAY_ms(DELAY_TIME);
    }
}
Example #3
0
int main(void)
{
	SystemInit();
	GLCD_Init();
	clock_init();

#ifndef BUSY_WAIT
	timer0_init();
#endif /* ifndef BUSY_WAIT */
	
	while(1)
	{
		GLCD_Clear(White);
		GLCD_DisplayString(0, 0, 1, (unsigned char*) clock.text);
		
		// Delay by 1000 milliseconds
#ifdef BUSY_WAIT
		delay_busy_wait(1000);
		clock_increment();
		clock_print();
#else
		// incrementing clock done within interrupt handlers
		clock_print();
#endif /* ifdef BUSY_WAIT */		
	}
}
Example #4
0
void init_system()
{
	// Initialize system and GLCD
	SystemInit();
	GLCD_Init();
	GLCD_Clear(White);
}
Example #5
0
/* With ARM and GHS toolsets, the entry point is main() - this will
   allow the linker to generate wrapper code to setup stacks, allocate
   heap area, and initialize and copy code and data segments. For GNU
   toolsets, the entry point is through __start() in the crt0_gnu.asm
   file, and that startup code will setup stacks and data */
int main(void)
{
	COORDINATE_Type point1,point2,point3;
	COLORCFG_Type tricfg;
	System_Init();                        // Initialize System

	GLCD_Clear(White);
	// Triangle coordinates
	point1.x = 20;
	point1.y = 20;
	point2.x = 80;
	point2.y = 80;
	point3.x = 30;
	point3.y = 120;
	tricfg.fill = YES;
	tricfg.bndry= YES;
	tricfg.bcolor = Blue;
	tricfg.fill_color=Green;
	// Display Triangle
	GLCD_Triangle(&point1,&point2,&point3,&tricfg);

	// Display Coordinates
    gprintf(point1.x+2,point1.y,1,Black,"(%d03,%d03)",point1.x,point1.y);
    gprintf(point2.x+2,point2.y,1,Black,"(%d03,%d03)",point2.x,point2.y);
    gprintf(point3.x+2,point3.y,1,Black,"(%d03,%d03)",point3.x,point3.y);

    while(1);
    return 1;
}
Example #6
0
/*********************************************************************//**
 * @brief		c_entry: Main LCD program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
//	/* Initialize debug via UART0
//	 * – 115200bps
//	 * – 8 data bit
//	 * – No parity
//	 * – 1 stop bit
//	 * – No flow control
//	 */
//	debug_frmwrk_init();
//
//	// print welcome screen
//	print_menu();

	/* LCD block section -------------------------------------------- */
	GLCD_Init();
	GLCD_Clear(White);

	/* Update LCD Module display text. */
	GLCD_DisplayString(0,0, lcd_text[0] );
	GLCD_DisplayString(1,2, lcd_text[1] );

    /* Loop forever */
    while(1);
    return 1;
}
Example #7
0
int main( void ){
    // Initialization
    int i,j;
    bst_t* tree = NULL;
    
    SystemInit();
    init_scroll();
    GLCD_Clear( Blue );
    
    tree = malloc(sizeof(bst_t));
    bst_init(tree);
    
    // Insertion
    for (i=0; i<100; i++) bst_insert(tree, value_array[i]);
    printf("0 | %d,  %d\n",bst_min(tree), bst_max(tree));
            
    // Deletion            
    for (i=0; i<5; i++){
            for (j=0; j<20; j++) bst_erase(tree, erase_array[i][j]);
            printf("%d | %d, %d\n", i+1, bst_min(tree), bst_max(tree));
    }

    // Destruction
    bst_destroy(tree);
    while ( 1 ) {
        /* An emebedded system does not terminate... */
    }
}
Example #8
0
//reset the game
__inline void reset(){
		memset(x_offsets, 0, sizeof(x_offsets));
		memset(widths, 0, sizeof(widths));
		count = 0;
		current_block.y_offset = INITIAL_Y;
		current_block.width = INITIAL_WIDTH;
		GLCD_Clear(White);
}
Example #9
0
/*
	Referesh the screen based on the stored characer in the linked list.
*/
void refresh_lcd( void ) {
	size_t i = 0;
	GLCD_Clear(BGC);

	for( i = 0; i <= window_size; ++i ) {
		GLCD_DisplayString( i, 0, 1, chache[(i + window_start) % CACHE_LINE_CAP ]);
	}
}
Example #10
0
/*----------------------------------------------------------------------------
 *        Initialize On Board LCD Module
 *---------------------------------------------------------------------------*/
static void init_display (void) {
  /* LCD Module init */

  GLCD_Init ();
  GLCD_Clear (White);
  GLCD_SetTextColor (Blue);
  GLCD_DisplayString (1, 2, "     RL-ARM");
  GLCD_DisplayString (2, 2, "SD_File example");
}
Example #11
0
/* With ARM and GHS toolsets, the entry point is main() - this will
   allow the linker to generate wrapper code to setup stacks, allocate
   heap area, and initialize and copy code and data segments. For GNU
   toolsets, the entry point is through __start() in the crt0_gnu.asm
   file, and that startup code will setup stacks and data */
int main(void)
{
	System_Init();                         // Initialize System

	GLCD_Clear(White);
	GLCD_Circle (80,80,30,YES,Blue,Green); // Draw Green Circle with Blue boundary
    while(1);
    return 1;
}
Example #12
0
int main(void)
{
	SystemInit();
	GLCD_Init();
	GLCD_Clear(White);

	runHardwareTimer();

	return 0;
}
Example #13
0
/*----------------------------------------------------------------------------
 *        Main: Initialize and start RTX Kernel
 *---------------------------------------------------------------------------*/
int main (void) {

  SystemInit();                             /* Initialize the MCU clocks     */

  LED_init ();                              /* Initialize the LEDs           */
 
  GLCD_Init();                              /* Initialize the GLCD           */
  GLCD_Clear(White);                        /* Clear the GLCD                */

  os_sys_init(init);                        /* Initialize RTX and start init */
}
void show_bitmap()
{
	
	
	int ax_Phys[2],ay_Phys[2],i;
	unsigned char *images[] = { gImage_terminator_large,
					gImage_britney
					};
	//clear_buttons_and_frames();
	
	GUIDEMO_ShowIntro("Photographic Bitmap",
                    "Showing"
                    "\nTerminator Sarah Connor Chronicles"
                    "\nBy Siddharth Kaul");
	GLCD_Init ();
  	GLCD_Clear (White);
	i = 0;
	do
	{
		GUI_PID_STATE State;
		GUI_TOUCH_GetState(&State);
		if (State.Pressed) 
		{
			GLCD_Clear(White);
		    GLCD_Bitmap(0, 0, 320, 240, images[i]);
			i++;
			if(i > 1)
			{
				i = 0;	
			}
			
			//break;
		}
	}while(1);//end of do while	
	//delete pointer to free up memory
	free(images);
	/*
	GUI_SetFont(&GUI_Font24B_1);
	GUI_SetColor(GUI_YELLOW);
	GUI_DispStringAt("Terminator", 0,0);*/
}
Example #15
0
int main(void) {
    SystemInit();
    GLCD_Init();
    GLCD_Clear(White);
    GLCD_DisplayString(0, 0, 1, "LAB 2");

    init_morse_code_fsm();
    init_debounced_button();

    while(1) {}

    return 0;
}
Example #16
0
int main( void ) {
	/*** Declare all variables ***/
// 	unsigned short circle[N][N] = {BG};
// 	unsigned short circleBitmap[N];
	/*** Declare all variables ***/
	
	SystemInit();
	GLCD_Init();
	GLCD_Clear(BG); 
	
	createCircle(160, 120);

  while(1);
}	
Example #17
0
void init_scroll( void ) {
	GLCD_Init(); 

	GLCD_Clear(BGC);
	GLCD_SetBackColor(BGC);
	GLCD_SetTextColor(TXC);

	cache_start = 0;
	cache_size = 0;
	last_col_cahche = 0;
	window_start = 0;
	window_size = 0;

}
Example #18
0
int main(void) {
    SystemInit();
    GLCD_Init();
    GLCD_Clear(Black);
		GLCD_SetTextColor(Red);
		GLCD_SetBackColor(Black);
		__enable_irq();
	
		GLCD_DisplayString(1, 1, 1, "Status: ");
		GLCD_DisplayString(1, 9, 1, "START");
		GLCD_DisplayString(4, 5, 1, "TIMER");
		BoardInit();
	
		hwInterrupt(min_to_run * ms_in_min);
		GLCD_DisplayString(1, 9, 1, "END  ");
    return 0;
}
Example #19
0
int main()
{
	SystemInit();
	GLCD_Init();
	GLCD_Clear(White);

	LED_Init();
	Pushbutton_Init();
	Timer_Init(LPC_TIM0);

	FSM_Init();
	CreateMorseFSM();

	MorseReader_Init();
	MorseReader_FSMRun();

	return 0;
}
Example #20
0
/*----------------------------------------------------------------------------
  Main Thread 'main'
 *---------------------------------------------------------------------------*/
int main (void) {

  LED_Init ();                              /* Initialize the LEDs           */
  GLCD_Init();                              /* Initialize the GLCD           */

  GLCD_Clear(White);                        /* Clear the GLCD                */

  mut_GLCD = osMutexCreate(osMutex(mut_GLCD));

  tid_phaseA = osThreadCreate(osThread(phaseA), NULL);
  tid_phaseB = osThreadCreate(osThread(phaseB), NULL);
  tid_phaseC = osThreadCreate(osThread(phaseC), NULL);
  tid_phaseD = osThreadCreate(osThread(phaseD), NULL);
  tid_clock  = osThreadCreate(osThread(clock),  NULL);
  tid_lcd    = osThreadCreate(osThread(lcd),    NULL);

  osSignalSet(tid_phaseA, 0x0001);          /* set signal to phaseA thread   */

  osDelay(osWaitForever);
  while(1);
}
Example #21
0
/*********************************************************************//**
 * @brief	Main 4-bit LCD porting with GPIO program body
 **********************************************************************/
int c_entry(void)
{
	// DeInit NVIC and SCBNVIC
	NVIC_DeInit();
	NVIC_SCBDeInit();

	/* Configure the NVIC Preemption Priority Bits:
	 * two (2) bits of preemption priority, six (6) bits of sub-priority.
	 * Since the Number of Bits used for Priority Levels is five (5), so the
	 * actual bit number of sub-priority is three (3)
	 */
	NVIC_SetPriorityGrouping(0x05);

	//  Set Vector table offset value
#if (__RAM_MODE__==1)
	NVIC_SetVTOR(0x10000000);
#else
	NVIC_SetVTOR(0x00000000);
#endif

	/* Initialize debug
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* LCD block section -------------------------------------------- */
	GLCD_Init();
//	LCD_cur_off();
	GLCD_Clear(White);

	/* Update LCD Module display text. */
	GLCD_DisplayString(0,0, lcd_text[0] );
	GLCD_DisplayString(1,2, lcd_text[1] );

    /* Loop forever */
    while(1);
    return 1;
}
Example #22
0
/*----------------------------------------------------------------------------
  Thread 6 'lcd': LCD Control Thread
 *---------------------------------------------------------------------------*/
void lcd (void const *argument) {

  GLCD_Clear(White);                                /* Clear the LCD         */
  for (;;) {
    osMutexWait(mut_GLCD, osWaitForever);
    GLCD_SetBackColor(Blue);                        /* Set the Back Color    */
    GLCD_SetTextColor(White);                       /* Set the Text Color    */
    GLCD_DisplayString(0, 0, __FI, "    MCB1700 Demo    ");
    GLCD_DisplayString(1, 0, __FI, "    RTX Traffic     ");
    GLCD_DisplayString(2, 0, __FI, "    www.keil.com    ");
    osMutexRelease(mut_GLCD);
    osDelay(4000);

    osMutexWait(mut_GLCD, osWaitForever);
    GLCD_SetBackColor(Blue);                        /* Set the Back Color    */
    GLCD_SetTextColor(Red);                         /* Set the Text Color    */
    GLCD_DisplayString(0, 0, __FI, "    MCB1700 Demo    ");
    GLCD_DisplayString(1, 0, __FI, "    RTX Traffic     ");
    GLCD_DisplayString(2, 0, __FI, "    www.keil.com    ");
    osMutexRelease(mut_GLCD);
    osDelay(4000);
  }
}
Example #23
0
int_t main(void)
{
   error_t error;
   NetInterface *interface;
   OsTask *task;
   MacAddr macAddr;
#if (APP_USE_DHCP == DISABLED)
   Ipv4Addr ipv4Addr;
#endif
#if (APP_USE_SLAAC == DISABLED)
   Ipv6Addr ipv6Addr;
#endif

   //Initialize kernel
   osInitKernel();
   //Configure debug UART
   debugInit(115200);

   //Start-up message
   TRACE_INFO("\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("*** CycloneTCP Web Server Demo ***\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n");
   TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__);
   TRACE_INFO("Target: SAM3X\r\n");
   TRACE_INFO("\r\n");

   //Configure I/Os
   ioInit();
   //ADC initialization
   adcInit();

   //Initialize LCD display
   GLCD_Init();
   GLCD_SetBackColor(Blue);
   GLCD_SetTextColor(White);
   GLCD_Clear(Blue);

   //Welcome message
   lcdSetCursor(0, 0);
   printf("Web Server Demo\r\n");

   //Generate a random seed

   //PRNG initialization
   error = yarrowInit(&yarrowContext);
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize PRNG!\r\n");
   }

   //Properly seed the PRNG
   error = yarrowSeed(&yarrowContext, seed, sizeof(seed));
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to seed PRNG!\r\n");
   }

   //TCP/IP stack initialization
   error = tcpIpStackInit();
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n");
   }

   //Configure the first Ethernet interface
   interface = &netInterface[0];

   //Set interface name
   tcpIpStackSetInterfaceName(interface, "eth0");
   //Set host name
   tcpIpStackSetHostname(interface, "WebServerDemo");
   //Select the relevant network adapter
   tcpIpStackSetDriver(interface, &sam3xEthDriver);
   tcpIpStackSetPhyDriver(interface, &dm9161PhyDriver);
   //Set external interrupt line driver
   tcpIpStackSetExtIntDriver(interface, &extIntDriver);
   //Set host MAC address
   macStringToAddr(APP_MAC_ADDR, &macAddr);
   tcpIpStackSetMacAddr(interface, &macAddr);

   //Initialize network interface
   error = tcpIpStackConfigInterface(interface);
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name);
   }

#if (IPV4_SUPPORT == ENABLED)
#if (APP_USE_DHCP == ENABLED)
   //Get default settings
   dhcpClientGetDefaultSettings(&dhcpClientSettings);
   //Set the network interface to be configured by DHCP
   dhcpClientSettings.interface = interface;
   //Disable rapid commit option
   dhcpClientSettings.rapidCommit = FALSE;

   //DHCP client initialization
   error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings);
   //Failed to initialize DHCP client?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize DHCP client!\r\n");
   }

   //Start DHCP client
   error = dhcpClientStart(&dhcpClientContext);
   //Failed to start DHCP client?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start DHCP client!\r\n");
   }
#else
   //Set IPv4 host address
   ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr);
   ipv4SetHostAddr(interface, ipv4Addr);

   //Set subnet mask
   ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr);
   ipv4SetSubnetMask(interface, ipv4Addr);

   //Set default gateway
   ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr);
   ipv4SetDefaultGateway(interface, ipv4Addr);

   //Set primary and secondary DNS servers
   ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr);
   ipv4SetDnsServer(interface, 0, ipv4Addr);
   ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr);
   ipv4SetDnsServer(interface, 1, ipv4Addr);
#endif
#endif

#if (IPV6_SUPPORT == ENABLED)
#if (APP_USE_SLAAC == ENABLED)
   //Get default settings
   slaacGetDefaultSettings(&slaacSettings);
   //Set the network interface to be configured
   slaacSettings.interface = interface;

   //SLAAC initialization
   error = slaacInit(&slaacContext, &slaacSettings);
   //Failed to initialize SLAAC?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize SLAAC!\r\n");
   }

   //Start IPv6 address autoconfiguration process
   error = slaacStart(&slaacContext);
   //Failed to start SLAAC process?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start SLAAC!\r\n");
   }
#else
   //Set link-local address
   ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr);
   ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID);

   //Set IPv6 prefix
   ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr);
   ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH);

   //Set global address
   ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr);
   ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID);

   //Set router
   ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr);
   ipv6SetRouter(interface, &ipv6Addr);

   //Set primary and secondary DNS servers
   ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr);
   ipv6SetDnsServer(interface, 0, &ipv6Addr);
   ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr);
   ipv6SetDnsServer(interface, 1, &ipv6Addr);
#endif
#endif

   //Get default settings
   httpServerGetDefaultSettings(&httpServerSettings);
   //Bind HTTP server to the desired interface
   httpServerSettings.interface = &netInterface[0];
   //Listen to port 80
   httpServerSettings.port = HTTP_PORT;
   //Specify the server's root directory
   strcpy(httpServerSettings.rootDirectory, "/www/");
   //Set default home page
   strcpy(httpServerSettings.defaultDocument, "index.shtm");
   //Callback functions
   httpServerSettings.authCallback = httpServerAuthCallback;
   httpServerSettings.cgiCallback = httpServerCgiCallback;
   httpServerSettings.uriNotFoundCallback = httpServerUriNotFoundCallback;

   //HTTP server initialization
   error = httpServerInit(&httpServerContext, &httpServerSettings);
   //Failed to initialize HTTP server?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize HTTP server!\r\n");
   }

   //Start HTTP server
   error = httpServerStart(&httpServerContext);
   //Failed to start HTTP server?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start HTTP server!\r\n");
   }

   //Start TCP echo service
   error = tcpEchoStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start TCP echo service!\r\n");
   }

   //Start UDP echo service
   error = udpEchoStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start UDP echo service!\r\n");
   }

   //Start TCP discard service
   error = tcpDiscardStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start TCP discard service!\r\n");
   }

   //Start UDP discard service
   error = udpDiscardStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start UDP discard service!\r\n");
   }

   //Start TCP chargen service
   error = tcpChargenStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start TCP chargen service!\r\n");
   }

   //Start UDP chargen service
   error = udpChargenStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start UDP chargen service!\r\n");
   }

   //Create user task
   task = osCreateTask("User Task", userTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Create a task to blink the LED
   task = osCreateTask("Blink", blinkTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Start the execution of tasks
   osStartKernel();

   //This function should never return
   return 0;
}
Example #24
0
void Vectored_Interrupt(int button){
	char cString[4], currDiffString[4];
	//GLCD_Clear(White);                    /* Clear graphical LCD display        */
	GLCD_SetBackColor(Blue);
	GLCD_SetTextColor(White);
	
	switch(button){
		case USER_BUTTON:

				//GLCD_DisplayString(0, 0, __FI, "< --User Button -- >");
				switch(currentState) {
					case WELCOME_SCREEN: // If on the welcome screen, set up difficulty screen
						GLCD_Clear(White);
						if(currentDifficulty == 0){
							currentDifficulty = 1;
						}
						updateNextDifficulty(nextDifficulty);
						DisplayInstructions();
						DrawBarGraph(BAR_X,BAR_Y,currentDifficulty * 20,BAR_HEIGHT,BAR_VALUE);
						
						currentState = DIFFICULTY_SCREEN;
						
					break;
						
					case DIFFICULTY_SCREEN: // Transition to Question Screen
						
						updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty);
					
						currentDifficulty = nextDifficulty; // Set the difficulty
						
						currentState = QUESTION_SCREEN;
					
						questionScreen(); // Display the question screen
					
					
					break;
					
					case QUESTION_SCREEN: // Question Screen uses countdown timer - no inputs
						
					break;
					
					case ANSWER_SCREEN:
						
						//answerScreen();
					
						currentState = MARKING_SCREEN; // Mark the users answer
					break;
					

					
					case MARKING_SCREEN: // Mark the users answer attempt
						markAnswer();
					
						currentDifficulty = nextDifficulty; // Set the difficulty
					
						currentState = NEXT_QUESTION;
					
					break;
					
					case NEXT_QUESTION: // Move on to next question
						
						currentDifficulty = nextDifficulty; // Set the difficulty
						currentState = QUESTION_SCREEN;
						questionScreen(); // Display the question screen

					
					break;
					
			};
						
		
		
				//GLCD_DisplayString(6, 0, __FI, GenerateRandomString(5));
				
				//doTone = ~doTone;
			break;
		
		case JOYSTICK_SELECT:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK Select -->");
				// Left available for future program improvements
			break;
		
		case JOYSTICK_UP:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK UP   -- >");
				
				inputAnswer(JOYSTICK_UP);
			break;
		
		case JOYSTICK_DOWN:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK DOWN -- >");
				
				inputAnswer(JOYSTICK_DOWN);
			break;
		
		case JOYSTICK_RIGHT:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK RIGHT-- >");
				
				inputAnswer(JOYSTICK_RIGHT);
			break;
		
		case JOYSTICK_LEFT:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK LEFT -- >");
				
				inputAnswer(JOYSTICK_LEFT);
			break;
		
		case POTENTIOMETER_TURNED:
			  //sprintf(cString, "%02d", c);
		
			switch(currentState) {
				case DIFFICULTY_SCREEN:
					nextDifficulty = (c / 3) + 1;
									
					nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty;
				
					sprintf(currDiffString, "%1d", nextDifficulty);
					//updateScoreAndDifficulty(currentScore, currDifficulty, nextDifficulty);
					updateNextDifficulty(nextDifficulty);
					DrawBarGraph(BAR_X,BAR_Y,nextDifficulty * 20,BAR_HEIGHT,BAR_VALUE);
					//GLCD_SetBackColor(Red);
				break;
				
				case WELCOME_SCREEN:
					
				break;
				
				
				default:
					nextDifficulty = (c / 3) + 1;
									
					nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty;
					sprintf(currDiffString, "%1d", nextDifficulty);
					
					updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty);
					
					
				break;
			}		
					
			break;
		
		default:
			break;
	}
}
Example #25
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void) {
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
  
  /* System Clocks Configuration */
  RCC_Configuration();
  
  /* System Tick Configuration at 1us */
  SysTick_Config(SystemCoreClock / 1000000);
  
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
  
  /* TIM2 Configuration (Client & ATFC Server) */
  TIM2_Configuration();
  
#elif defined USE_EQDAS_SERVER
  
  /* TIM4 Configuration */
  TIM4_Configuration();
  
#endif
  
  /* TIM5 Configuration (GLCD & Ethernet) */
  TIM5_Configuration();
  
  /* TIM6 Configuration (RTC load) */
  //TIM6_Configuration();
  
  /* CLCD Configuration */
  CLCD_Configuration();
  
  /* GLCD Configuration */
  GLCD_Configuration();
  
  /* UART1 Configuration */
  UART_Configuration();
  
  /* RTC configuration by setting the time by Serial USART1 */
  RTC_SetTimeBySerial();
  
  /* Let user set the IP through terminal forcefully */
  //ForceIPSetBySerial();

  /* WIZ820io SPI1 configuration */
  WIZ820io_SPI1_Configuration();
  
  /* W5200 Configuration */
  Set_network();
  
  /* Print WIZ820io configuration */
  printSysCfg();
  
  /* EXTI Configuration */
  EXTI_Configuration();
  
  /* FatFS configuration */
  f_mount(0, &fs);  // mSD
  //f_mount(1, &fs);  // NAND
  
  /* Display Total size of SD card in MB scale */
  SD_TotalSize();
  
  /* Scan all files in mSD card */
  //scan_files(path);
  
  /* MAL configuration */
  //Set_System();
  
  /* UMS configuration */
  //Set_USBClock();
  //USB_Interrupts_Config();
  //USB_Init();
  
  /* loop upon completion of USB Enumeration */
  //while (bDeviceState != CONFIGURED);
  
  /* ATFC Algorithm GPIO */
  ATFC_GPIO_Configuration();
  
  /* ATFC Parameter Initialization */
  ATFCAlgorithmParameterSetup();
  
  /* GPS-UART3 Configuration - This have to be here otherwise it wouldn't work */
  GPS_Configuration();
  
  // For TCP client's connection request delay
  presentTime = my_time;

  /* Create directory and sub directory in accordance with current date */
  filePath = CreateDirectoryAccordingly(GetYearAndMergeToInt(), GetMonthAndMergeToInt(), 
                                        GetDayAndMergeToInt(), RTC_GetCounter() / 3600);
  
  /* Create file in append mode in accordance with current minute */
  CreateFileAppendModeAccordingly(filePath, (RTC_GetCounter() % 3600) / 60);
  
  /* Clear GLCD to better represent waveform */
  GLCD_Clear();
  
  //BKP_WriteBackupRegister(BKP_DR8, 0);
  
  // When everything is set, print message
  printf("\r\n\n - System is ready - ");
  
  while (1) {
    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
    
    /* Index synchronization routine -----------------------------------------------*/
    if(SyncFlag) { // prevent unpleasant impuse from happening
      // Index synchronization dedicated to GLCD & Ethernet
      if(arrIdx != index) {
        // Index synchronization
        arrIdx = index;
      }
    }
    /* End of index synchronization routine -----------------------------------------*/
    
    if(TimerCount > 999) { // 0 ~ 999 (1000) = 1 sec
      TimerCount = 0;
      
      //my_time++;  // uncomment when tcp connection is needed
      
      /* Setup TCP Client or Server -------------------------------------------------*/
      /* Please open config.h file to choose a proper board you wish to use ---------*/    
      /* Start TCP Client process */
      ProcessTcpClient(SOCK_ZERO);  // TCP Client
      
      /* Parameter setting Server side with port 5050 in default */
      ATFCTcpServer(SOCK_TWO, EQDAS_Conf_PORT);  // SOCK_TWO because of flag conformity
      /*------------------------------------------------------------------------------*/
      
      /* Process Parameter Text Stream -----------------------------------------------*/
      if(PCFlag) {  // EQDAS Client System and ATFC Algorithm Setting
        PCFlag = false;
        
        ProcessParameterStream();
      }
      /* End of Parameter process ----------------------------------------------------*/
    }

    /* 10ms interval between points */
    if(TIM5Count >= 9) {
      TIM5Count = 0;
      
      // Make a copy from raw collected data to temporary array
      CopyToTmpArray(arrIdx);
      
      // Determine KMA scale
      KMAGrade = DetermineKMA(arrIdx);
      
      // Check sign bit and apply to int container
      CheckSignAndToInt(arrIdx); // this function also cuts surplus 1G
      
      /* Switch menu & waveform display through graphic lcd */
      GLCD_AxisViewWithWaveform(mode, arrIdx);
      
      //int mATFCBit;
      //mATFCBit_lcd = mAxisBuf.ATFCBit_lcd[arrIdx];
      
      int AxisDataToATFCAlgorithm, mATFCEventDetection;
      AxisDataToATFCAlgorithm = mAxisBuf.tmp_data_y_lcd[arrIdx];  // Axis Z
      ATFCAlgorithm(AxisDataToATFCAlgorithm);
      mATFCEventDetection = EventDetection;
      
      /* Display KMA Intensity on Graphic LCD */
      GLCD_DisplayKMAIntensity(KMAGrade, mATFCEventDetection);
      
      /* Prevent access to volatile variable warning */
      /* This have to be here in order to correct data to be used in ATFC */      
      /* ATFC Server side for each EQ DAS Client */
      if(EQATFCFlag) {
        int mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec;
        mYear = year; mMonth = month; mDay = day;
        mHour = hour; mMin = minute; mSec = second; mTMSec = arrIdx;
        
        int mX, mY, mZ, mATFCBit;
        mX = mAxisBuf.tmp_data_x_lcd[arrIdx] >> 2;
        mY = mAxisBuf.tmp_data_y_lcd[arrIdx] >> 2;
        mZ = mAxisBuf.tmp_data_z_lcd[arrIdx] >> 2;
        mATFCBit = mATFCEventDetection;
        
        char ATFC_Buf[40];
        sprintf(ATFC_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%d\r\n",
                mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec,
                mX, mY, mZ, mATFCBit);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_TWO) == SOCK_ESTABLISHED) {  // SOCK_TWO : PC
          /* send selected data */
          send(SOCK_TWO, (uint8_t*)ATFC_Buf, strlen(ATFC_Buf), (bool)false);
        }
      }
      // Copy to data buffer to be written through FATFS
      //CopyToFatFsDataBuffer(arrIdx);
    }
    
    /* RTC 1Hz interrupt */
    if(RTCTimeDisplay) { // 1Hz calibrated by RTC
      RTCTimeDisplay = false;
      
      int TimeVar;
      TimeVar = RTC_GetCounter();
      /* Compute hour */
      THH = TimeVar / 3600;
      /* Compute minute */
      TMM = (TimeVar % 3600) / 60;
      /* Compute second */
      TSS = (TimeVar % 3600) % 60;
      
      /* Refresh date on every 1s */
      year = GetYearAndMergeToInt();
      month = GetMonthAndMergeToInt();
      day = GetDayAndMergeToInt();
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      
      if(ThirtyMinuteMark == 1799) {
        ThirtyMinuteMark = 0;
        ThirtyMinuteFlag = true;
      } else {
        ThirtyMinuteMark++; 
      }
      
      /* Adjust realtime clock deviation */
      if(hour > 23) {
        int i, currentDay, mDay, mHour, mMin, mSec;
        mDay = hour / 24;
        
        for(i=0; i<mDay; i++) {
          IncreaseSingleDay();
          if(i == mDay - 1) {
            currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt();
            BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date
          }
        }
        mHour = THH % 24;
        mMin = TMM;
        mSec = TSS;
        
        /* Change the current time */
        RTC_SetCounter(mHour*3600 + mMin*60 + mSec);
      }
    }
    
#endif
    
    if(ParseGPS) {
      ParseGPS = false;
      
      char *srcstr = "$GPRMC";
      char *token = ",";  char *processedString;
      char StringYear[3], StringMonth[3], StringDay[3], StringHour[3], StringMinute[3], StringSecond[3];
      int GPSYear, GPSMonth, GPSDay, GPSHour, GPSMinute, GPSSecond;
      if(strncmp((char const*)GPS_Buffer, srcstr, 6) == 0) {
        //printf("GPS_Buffer = %s\r\n\r\n", (char*)GPS_Buffer);
        processedString = strtok((char*)GPS_Buffer, token);
        processedString = strtok(NULL, token);
        
        strncpy(StringHour, processedString, 2); StringHour[2] = 0;
        strncpy(StringMinute, processedString+2, 2); StringMinute[2] = 0;
        strncpy(StringSecond, processedString+4, 2); StringSecond[2] = 0;
        
        GPSHour = atoi(StringHour) + 9; // Current Hour = StringHour + 9
        GPSMinute = atoi(StringMinute);
        GPSSecond = atoi(StringSecond);
        
        int i; for(i=4; i!=0 ; i--) processedString = strtok(NULL, token);
        
        strncpy(StringYear, processedString+4, 2); StringYear[2] = 0;
        strncpy(StringMonth, processedString+2, 2); StringMonth[2] = 0;
        strncpy(StringDay, processedString, 2); StringDay[2] = 0;
        
        GPSYear = atoi(StringYear) + 2000;  // Currnet Year = StringYear + 2000
        GPSMonth = atoi(StringMonth);
        GPSDay = atoi(StringDay);
        
        /* The Year is chosen as criteria to the time */
        if( (GPSYear == GetYearAndMergeToInt()) && ThirtyMinuteFlag ) { // only when year matches between RTC and GPS
          ThirtyMinuteFlag = false;
          
          if(GPSMonth != GetMonthAndMergeToInt() || GPSDay != GetDayAndMergeToInt() ||
             GPSHour != THH || GPSMinute != TMM || GPSSecond != TSS) {
            /* Change the month and day */
            TranslateIntoMonth(GPSMonth);
            TranslateIntoDay(GPSDay);
            
            /* Save year data to unresettable backup register addr. no. 3 */
            int MMDD; MMDD = (GPSMonth * 100) + GPSDay;
            BKP_WriteBackupRegister(BKP_DR3, MMDD); // Save Month and Date  
            
            /* Change the current time */
            RTC_SetCounter(GPSHour*3600 + GPSMinute*60 + GPSSecond);
            
            printf("GPSHour = %d\r\n", GPSHour);
            printf("GPSMinute = %d\r\n", GPSMinute);
            printf("GPSSecond = %d\r\n\r\n", GPSSecond);
            
            printf("GPSYear = %d\r\n", GPSYear);
            printf("GPSMonth = %d\r\n", GPSMonth);
            printf("GPSDay = %d\r\n\r\n", GPSDay);
            
            printf("GPS-to-System synchronization complete!\r\n\r\n");
          }
        }
      }
    }
    
    if(ParseUSART1) {
      ParseUSART1 = false;
      
      // run some test on SDIO
      //SDIO_TEST();

#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
      
      /* Print WIZ820io configuration */
      printSysCfg();

      printf("\r\n");
      printf("BKP_DR1 = %d\r\n", BKP_ReadBackupRegister(BKP_DR1));
      printf("BKP_DR2 = %d\r\n", BKP_ReadBackupRegister(BKP_DR2));
      printf("BKP_DR3 = %d\r\n", BKP_ReadBackupRegister(BKP_DR3));
      printf("BKP_DR4 = %d\r\n", BKP_ReadBackupRegister(BKP_DR4));
      printf("BKP_DR5 = %d\r\n", BKP_ReadBackupRegister(BKP_DR5));
      printf("BKP_DR6 = %d\r\n", BKP_ReadBackupRegister(BKP_DR6));
      printf("BKP_DR7 = %d\r\n", BKP_ReadBackupRegister(BKP_DR7));
      printf("BKP_DR8 = %d\r\n", BKP_ReadBackupRegister(BKP_DR8));
      printf("BKP_DR9 = %d\r\n", BKP_ReadBackupRegister(BKP_DR9));
      printf("BKP_DR10 = %d\r\n", BKP_ReadBackupRegister(BKP_DR10));
      printf("BKP_DR11 = %d\r\n", BKP_ReadBackupRegister(BKP_DR11));
      printf("BKP_DR12 = %d\r\n", BKP_ReadBackupRegister(BKP_DR12));
      printf("BKP_DR13 = %d\r\n", BKP_ReadBackupRegister(BKP_DR13));
      printf("BKP_DR14 = %d\r\n", BKP_ReadBackupRegister(BKP_DR14));
      printf("BKP_DR15 = %d\r\n", BKP_ReadBackupRegister(BKP_DR15));
      printf("BKP_DR16 = %d\r\n\r\n", BKP_ReadBackupRegister(BKP_DR16));
      
      printf("RX_BUF = %s\r\n", RX_BUF);
      
      /*
      printf("\r\nstrlen(HEADER) : %d %s", strlen(HEADER), HEADER);
      
      printf("\r\nf_mkdir1 : ");
      char *dirPath = "0:/20130517";
      res = f_mkdir(dirPath);
      FPrintFatResult(res);
      
      printf("\r\nf_mkdir2 : ");
      dirPath = "0:/20130517/22H-23H";
      res = f_mkdir(dirPath);
      FPrintFatResult(res);
      
      char *filePath = "0:/20130517/2-23H/test.txt";
      // Create log file on the drive 0
      res = open_append(&fsrc, filePath);
      FPrintFatResult(res);
      
      if(res == FR_OK) {
        printf("test.txt successfully created\r\n");
        
        // Write buffer to file
        int bytesWritten;
        bytesWritten = f_printf(&fsrc, HEADER);
        printf("\r\n%d of bytesWritten", bytesWritten);
        
        // Close file
        f_close(&fsrc);
        
      } else if ( res == FR_EXIST ) {
        printf("\r\ntest.txt already exist");
      }
      */
      
      
#elif (defined) USE_EQDAS_SERVER
      
      char buffer[40];
      sprintf(buffer, "%s_%s_%s_%s_%s\r\n",
                DAQBoardOne[arrIdx].Date,
                DAQBoardOne[arrIdx].Time,
                DAQBoardOne[arrIdx].AxisX,
                DAQBoardOne[arrIdx].AxisY,
                DAQBoardOne[arrIdx].AxisZ);
      printf("\r\nRX_BUF : %s, strlen(RX_BUF) : %d", (char*)RX_BUF, strlen((char*)RX_BUF));
      printf("\r\nstrlen(buffer) = %d\n%s", strlen(buffer), buffer);
      
#endif
    
    }
    
// following routine is only necessary when the board works as server
#if defined USE_EQDAS_SERVER
    
    /* Server also needs to have get CLCD going while running */
    /* RTC 1Hz interrupt */
    if(RTCTimeDisplay) { // 1Hz calibrated by RTC
      RTCTimeDisplay = false;
      
      /* Adjust realtime clock deviation */
      if(hour > 23) {
        int i, currentDay, mDay, mHour, mMin, mSec;
        mDay = hour / 24;
        
        for(i=0; i<mDay; i++) {
          IncreaseSingleDay();
          if(i == mDay - 1) {
            currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt();
            BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date
          }
        }
        
        mHour = THH % 24;
        mMin = TMM;
        mSec = TSS;
        
        /* Change the current time */
        RTC_SetCounter(mHour*3600 + mMin*60 + mSec);
      }
      
      /* Display current time */
      Time_Display(RTC_GetCounter());
    }
    
    /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */
    /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */
    if(E1Flag) {
      E1Flag = false; // clear flag since this routine excutes ceaselessly over time
      
      ProcessTextStream(EQ_ONE, (char*)RX_BUF, E1Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag && !E2Flag) { // only when PC is connected and EQ-DAQ-02 is not connected
        // Send directly to PC
        SingleBoardDataToSendToPC(EQ_ONE, E1Order-10);
      }
      
      if(E1Order < 99) E1Order++;
      else E1Order = 0;
    }
    
    /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */
    /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */
    if(E2Flag) {
      E2Flag = false;
      
      ProcessTextStream(EQ_TWO, (char*)RX_BUF, E2Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag && !E1Flag) { // only when PC is connected and EQ-DAQ-01 is not connected
        // Send directly to PC
        //SendToPC(EQ_TWO, E2Order);
      }
      
      if(E2Order < 99) E2Order++;
      else E2Order = 0;
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {
        // Send directly to PC
        MultipleBoardDataToSendToPC(EQ_BOTH, E1Order-10, E2Order-10);
      }
    }
    
    /* Process server socket with each port */
    ProcessTcpServer(SOCK_ZERO, 5050);  // designated as for EQM-DAQ-01 with port 5050
    ProcessTcpServer(SOCK_ONE, 6060);   // designated as for EQM-DAQ-02 with port 6060
    ProcessTcpServer(SOCK_TWO, 7070);   // designated as for PC-CLIENT  with port 7070
    ProcessTcpServer(SOCK_THREE, 8080); // designated as for PC_DUMP    with port 8080
    
    /*
    ProcessTcpServer(SOCK_FOUR, 9090);   // designated as for TOBEUSED with port 9090
    ProcessTcpServer(SOCK_FIVE, 10010);   // designated as for TOBEUSED with port 10010
    ProcessTcpServer(SOCK_SIX, 10020);    // designated as for TOBEUSED with port 10020
    ProcessTcpServer(SOCK_SEVEN, 10030);  // designated as for TOBEUSED with port 10030
    */
      
#endif
      
  }
Example #26
0
File: LCDtask.c Project: benwr/blab
// This is the actual task that is run
static portTASK_FUNCTION(vLCDUpdateTask, pvParameters)
{
#if LCD_EXAMPLE_OP == 0
  unsigned short screenColor = 0;
  unsigned short tscr;
  unsigned char curLine;
  unsigned timerCount = 0;
  int xoffset = 0, yoffset = 0;
  unsigned int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
  unsigned int x, y;
  int i;
  float hue = 0, sat = 0.2, light = 0.2;
#else  // if LCD_EXAMPLE_OP==1
  unsigned char picIndex = 0;
#endif
  vtLCDMsg msgBuffer;
  vtLCDStruct *lcdPtr = (vtLCDStruct *)pvParameters;

#ifdef INSPECT_STACK
  // This is meant as an example that you can re-use in your own tasks
  // Inspect to the stack remaining to see how much room is remaining
  // 1. I'll check it here before anything really gets started
  // 2. I'll check during the run to see if it drops below 10%
  // 3. You could use break points or logging to check on this, but
  //    you really don't want to print it out because printf() can
  //    result in significant stack usage.
  // 4. Note that this checking is not perfect -- in fact, it will not
  //    be able to tell how much the stack grows on a printf() call and
  //    that growth can be *large* if version 1 of printf() is used.
  unsigned portBASE_TYPE InitialStackLeft = uxTaskGetStackHighWaterMark(NULL);
  unsigned portBASE_TYPE CurrentStackLeft;
  float remainingStack = InitialStackLeft;
  remainingStack /= lcdSTACK_SIZE;
  if (remainingStack < 0.10) {
    // If the stack is really low, stop everything because we don't want it to
    // run out
    // The 0.10 is just leaving a cushion, in theory, you could use exactly all
    // of it
    VT_HANDLE_FATAL_ERROR(0);
  }
#endif

  // Graph initialization
  const unsigned graphXoff = 30;
  const unsigned graphYoff = 10;
  const unsigned graphWidth = 260;
  const unsigned graphHeight = 160;
  uint8_t graphVals[graphWidth];
  for (i = 0; i < graphWidth; i++) {
    graphVals[i] = 0;
  }
  uint8_t graphStart = 0;

  /* Initialize the LCD and set the initial colors */
  GLCD_Init();
  tscr = White;         // may be reset in the LCDMsgTypeTimer code below
  screenColor = Black;  // may be reset in the LCDMsgTypeTimer code below
  GLCD_SetTextColor(tscr);
  GLCD_SetBackColor(screenColor);
  GLCD_Clear(screenColor);
  GLCD_ClearWindow(graphXoff - 1, graphYoff - 1, 1, graphHeight + 1, Blue);
  GLCD_ClearWindow(
      graphXoff - 1, graphYoff + graphHeight + 1, graphWidth + 1, 1, Blue);
  GLCD_DisplayString(22, 47, 0, (unsigned char *)"0min");
  GLCD_DisplayString(22, 37, 0, (unsigned char *)"-1min");
  GLCD_DisplayString(22, 27, 0, (unsigned char *)"-2min");
  GLCD_DisplayString(22, 17, 0, (unsigned char *)"-3min");
  GLCD_DisplayString(22, 7, 0, (unsigned char *)"-4min");
  GLCD_DisplayString(22, 0, 0, (unsigned char *)"0.0m");
  GLCD_DisplayString(14, 0, 0, (unsigned char *)"0.5m");
  GLCD_DisplayString(8, 0, 0, (unsigned char *)"1.0m");
  GLCD_DisplayString(2, 0, 0, (unsigned char *)"1.5m");

// Note that srand() & rand() require the use of malloc() and should not be used
// unless you are using
//   MALLOC_VERSION==1
#if MALLOC_VERSION == 1
  srand((unsigned)55);  // initialize the random number generator to the same
                        // seed for repeatability
#endif

  curLine = lcdNUM_SMALL_LINES - 1;
  // This task should never exit
  for (;;) {
#ifdef INSPECT_STACK
    CurrentStackLeft = uxTaskGetStackHighWaterMark(NULL);
    float remainingStack = CurrentStackLeft;
    remainingStack /= lcdSTACK_SIZE;
    if (remainingStack < 0.10) {
      // If the stack is really low, stop everything because we don't want it to
      // run out
      VT_HANDLE_FATAL_ERROR(0);
    }
#endif

#if LCD_EXAMPLE_OP == 0
    // Wait for a message
    if (xQueueReceive(lcdPtr->inQ, (void *)&msgBuffer, portMAX_DELAY) !=
        pdTRUE) {
      VT_HANDLE_FATAL_ERROR(0);
    }

    // Log that we are processing a message -- more explanation of logging is
    // given later on
    vtITMu8(vtITMPortLCDMsg, getMsgType(&msgBuffer));
    vtITMu8(vtITMPortLCDMsg, getMsgLength(&msgBuffer));

    // Take a different action depending on the type of the message that we
    // received
    switch (getMsgType(&msgBuffer)) {
    case LCDMsgTypePrint: {
      // This will result in the text printing in the last five lines of the
      // screen
      char lineBuffer[lcdCHAR_IN_LINE + 1];
      copyMsgString(lineBuffer, &msgBuffer, lcdCHAR_IN_LINE);
      // clear the line
      GLCD_ClearLn(curLine, 1);
      // show the text
      GLCD_DisplayString(curLine, 0, 0, (unsigned char *)lineBuffer);
      curLine++;
      if (curLine == lcdNUM_SMALL_LINES) {
        curLine = lcdNUM_SMALL_LINES - 1;
      }
      break;
    }
    case LCDMsgTypePoint: {
      graphVals[graphStart] = getMsgPoint(&msgBuffer);
      break;
    }
    case LCDMsgTypeTimer: {
      // Note: if I cared how long the timer update was I would call my
      // routine
      //    unpackTimerMsg() which would unpack the message and get that value
      // Each timer update will cause a circle to be drawn on the top half of
      // the screen
      //   as explained below

      if (timerCount % 2 == 0) {
        /* ************************************************** */
        // Find a new color for the screen by randomly (within limits)
        // selecting
        // HSL values
        // This can be ignored unless you care about the color map
        /*
                        #if MALLOC_VERSION==1
                        hue = rand() % 360;
                        sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat
           +=
           0.5;
                        light = (rand() % 1024) / 1023.0;	light = light *
           0.8; light += 0.10;
                        #else
                        hue = (hue + 1); if (hue >= 360) hue = 0;
                        sat+=0.01; if (sat > 1.0) sat = 0.20;
                        light+=0.03; if (light > 1.0) light = 0.20;
                        #endif
                        screenColor = hsl2rgb(hue,sat,light);

                        // Now choose a complementary value for the text color
                        hue += 180;
                        if (hue >= 360) hue -= 360;
                        tscr = hsl2rgb(hue,sat,light);
                        GLCD_SetTextColor(tscr);
                        GLCD_SetBackColor(screenColor);

                        unsigned short int *tbuffer = buffer;
                        //int i;
                        for(i = BUF_LEN; i--;) {
                                tbuffer[i] = screenColor;
                        }
        */
        // End of playing around with figuring out a random color
        /* ************************************************** */

        // clear the top half of the screen
        // GLCD_ClearWindow(0,0,320,120,screenColor);

        /*
                        // Now we are going to draw a circle in the buffer
                        // count is how many pixels are in the circle
                        int	count = 50;
                        float radius;
                        float inc, val, offset = MAX_RADIUS;
                        unsigned short circleColor;
                        inc = 2*M_PI/count;
                        xmax = 0;
                        ymax = 0;
                        xmin = 50000;
                        ymin = 50000;
                        val = 0.0;
                        for (i=0;i<count;i++) {
                                // Make the circle a little thicker
                                // by actually drawing three circles w/
           different radii
                                float cv = cos(val), sv=sin(val);
                                circleColor = (val*0xFFFF)/(2*M_PI);
                                GLCD_SetTextColor(circleColor);
                                for
           (radius=MAX_RADIUS-2.0;radius<=MAX_RADIUS;radius+=1.0) {
                                        x = round(cv*radius+offset);
                                        y = round(sv*radius+offset);
                                        if (x > xmax) xmax = x;
                                        if (y > ymax) ymax = y;
                                        if (x < xmin) xmin = x;
                                        if (y < ymin) ymin = y;
                                        //tbuffer[(y*((MAX_RADIUS*2)+1)) + x]
           =
           circleColor;
                                }
                                val += inc;
                        }
        */
        // GLCD_ClearWindow(graphXoff, graphYoff, graphWidth, graphHeight,
        // screenColor);
        graphStart = (graphStart + 1) % graphWidth;

        DEBUG_OUT(0xf);
        for (i = 0; i < graphWidth; i++) {
          unsigned index = (i + graphStart) % graphWidth;
          unsigned y = graphHeight - graphVals[index] + graphYoff;
          unsigned x = i + graphXoff;
          GLCD_ClearWindow(x, graphYoff, 1, graphHeight, screenColor);
          GLCD_PutPixel(x, y);
        }
        DEBUG_OUT(0x0);

      }  // else {

      // We are going to write out the buffer
      //   back onto the screen at a new location
      // This is *very* fast

      /*
      // First, clear out where we were
      GLCD_ClearWindow(xoffset,yoffset,xmax+1-xmin,ymax+1-ymin,screenColor);
      // Pick the new location
      #if MALLOC_VERSION==1
      xoffset = rand() % (320-(xmax+1-xmin));
      yoffset = rand() % (120-(ymax+1-ymin));
      #else
      xoffset = (xoffset + 10) % (320-(xmax+1-xmin));
      yoffset = (yoffset + 10) % (120-(ymax+1-ymin));
      #endif
      // Draw the bitmap
      GLCD_Bitmap(xoffset,yoffset,xmax+1-xmin,ymax-1-ymin,(unsigned
      char*)buffer);
      */
      //}

      timerCount++;
      if (timerCount >= 100) {
        // every so often, we reset timer count and start again
        // This isn't for any important reason, it is just to for this example
        // code to do "stuff"
        timerCount = 0;
      }
      break;
    }
    default: {
      // In this configuration, we are only expecting to receive timer
      // messages
      VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
      break;
    }
    }  // end of switch()

// Here is a way to do debugging output via the built-in hardware -- it requires
// the ULINK cable and the debugger in the Keil tools to be connected.  You can
// view PORT0 output in the "Debug(printf) Viewer" under "View->Serial Windows".
// You have to enable "Trace" and "Port0" in the Debug setup options.  This
// should not be used if you are using Port0 for printf(). There are 31 other
// ports and their output (and port 0's) can be seen in the
// "View->Trace->Records" windows.  You have to enable the ports in the Debug
// setup options.  Note that unlike ITM_SendChar() this "raw" port write is not
// blocking.  That means it can overrun the capability of the system to record
// the trace events if you go too quickly; that won't hurt anything or change
// the program execution and you can tell if it happens because the
// "View->Trace->Records" window will show there was an overrun.

// vtITMu16(vtITMPortLCD,screenColor);

#elif LCD_EXAMPLE_OP == 1
    // In this alternate version, we just keep redrawing a series of bitmaps as
    // we receive timer messages

    // Wait for a message
    if (xQueueReceive(lcdPtr->inQ, (void *)&msgBuffer, portMAX_DELAY) !=
        pdTRUE) {
      VT_HANDLE_FATAL_ERROR(0);
    }
    if (getMsgType(&msgBuffer) != LCDMsgTypeTimer) {
      // In this configuration, we are only expecting to receive timer messages
      VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
    }
    /* go through a  bitmap that is really a series of bitmaps */
    picIndex = (picIndex + 1) % 9;
    GLCD_Bmp(99,
             99,
             120,
             45,
             (unsigned char *)&ARM_Ani_16bpp[picIndex * (120 * 45 * 2)]);
#else
    Bad setting
#endif
  }
}
Example #27
0
// This is the actual task that is run
static portTASK_FUNCTION( vLCDUpdateTask, pvParameters )
{
	#if LCD_EXAMPLE_OP==0
	unsigned short screenColor = 0;
	unsigned short tscr;
	unsigned char curLine;
	unsigned timerCount = 0;
	int xoffset = 0, yoffset = 0;
	unsigned int xmin=0, xmax=0, ymin=0, ymax=0;
	unsigned int x, y;
	int i, j;
	float hue=0, sat=0.2, light=0.2;
	#elif LCD_EXAMPLE_OP==1
	unsigned char picIndex = 0;
	#else
	Bad definition
	#endif
	vtLCDMsg msgBuffer;
	vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters;

	#ifdef INSPECT_STACK
	// This is meant as an example that you can re-use in your own tasks
	// Inspect to the stack remaining to see how much room is remaining
	// 1. I'll check it here before anything really gets started
	// 2. I'll check during the run to see if it drops below 10%
	// 3. You could use break points or logging to check on this, but
	//    you really don't want to print it out because printf() can
	//    result in significant stack usage.
	// 4. Note that this checking is not perfect -- in fact, it will not
	//    be able to tell how much the stack grows on a printf() call and
	//    that growth can be *large* if version 1 of printf() is used.   
	unsigned portBASE_TYPE InitialStackLeft = uxTaskGetStackHighWaterMark(NULL);
	unsigned portBASE_TYPE CurrentStackLeft;
	float remainingStack = InitialStackLeft;
	remainingStack /= lcdSTACK_SIZE;
	if (remainingStack < 0.10) {
		// If the stack is really low, stop everything because we don't want it to run out
		// The 0.10 is just leaving a cushion, in theory, you could use exactly all of it
		VT_HANDLE_FATAL_ERROR(0);
	}
	#endif

	/* Initialize the LCD and set the initial colors */
	GLCD_Init();
	tscr = Red; // may be reset in the LCDMsgTypeTimer code below
	screenColor = White; // may be reset in the LCDMsgTypeTimer code below
	GLCD_SetTextColor(tscr);
	GLCD_SetBackColor(screenColor);
	GLCD_Clear(screenColor);

	// Added by Matthew Ibarra 2/2/2013
	int xPos = 0;

	// Note that srand() & rand() require the use of malloc() and should not be used unless you are using
	//   MALLOC_VERSION==1
	#if MALLOC_VERSION==1
	srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability
	#endif

	curLine = 5;
	// This task should never exit
	for(;;)
	{	
		#ifdef INSPECT_STACK   
		CurrentStackLeft = uxTaskGetStackHighWaterMark(NULL);
		float remainingStack = CurrentStackLeft;
		remainingStack /= lcdSTACK_SIZE;
		if (remainingStack < 0.10) {
			// If the stack is really low, stop everything because we don't want it to run out
			VT_HANDLE_FATAL_ERROR(0);
		}
		#endif

		#if LCD_EXAMPLE_OP==0
		// Wait for a message
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}
		

		#if EXAMPLE_COLOR_CHANGE==1
		//Log that we are processing a message -- more explanation of logging is given later on
		vtITMu8(vtITMPortLCDMsg,getMsgType(&msgBuffer));
		vtITMu8(vtITMPortLCDMsg,getMsgLength(&msgBuffer));

		// Take a different action depending on the type of the message that we received
		switch(getMsgType(&msgBuffer)) {
		case LCDMsgTypePrint: {
			// This will result in the text printing in the last five lines of the screen
			char   lineBuffer[lcdCHAR_IN_LINE+1];
			copyMsgString(lineBuffer,&msgBuffer,lcdCHAR_IN_LINE);
			// clear the line
			GLCD_ClearLn(curLine,1);
			// show the text
			GLCD_DisplayString(curLine,0,1,(unsigned char *)lineBuffer);
			curLine++;
			if (curLine == lcdNUM_LINES) {
				curLine = 5;
			}
			break;
		}
		case LCDMsgTypeTimer: {
			// Note: if I cared how long the timer update was I would call my routine
			//    unpackTimerMsg() which would unpack the message and get that value
			// Each timer update will cause a circle to be drawn on the top half of the screen
			//   as explained below
			if (timerCount == 0) {
				/* ************************************************** */
				// Find a new color for the screen by randomly (within limits) selecting HSL values
				// This can be ignored unless you care about the color map
				#if MALLOC_VERSION==1
				hue = rand() % 360;
				sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat += 0.5;
				light = (rand() % 1024) / 1023.0;	light = light * 0.8; light += 0.10;
				#else
				hue = (hue + 1); if (hue >= 360) hue = 0;
				sat+=0.01; if (sat > 1.0) sat = 0.20;	
				light+=0.03; if (light > 1.0) light = 0.20;
				#endif
				screenColor = hsl2rgb(hue,sat,light);
				// Now choose a complementary value for the text color
				hue += 180;
				if (hue >= 360) hue -= 360;
				tscr = hsl2rgb(hue,sat,light);
				GLCD_SetTextColor(tscr);
				GLCD_SetBackColor(screenColor);
				// End of playing around with figuring out a random color
				/* ************************************************** */

				// clear the top half of the screen
				GLCD_ClearWindow(0,0,320,120,screenColor); 

				// Now we are going to draw a circle in the upper left corner of the screen
				int	count = 200;
				float radius;
				float inc, val, offset = MAX_RADIUS;
				unsigned short circleColor;
				inc = 2*M_PI/count;
				xmax = 0;
				ymax = 0;
				xmin = 50000;
				ymin = 50000;
				val = 0.0;
				for (i=0;i<count;i++) {
					// Make the circle a little thicker
					// by actually drawing three circles w/ different radii
					float cv = cos(val), sv=sin(val);
					circleColor = (val*0xFFFF)/(2*M_PI);
					GLCD_SetTextColor(circleColor);
					for (radius=MAX_RADIUS-2.0;radius<=MAX_RADIUS;radius+=1.0) {
						x = round(cv*radius+offset);
						y = round(sv*radius+offset);
						if (x > xmax) xmax = x;
						if (y > ymax) ymax = y;
						if (x < xmin) xmin = x;
						if (y < ymin) ymin = y;
						GLCD_PutPixel(x,y);	
					}
					val += inc;
				}
				// Now we are going to read the upper left square of the LCD's
				// memory (see its data sheet for details on that) and save
				// that into a buffer for fast re-drawing later
				if (((xmax+1-xmin)*(ymax+1-ymin)) > BUF_LEN) {
					// Make sure we have room for the data
					VT_HANDLE_FATAL_ERROR(0);
				}
				unsigned short int *tbuffer = buffer;
				unsigned int width = (xmax+1-xmin);
				for (j=ymin;j<=ymax;j++) {
					GLCD_GetPixelRow (xmin,j,width,tbuffer);
					tbuffer += width;
				}
				// end of reading in the buffer
				xoffset = xmin;
				yoffset = ymin;
			} else {
				// We are going to write out the data read into the buffer
				//   back onto the screen at a new location
				// This is *very* fast

				// First, clear out where we were
				GLCD_ClearWindow(xoffset,yoffset,xmax+1-xmin,ymax+1-ymin,screenColor);
				// Pick the new location
				#if MALLOC_VERSION==1
				xoffset = rand() % (320-(xmax+1-xmin));
				yoffset = rand() % (120-(ymax+1-ymin));
				#else
				xoffset = (xoffset + 10) % (320-(xmax+1-xmin));
				yoffset = (yoffset + 10) % (120-(ymax+1-ymin));
				#endif
				// Draw the bitmap
				GLCD_Bitmap(xoffset,yoffset,xmax+1-xmin,ymax-1-ymin,(unsigned char *)buffer);
			}
			timerCount++;
			if (timerCount >= 40) {	  
				// every so often, we reset timer count and start again
				// This isn't for any important reason, it is just to for this example code to do "stuff"
				timerCount = 0;
			}
			break;
		}
		default: {
			// In this configuration, we are only expecting to receive timer messages
			VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
			break;
		}
		} // end of switch()
		#endif
		#if MILESTONE_1==1
		// Added by Matthew Ibarra 2/2/2013
			if(timerCount==0) {
				GLCD_Clear(screenColor);
				
				// Draw the vertical gridlines onto the LCD
				int i;
				for(i = 320/6; i < 315; i = i + 320/6) {
					GLCD_ClearWindow(i, 0, 1, 240, Red);
				}
				
				// Draw the vertical gridlines onto the LCD
				for(i = 240/4; i < 235; i = i + 240/4) {
					GLCD_ClearWindow(0, i, 320, 1, Red);
				}
				
				//Output Scale on LCD
				GLCD_DisplayString(29, 0, 0, (unsigned char*) "V/div=2.5 s/div=3");
				timerCount++;
			}
			int adcValue;
			getMsgValue(&adcValue, &msgBuffer);
			int displayValue;
			displayValue = 120 - (adcValue * 120)/(0x100);
			GLCD_ClearWindow(xPos, displayValue, 2, 2, Black);
			xPos += 2;
			if(xPos > 320) {
				timerCount = 0;
				xPos = 0;
			}
		#endif

		// Here is a way to do debugging output via the built-in hardware -- it requires the ULINK cable and the
		//   debugger in the Keil tools to be connected.  You can view PORT0 output in the "Debug(printf) Viewer"
		//   under "View->Serial Windows".  You have to enable "Trace" and "Port0" in the Debug setup options.  This
		//   should not be used if you are using Port0 for printf()
		// There are 31 other ports and their output (and port 0's) can be seen in the "View->Trace->Records"
		//   windows.  You have to enable the prots in the Debug setup options.  Note that unlike ITM_SendChar()
		//   this "raw" port write is not blocking.  That means it can overrun the capability of the system to record
		//   the trace events if you go too quickly; that won't hurt anything or change the program execution and
		//   you can tell if it happens because the "View->Trace->Records" window will show there was an overrun.
		//vtITMu16(vtITMPortLCD,screenColor);

		#elif 	LCD_EXAMPLE_OP==1
		// In this alternate version, we just keep redrawing a series of bitmaps as
		//   we receive timer messages
		// Wait for a message
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}
		if (getMsgType(&msgBuffer) != LCDMsgTypeTimer) {
			// In this configuration, we are only expecting to receive timer messages
			VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
		}
  		/* go through a  bitmap that is really a series of bitmaps */
		picIndex = (picIndex + 1) % 9;
		GLCD_Bmp(99,99,120,45,(unsigned char *) &ARM_Ani_16bpp[picIndex*(120*45*2)]);
		#else
		Bad setting
		#endif	
	}
}
Example #28
0
/** @addtogroup GLCD_CAL_Public_Functions
 * @{
 */
void TSC2004_Cal_Init(MATRIX_Type *matrixPtr)
{
	int n;
	COLORCFG_Type ClrCfg;
	MATRIX_Type	matrix[4],avgmatrix;
	ts_event RTouch;
	ts_eventCal screenSample[5];
	ts_eventCal displaySample[5] =	{
									{  20,  20 },
									{ 300,  20 },
									{ 300, 220 },
									{  20, 220 },
									{ 160, 120 },
								};

 ts_eventCal displaytriangle1[3] = {displaySample[0],displaySample[4],displaySample[1]};
 ts_eventCal displaytriangle2[3] = {displaySample[1],displaySample[4],displaySample[2]};
 ts_eventCal displaytriangle3[3] = {displaySample[2],displaySample[4],displaySample[3]};
 ts_eventCal displaytriangle4[3] = {displaySample[3],displaySample[4],displaySample[0]};



 GLCD_Clear(White);


 for(n=0; n<5; n++)
 	{
 		switch (n) {
 			case 0:
 				ClrCfg.bcolor = Red;
 				ClrCfg.bndry = FALSE;
 				ClrCfg.fill = TRUE;
 				ClrCfg.fill_color = Red;
 				GLCD_Circle(20,20,3,&ClrCfg);
 				break;

 			case 1:
 				ClrCfg.bcolor = Red;
 				ClrCfg.bndry = FALSE;
 				ClrCfg.fill = TRUE;
 				ClrCfg.fill_color = Red;
 				GLCD_Circle(300,20,3,&ClrCfg);
 				break;

 			case 2:
 				ClrCfg.bcolor = Red;
 				ClrCfg.bndry = FALSE;
 				ClrCfg.fill = TRUE;
 				ClrCfg.fill_color = Red;
 				GLCD_Circle(300,220,3,&ClrCfg);
 				break;

 			case 3:
 				ClrCfg.bcolor = Red;
 				ClrCfg.bndry = FALSE;
 				ClrCfg.fill = TRUE;
 				ClrCfg.fill_color = Red;
 				GLCD_Circle(20,220,3,&ClrCfg);
 				break;

 			case 4:
 				ClrCfg.bcolor = Red;
 				ClrCfg.bndry = FALSE;
 				ClrCfg.fill = TRUE;
 				ClrCfg.fill_color = Red;
 				GLCD_Circle(160,120,3,&ClrCfg);
 				break;

 			default:
 				break;
 		}
 		//printf(LPC_UART0, "Touch point\n\r");
 		while(TReady == FALSE);
// 		printf(LPC_UART0,"\x1b[8;1After While\n\r");
 		delay_ms(2000);

 		screenSample[n].x = gTouch.x;
 		screenSample[n].y = gTouch.y;
// 		printf(LPC_UART0,"\x1b[3;1H gTouchx = %d08",gTouch.x);
// 		printf(LPC_UART0,"\x1b[4;1H gTouchy = %d08",gTouch.y);

 		TReady = FALSE;
 	}

 	CalTouch=FALSE;
// 	printf(LPC_UART0,"line reached");
 	 ts_eventCal screentriangle1[3] = {screenSample[0],screenSample[4],screenSample[1]};
     ts_eventCal screentriangle2[3] = {screenSample[1],screenSample[4],screenSample[2]};
     ts_eventCal screentriangle3[3] = {screenSample[2],screenSample[4],screenSample[3]};
     ts_eventCal screentriangle4[3] = {screenSample[3],screenSample[4],screenSample[0]};


     SetCalibrationMatrix(displaytriangle1, screentriangle1, &matrix[0]);
     SetCalibrationMatrix(displaytriangle2, screentriangle2, &matrix[1]);
     SetCalibrationMatrix(displaytriangle3, screentriangle3, &matrix[2]);
     SetCalibrationMatrix(displaytriangle4, screentriangle4, &matrix[3]);


    	matrixPtr->An = ( matrix[0].An + matrix[1].An + matrix[2].An + matrix[3].An ) / 4;
    	matrixPtr->Bn = ( matrix[0].Bn + matrix[1].Bn + matrix[2].Bn + matrix[3].Bn ) / 4;
    	matrixPtr->Cn = ( matrix[0].Cn + matrix[1].Cn + matrix[2].Cn + matrix[3].Cn ) / 4;
    	matrixPtr->Dn = ( matrix[0].Dn + matrix[1].Dn + matrix[2].Dn + matrix[3].Dn ) / 4;
    	matrixPtr->En = ( matrix[0].En + matrix[1].En + matrix[2].En + matrix[3].En ) / 4;
    	matrixPtr->Fn = ( matrix[0].Fn + matrix[1].Fn + matrix[2].Fn + matrix[3].Fn ) / 4;
    	matrixPtr->Divider = ( matrix[0].Divider + matrix[1].Divider + matrix[2].Divider + matrix[3].Divider ) / 4;


    	GLCD_Clear(White);

}
Example #29
0
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {                       /* Main Program                       */

//************************************************************************************************************
    /* this is contiki-code */
    watchdog_init();

    /* Initialize hardware. */
    clock_init();

    /* UART4 Initialization */
//	uart4_init(115200);
    USBD_Init(&USB_OTG_dev,	USB_OTG_FS_CORE_ID,	&USR_desc, &USBD_CDC_cb, &USR_cb);

    // Led initialization
    leds_init();
    leds_on(LEDS_BLUE);


    PRINTF("\r\nStarting ");
    PRINTF(CONTIKI_VERSION_STRING);
    PRINTF(" on %s \r\n", PLATFORM_NAME);

#ifdef __USE_LCD
    GLCD_Init();                          /* Initialize graphical LCD display   */

    GLCD_Clear(White);                    /* Clear graphical LCD display        */
    GLCD_SetBackColor(DarkGreen);
    GLCD_SetTextColor(White);
    GLCD_DisplayString(0, 0, __FI, " KUSZ - TU Dortmund ");
    GLCD_DisplayString(1, 0, __FI, "       contiki      ");
    GLCD_DisplayString(2, 0, __FI, " www.tu-dortmund.de ");
    GLCD_SetBackColor(White);
    GLCD_SetTextColor(Blue);

    watchdog_periodic();
#endif // __USE_LCD

    /*
     * Initialize Contiki and our processes.
     */

#ifdef WITH_SERIAL_LINE_INPUT
    //  uart1_set_input(serial_line_input_byte);
    // serial_line_init();
#endif

    /* rtimer and ctimer should be initialized before radio duty cycling layers*/
    rtimer_init();

    process_init();

    process_start(&sensors_process, NULL);

    /* etimers must be started before ctimer_init */
    process_start(&etimer_process, NULL);
    ctimer_init();

    /* Start radio and radio receive process */
    NETSTACK_RADIO.init();

    /* makes use of cpu-specific RNG peripheral - no seed needed */
    random_init(0);

    /* Set addresses BEFORE starting tcpip process */
    addr.u8[0] = 0x02;
    addr.u8[1] = *((uint8_t*)0x1FFF7A10);
    addr.u8[2] = *((uint8_t*)0x1FFF7A10+1);
    addr.u8[3] = 0xFF;
    addr.u8[4] = 0xFE;
    addr.u8[5] = *((uint8_t*)0x1FFF7A10+2);
    addr.u8[6] = *((uint8_t*)0x1FFF7A10+3);
    addr.u8[7] = *((uint8_t*)0x1FFF7A10+4);

    memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t));
    rimeaddr_set_node_addr(&addr);

    rf230_set_pan_addr(0xabcd,0xbabe,(uint8_t *)&addr.u8);
    rf230_set_channel(CHANNEL_802_15_4);
    rf230_set_txpower(0); /* max */
    PRINTF("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);

    /* Initialize stack protocols */
    queuebuf_init();

    NETSTACK_RDC.init();
    NETSTACK_MAC.init();
    NETSTACK_NETWORK.init();

#define ANNOUNCE_BOOT 1
#if ANNOUNCE_BOOT
    PRINTF("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(),
           CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()),
           rf230_get_txpower());
#if UIP_CONF_IPV6_RPL
    PRINTF("RPL Enabled\n");
#endif
#if UIP_CONF_ROUTER
    PRINTF("Routing Enabled\n");
#endif
#endif /* ANNOUNCE_BOOT */

    process_start(&tcpip_process, NULL);

    /* Autostart other processes */
    autostart_start(autostart_processes);

#if ANNOUNCE_BOOT
    PRINTF("Online\n");
#endif /* ANNOUNCE_BOOT */

    energest_init();
    ENERGEST_ON(ENERGEST_TYPE_CPU);
    watchdog_start();


    while (1) {                           /* Loop forever                       */

        watchdog_periodic();

        process_run();

    }
}
Example #30
0
// This is the actual task that is run
static portTASK_FUNCTION( vLCDUpdateTask, pvParameters )
{
	portTickType xUpdateRate, xLastUpdateTime;
	vtLCDMsg msgBuffer;
	vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters;
	//counter for line display
	//uint8_t counter = 0;
	/* Initialize the LCD */
	GLCD_Init();
	GLCD_Clear(White);

	const char line_0[] = "Calc. Position";
	const char line_2[] = "Bearing from #0";
	const char line_4[] = "GPS";
	const char line_6[] = "Bearing from GPS";
	const char line_8[] = "RSSI [0, 1, 2]";
	int initial = 0;

	// Scale the update rate to ensure it really is in ms
	xUpdateRate = lcdWRITE_RATE_BASE / portTICK_RATE_MS;

	/* We need to initialise xLastUpdateTime prior to the first call to 
	vTaskDelayUntil(). */
	xLastUpdateTime = xTaskGetTickCount();
	// Note that srand() & rand() require the use of malloc() and should not be used unless you are using
	//   MALLOC_VERSION==1
	#if MALLOC_VERSION==1
	srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability
	#endif
	// Like all good tasks, this should never exit
	for(;;)
	{	
	if (LCD_STATE == 2){
		/* Ask the RTOS to delay reschduling this task for the specified time */
		vTaskDelayUntil( &xLastUpdateTime, xUpdateRate );
		// wait for a message from another task telling us to send/recv over i2c
		
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}

		//Log that we are processing a message
		vtITMu8(vtITMPortLCDMsg,msgBuffer.length);

		if (msgBuffer.buf[0] == 0xDE && msgBuffer.buf[1] == 0xAD && msgBuffer.buf[2] == 0xBE){
			GLCD_Clear(White);
			LCD_STATE = 3;		
		}
		else {
			char buf[21];
			sprintf(buf, "%4.6f, %4.6f", msgBuffer.tlat, msgBuffer.tlon);
			GLCD_DisplayString(0,0,1,(unsigned char *)msgBuffer.buf);
			GLCD_DisplayString(1,0,1,(unsigned char *) buf);
		}
	}
	else if (LCD_STATE == 3){
		/* Ask the RTOS to delay reschduling this task for the specified time */
		//vTaskDelayUntil( &xLastUpdateTime, xUpdateRate );

		// wait for a message from another task telling us to send/recv over i2c
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}
		#if USE_GPIO == 1
		GPIO_SetValue(1, 0x20000000);
		#endif
		//Log that we are processing a message
		vtITMu8(vtITMPortLCDMsg,msgBuffer.length);
		// Decide what color and then clear the line
		GLCD_SetTextColor(Black);
		GLCD_SetBackColor(White);

		if(!initial){
			GLCD_DisplayString(0, 0, 1, (unsigned char *)line_0);
			GLCD_DisplayString(2, 0, 1, (unsigned char *)line_2);
			GLCD_DisplayString(4, 0, 1, (unsigned char *)line_4);
			GLCD_DisplayString(6, 0, 1, (unsigned char *)line_6);
			GLCD_DisplayString(8, 0, 1, (unsigned char *)line_8);
			initial++;
		}
		GLCD_DisplayString(msgBuffer.line_num + 1, 0, 1, (unsigned char *)msgBuffer.buf);
		#if USE_GPIO == 1
		GPIO_ClearValue(1, 0x20000000);
		#endif
	}
else{
	//	Bad setting
	}	
	}
}