/*!
 @brief Thread to display temperature
 @param argument Unused
*/
void temperature_DispFlag_thread(void const * argument)
{
	// Extracts the semaphore object from the argument.
	// This semaphore object was created in the main
	osSemaphoreId* semaphore;
	semaphore = (osSemaphoreId*)argument;
	
	uint8_t ResourceLocked = 1;  // Flag gets turned on if semaphore_lock achieved
	uint32_t tokentemp;          // Return of semwait
	
	// Wait for the semaphore with 1ms timeout
  osEvent event = osSignalWait(SIGNAL_DISP_TEMPERATURE, 1);

	while(1)
	{
		tokentemp=osSemaphoreWait (*semaphore, osWaitForever);
    ResourceLocked=1; // turn flag on if resource_locked		
		
    while (ResourceLocked)
		{
			// wait for a signal with 1ms timeout
			event = osSignalWait(SIGNAL_DISP_TEMPERATURE, 1);
			if (event.status == osEventTimeout)
			{
				// in case of timeout display
				LCD_DisplayTemperature(temp);
			}
			else
			{
				// signal received which is not timeout
				// clear the signal flag for the tilt display thread
				osSignalClear (tilt_TurnDispFlag_thread, SIGNAL_DISP_TILT);
				
				//clear the screen
				LCD_clear_display();
				
				// turn the resource_locked flag off
				ResourceLocked = 0;
				tokentemp=0;
				
				// turn the flag to display the string "temperature" once
				GLB_Temperature_display_flag=1;
				
				// release the semaphore 
				osSemaphoreRelease(*semaphore);
				
				//wait 5ms for the other thread to grab the semaphore
			  osDelay(5);
			}
		}
		
	}
	
}
Example #2
0
void LCD_config()
{
    function_set(1,1,0);    //DL = 1 for 8-bit interface, N = 1 to set the fonts for 2 line display and if N = 1 then value of F doesn't matter

    LCD_clear_display();

    display_control(1,0,0); //D = 1, so that display is On, C = 0, so that cursor is Off, B = 0 so that cursor is not blinking
    Entry_mode_set(1,0);    // I_D = 1 so that the cursor position should increment after each character display. S = 0 because we don't want the display to shift after each character display

    _delay_ms(50);
}
Example #3
0
	void mode_change_thread(void const * argument){
		wirelessTransmit_TX(motor_init);
		keypad_column_init();		
		osDelay(100);
		
		/*read column*/
		int8_t key_column = readKeyColumn();
		keypad_row_init();
		
		/*read row*/
		int8_t key_row = readKeyRow();
		
		mode = read_keypad(key_column, key_row);
			
		while(1){
			mode = read_keypad(key_column, key_row);
				while(mode == 'e'){
						wirelessTransmit_TX(motor_init);
						keypad_column_init();		
						osDelay(100);
						
						/*read column*/
						int8_t key_column = readKeyColumn();
						keypad_row_init();
						
						/*read row*/
						int8_t key_row = readKeyRow();
						
						mode = read_keypad(key_column, key_row);
				}
				if (mode == 'A'){
				printf (">>>>>>>>Entering Mode_1 Real Time Tilting<<<<<<<<\n");
				char mode1[7] = "Mode 1";
				LCD_clear_display();
				LCD_DISPLAY_UPDATE_POS(0x80, mode1);
				wirelessTransmit_TX(mode_A);
				
				tilt_thread = osThreadCreate(osThread(tilt_detection_thread),NULL);
				tilt_transmit_thread = osThreadCreate(osThread(transmitTiltAngles),NULL);
							
				uint8_t readreg=read_Status_Register(WIRELESS_STATUS_VERSION);
				
					mode_selection = 1;
					
			}else if (mode == 'B'){
				printf (">>>>>>>>Entering Mode_2 Movement Sequence Input<<<<<<<<\n");
				wirelessTransmit_TX(mode_B);
//				printf ("A: positive sign(must be entered). B: negative sign. C: terminate input\n");
//				printf ("IMPORTANT: To input <30,-60,10> <-45,65,8>...<20,-30,5> You shall enter the key as following:\n");
//				printf ("A30B60A10B45A65A08...A20B30A05C\n");
				
				keypad_thread = osThreadCreate(osThread(keypad), NULL);
				
				
				mode_selection = 2;
				
				
			}else if (mode == 'C'){
				printf (">>>>>>>>Entering Mode_3 Record and Play Option<<<<<<<<\n");
				wirelessTransmit_TX(mode_C);
				mode_selection = 3;
				
			}
			
			osSignalWait(SIGNAL_MODE_CHANGE, osWaitForever);
			if(mode_selection == 1 ){
				osThreadTerminate(tilt_transmit_thread);
				osThreadTerminate(tilt_thread);
			}
			else if(mode_selection == 2){
				osThreadTerminate(keypad_thread);
			}
			else{
			
			}
			
			mode_selection=0;
		}
}
Example #4
0
void keypad(void const *argument){
	printf("keypad thread entered!\n");		
	int8_t num = -1;
	int8_t k = 0;;
	
	char ch;
	
	
	
//	while(1){
//		keypad_column_init();		
//		osDelay(200);
//		
//		/*read column*/
//		int8_t key_column = readKeyColumn();
//		keypad_row_init();
//		
//		/*read row*/
//		int8_t key_row = readKeyRow();
//		
//		/*read number*/
//		num = read_keypad(key_column, key_row);
	
//		if (num != -1)
//			printf ("%d\n", num);
//		else{
//			ch = read_symble(key_column, key_row);
//			if (ch != 'e'){
//					printf ("%c\n", ch);
//			}
//		
		while (ch != 'D'){
			keypad_column_init();		
			osDelay(250);
			
			/*read column*/
			int8_t key_column = readKeyColumn();
			keypad_row_init();
			
			/*read row*/
			int8_t key_row = readKeyRow();
			
			ch = read_keypad(key_column, key_row);
			
			
		
			
			
			if (ch != 'e' ){	
//				sequence[k] = ch;
//				printf("sequence[%d]: %c\n", k,sequence[k] );
//				k++;
				
				//if (ch == 'D'){
					sequence[0] = ch;
					sequence[1] = 'D';
					printf ("before sendSequence: %s\n", sequence);
					LCD_clear_display();
					LCD_DISPLAY_UPDATE_POS(0x80, sequence);
					sendSequence(sequence);
					//transmit_sequence_thread = osThreadCreate(osThread(transmitSequence), NULL);
					
					
					
					
				//}
				
				
			}
		}
		
//		
//		
	
}