Example #1
0
void LCD_UpdateScreenInsulin(void)
{
	int column, row;
	
	// Format GlobalPosition into string to display on LCD
	GLCD_SetFont(&GLCD_Font_16x24);
	sprintf(LCD_StringInsulin, "%d%% Remaining", 100 - ((StepperMotor_GlobalPosition * 100) / SYRINGE_LENGTH));
	GLCD_DrawString(20, 40, LCD_StringInsulin);
	
	// Display current insulin queue on LCD
	GLCD_SetFont(&GLCD_Font_6x8);
	GLCD_DrawString(10, 140, "Current Insulin Queue\0");
	for(column = 0; column < INSULIN_QUEUE_SIZE / 4; column++)
	{
		for(row = 0; row < 4; row++)
		{
			if(InsulinQueue_Head != 4 * column + row)
			{
				sprintf(LCD_InsulinQueueEntry, "%d", *(pInsulinQueue_Queue + (4 * column + row)));
			}
			else
			{
				sprintf(LCD_InsulinQueueEntry, "*%d", *(pInsulinQueue_Queue + (4 * column + row)));
			}
			GLCD_DrawString((10 + (row * 30)), 150 + (column * 10), LCD_InsulinQueueEntry);
		}
	}
}
Example #2
0
void LCD_DisplayADC(ProfileOptions* current)
{
	sprintf(LCD_ADCReading, "ADC: %d", current->LastADCReading);
	GLCD_DrawString(20, 100, LCD_ADCReading);
	
	sprintf(LCD_PHReading, " PH: %.2f", current->LastPHReading);
	GLCD_DrawString(20, 110, LCD_PHReading);
}
void DrawPongPreview()
{
	GLCD_DrawRectangle(211,GLCD_HEIGHT/2,103,2); //Draw middle line
	GLCD_DrawRectangle(250,160,5,5); //Draw ball	

	GLCD_DrawRectangle(215,8,50,4); //Draw Up paddle
	GLCD_DrawString(215, (GLCD_HEIGHT/2)-25,  "3"); //Write Upper player's score	

	GLCD_DrawRectangle(260,227,50,4); //Draw bottom paddle
	GLCD_DrawString(215, (GLCD_HEIGHT/2)+10,  "5"); //Write bottmom player's score
}
Example #4
0
void LCD_SetUpCommon(void)
{
	GLCD_SetFont(&GLCD_Font_16x24);
	GLCD_DrawString(112, 5, "Set-Up\0");
	GLCD_DrawBitmap(160, 120, 12, 12, &Arrows_16bpp_red[4*532]); // center dot
	GLCD_DrawBitmap(159, 100, 14, 19, &Arrows_16bpp_red[2*532]); // up arrow
	GLCD_DrawBitmap(159, 133, 14, 19, &Arrows_16bpp_red[3*532]); // down arrow
	GLCD_DrawBitmap(140, 119, 19, 14, &Arrows_16bpp_red[0*532]); // left arrow
	GLCD_DrawBitmap(173, 119, 19, 14, &Arrows_16bpp_red[1*532]); // right arrow
	GLCD_SetFont(&GLCD_Font_6x8);
	GLCD_DrawString(1, 30, "Select option on joystick for:\0");
}
Example #5
0
void LCD_InsulinOverDosePrevention(STATUS current)
{
	GLCD_ClearScreen();
	GLCD_SetFont(&GLCD_Font_16x24);
	if(current == Bolus_Status)
	{
		sprintf(LCD_StringInsulinOD, "Bolus: %d units", Profile_CurrentOptions.BolusSteps);
	}
	else if(current == Basal_Status)
	{
		sprintf(LCD_StringInsulinOD, "Basal: %d units", Profile_CurrentOptions.BasalStepsPerDose);
	}
	GLCD_DrawString(20, 60, LCD_StringInsulinOD);
	GLCD_SetFont(&GLCD_Font_6x8);
	GLCD_DrawString(20, 100, "Please wait to administer insulin\0");
	GLCD_DrawString(20, 120, "Press down on joystick to advance\0");
}
Example #6
0
void LCD_UpdateScreenState(void)
{
	GLCD_SetFont(&GLCD_Font_16x24);
	switch(Control_GlobalState)
	{
		case Administration_State:
			GLCD_DrawString(150, 20, "Admin\0");
			break;
		case Empty_State:
			GLCD_DrawString(150, 20, "Empty\0");
			break;
		case Full_State:
			GLCD_DrawString(150, 20, "Full\0");
			break;
		case None_State:
			GLCD_DrawString(150, 20, "Undefined\0");
			break;
	}
}
Example #7
0
void LCD_UpdateScreenStatus()
{
	GLCD_SetFont(&GLCD_Font_16x24);
	switch(Control_GlobalStatus)
	{
		case Basal_Status:
			GLCD_DrawString(20, 20, "Basal\0");
			break;
		case Bolus_Status:
			GLCD_DrawString(20, 20, "Bolus\0");
			break;
		case Backward_Status:
			GLCD_DrawString(20, 20, "Backward\0");
			break;
		case None_Status:
			GLCD_DrawString(20, 20, "None\0");
			break;
		case Wait_Status:
			GLCD_DrawString(20, 20, "Wait\0");
			break;
	}
}
Example #8
0
void LCD_DisplayOptions(BaseDisplay current)
{
	LCD_SetUpCommon();
	
	GLCD_SetFont(&GLCD_Font_6x8);
	GLCD_DrawString(186, 30, current.ProfileCategory);
	
	GLCD_DrawString(140-((current.Size1 + 3)*6), 121, current.ProfileOption1);
	
	GLCD_DrawString(204, 121, current.ProfileOption2);
	
	GLCD_DrawString(160 - ((current.Size3 / 2) * 6), 85, current.ProfileOption3);
	
	GLCD_DrawString(160 - ((current.Size4 / 2) * 6), 160, current.ProfileOption4);
	
	GLCD_DrawString(90, 185, "Push Down: Glucose Reading\0");
}
void AppPong()
{					
	switch(appPongState)
	{
		case Normal:			

			// Increment ball's position
			new_ball_X += ballVelocityX;
			new_ball_Y += ballVelocityY;
			// Check if the ball is colliding with the left paddle
			if (new_ball_X < (new_paddle0_X + paddleW) )
			{
				// Check if ball is within paddle's height
				if ((new_ball_Y > new_paddle0_Y) && (new_ball_Y < new_paddle0_Y + paddleH))
				{
					new_ball_X += ball_rad;  // Move ball over one to the right
					ballVelocityX = -ballVelocityX; // Change velocity
					Beep();
				}
			}
			// Check if the ball hit the right paddle
			if (new_ball_X + ball_rad > new_paddle1_X)
			{
				// Check if ball is within paddle's height
				if ((new_ball_Y > new_paddle1_Y) && (new_ball_Y < new_paddle1_Y + paddleH))
				{
					new_ball_X -= ball_rad;  // Move ball over one to the left
					ballVelocityX = -ballVelocityX; // change velocity
					Beep();
				}
			}
			// Check if the ball hit the top or bottom
			if ((new_ball_Y <= borderWidth) || (new_ball_Y >= (GLCD_HEIGHT - ball_rad - 1)))
			{
				// Change up/down velocity direction
				ballVelocityY = -ballVelocityY;
				Beep();
			}

			if(AUTOMATIC_CONTROL)
			{
				//Automatic Control
				new_paddle0_Y = new_ball_Y-paddleH/2; // Invincible paddle0					
			}
			else
			{
				//Controlled by potentiometer
				ADC_StartConversion();
				new_paddle0_Y = map(ADC_GetValue(),0,4096,0,GLCD_HEIGHT);
			}
			
			// Automatic control
			new_paddle1_Y = new_ball_Y-paddleH/2; // Invincible paddle1		

			// Check if paddle0 is not out of the frame
			if(new_paddle0_Y  < borderWidth) { // Top Frame
				new_paddle0_Y = borderWidth;
			}
			if(new_paddle0_Y + paddleH > GLCD_HEIGHT - borderWidth) { // Bottom Frame
				new_paddle0_Y = GLCD_HEIGHT - borderWidth - paddleH;
			}
			
			// Check if paddle1 is not out of the frame
			if(new_paddle1_Y  < borderWidth) { // Top Frame
				new_paddle1_Y = borderWidth;
			}
			if(new_paddle1_Y + paddleH > GLCD_HEIGHT - borderWidth) { // Bottom Frame
				new_paddle1_Y = GLCD_HEIGHT - borderWidth - paddleH;
			}

			joyMsk = Joystick_GetState();   // Show joystick arrows               
				if (joy ^ joyMsk)                
					{
						joy = joyMsk;

						if(joy & JOYSTICK_LEFT)
						{
							if(ballVelocityX > 0)
							{
								ballVelocityX--;
							}
							else
							{
								ballVelocityX++;
							}
							
							if(ballVelocityY > 0)
							{
								ballVelocityY--;
							}
							else
							{
								ballVelocityY++;
							}
						}
						if(joy & JOYSTICK_RIGHT)
						{
							if(ballVelocityX > 0)
							{
								ballVelocityX++;
							}
							else
							{
								ballVelocityX--;
							}
							
							if(ballVelocityY > 0)
							{
								ballVelocityY++;
							}
							else
							{
								ballVelocityY--;
							}
						}
						if(joy & JOYSTICK_CENTER)
						{
							
						}
						if(joy & JOYSTICK_UP)
						{						
							GLCD_SetForegroundColor(BackgroundColor);
							GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
							GLCD_SetForegroundColor(BallForegroundColor);
							ball_rad++;
						}
						if(joy & JOYSTICK_DOWN)
						{
							GLCD_SetForegroundColor(BackgroundColor);
							GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
							GLCD_SetForegroundColor(BallForegroundColor);
							ball_rad--;
						}	
				}
				
			if(new_ball_X > GLCD_WIDTH)
			{
				score0++;
				appPongState = Lose;
			}		
			
			if(new_ball_X < 0)
			{
				score1++;
				appPongState = Lose;
			}
			
			// Draw the Pong Field					
			
			//STATIC OBJECTS
			// Draw an outline of the screen:
			GLCD_SetForegroundColor(ForegroundColor);
			GLCD_DrawRectangle(0, 0, GLCD_WIDTH - 1, GLCD_HEIGHT - 1);
			// Draw the center line
			GLCD_DrawRectangle(GLCD_WIDTH/2 - 1, 0, borderWidth, GLCD_HEIGHT);	
			
			//MOVING OBJECTS		
			GLCD_SetForegroundColor(BackgroundColor);
			// Erase the Paddles:
			GLCD_DrawRectangle(old_paddle0_X, old_paddle0_Y, paddleW, paddleH);
			GLCD_DrawRectangle(old_paddle1_X, old_paddle1_Y, paddleW, paddleH);
			// Erase the ball:
			GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
			
			old_paddle0_X = new_paddle0_X;
			old_paddle0_Y = new_paddle0_Y;
			old_paddle1_X = new_paddle1_X;
			old_paddle1_Y = new_paddle1_Y;
			old_ball_X = new_ball_X;
			old_ball_Y = new_ball_Y;
			
			// Draw the Paddles:
			GLCD_SetForegroundColor(LeftPaddleForegroundColor);
			GLCD_DrawRectangle(new_paddle0_X, new_paddle0_Y, paddleW, paddleH);
			
			GLCD_SetForegroundColor(RightPaddleForegroundColor);					
			GLCD_DrawRectangle(new_paddle1_X, new_paddle1_Y, paddleW, paddleH);
			// Draw the ball:
			GLCD_SetForegroundColor(BallForegroundColor);	
			GLCD_DrawRectangle(new_ball_X, new_ball_Y, ball_rad, ball_rad);
			
			sprintf (str_score0, "%1u", score0); //takes the numeric value and convert it to a char with the %1u format (1 unit unsigned)
			sprintf (str_score1, "%1u", score1);
			str_score0[sizeof(str_score0)-1] = '\0'; //indicate end of string
			str_score1[sizeof(str_score1)-1] = '\0';
			GLCD_SetForegroundColor(LeftPaddleForegroundColor);
			GLCD_DrawString(5, 5, str_score0);
			GLCD_SetForegroundColor(RightPaddleForegroundColor);
			GLCD_DrawString((GLCD_WIDTH/2)+5, 5,  str_score1);
		
			break;
			
		case Lose:
			if(score0 >= SCORE_MAX_PONG || score1 >= SCORE_MAX_PONG)
			{
				appPongState = GameOver;
				break;
			}

			InitializeAppPong();
			break;
			
		case GameOver:
			GLCD_SetFont            (&GLCD_Font_16x24);
			if(score0 > score1)
			{
				GLCD_SetForegroundColor(GLCD_COLOR_BLUE);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2), GLCD_HEIGHT/2, "WIN !");
				GLCD_SetForegroundColor(GLCD_COLOR_GREEN);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2) + (GLCD_WIDTH/2), GLCD_HEIGHT/2, "LOSE !");
			}
			else
			{
				GLCD_SetForegroundColor(GLCD_COLOR_GREEN);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2) + (GLCD_WIDTH/2), GLCD_HEIGHT/2, "WIN !");
				GLCD_SetForegroundColor(GLCD_COLOR_BLUE);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2), GLCD_HEIGHT/2,  "LOSE !");
			}			
			
			score0 = 0;
			score1 = 0;
			osDelay(2000);
			menuChoice = InitMenu;

			osThreadTerminate (idThreadBeep);
			break;
	}	
			
}
Example #10
0
void AppMenu()
{
	offset_y = (1*24)+(3*8);
	BackgroundColor = GLCD_COLOR_WHITE;
	ForegroundColor = GLCD_COLOR_BLACK;
	
	joyMsk = Joystick_GetState();         
	if (joy ^ joyMsk)                		
	{
		joy = joyMsk;
	}
	
	if(joy & JOYSTICK_RIGHT)
	{
		switch(selection)
		{
			case 0:
				menuChoice = InitPong;
				break;
			case 1:
				menuChoice = InitShooter;
				break;
		}
	}

	if(joy & JOYSTICK_UP)
	{				
		if(selection > 0)
		{
			selection--;
		}		
	}
	if(joy & JOYSTICK_DOWN)
	{
		if(selection < (numberOfApps-1))
		{
			selection++;
		}		
	}

	GLCD_SetBackgroundColor (BackgroundColor);
  GLCD_SetForegroundColor (ForegroundColor);
  
	GLCD_DrawRectangle(24, 3, 180, offset_y);
					
	GLCD_SetFont            (&GLCD_Font_16x24);
	GLCD_DrawString         (32, (0*24)+(1*8), "Menu");
	GLCD_SetFont            (&GLCD_Font_6x8);
  GLCD_DrawString         (32, (1*24)+(1*8), "UP/DOWN to select a game");
  GLCD_DrawString         (32, (1*24)+(2*8), "RIGHT to confirm your choice");
	
	GLCD_DrawRectangle(210,3,105,233); //Draw border for preview
	//-------------------------------------------
	GLCD_SetFont            (&GLCD_Font_16x24);
	GLCD_SetForegroundColor (ForegroundColor);
	GLCD_DrawString         (32, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1) + offset_y - 12, "PONG");
		
	if(selection == 0)
	{
		GLCD_SetForegroundColor (ForegroundColor); //Draw if selected		
	}
	else
	{
		GLCD_SetForegroundColor (BackgroundColor); //Don't draw if not selected (will be drawn but in the same color as the background, hence invisible)
	}
	GLCD_DrawRectangle(24, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1) + offset_y - 24, 180, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1)-20);
	DrawPongPreview();	
	
	//-------------------------------------------
	
	//-------------------------------------------
	GLCD_SetForegroundColor (ForegroundColor);
	GLCD_DrawString         (32, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*2) + offset_y - 12, "SHOOTER");
		
	if(selection == 1)
	{
		GLCD_SetForegroundColor (ForegroundColor);		
	}
	else
	{
		GLCD_SetForegroundColor (BackgroundColor);	
	}
	GLCD_DrawRectangle(24, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*2) + offset_y - 24, 180, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1)-20);
	DrawShooterPreview();
	 
	 //-------------------------------------------

	
	select_y_start = (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1) + offset_y - 12;
	select_y_end = select_y_start + 32;	

}
Example #11
0
void AppShooter()
{
	  while (!stopShooter) {

		joyMsk = Joystick_GetState();
		btnMsk = Buttons_GetState();

		if (timerTick_01 > 2)
		{
			if (ballTimer != 0) { ballTimer--; }
			if ( ((btnMsk & 1) != 0) && (ballTimer == 0) )
			{
				ballTimer = 8;
				newBall = true;
			}
			
			if (joyMsk != 0)
			{
				osMutexWait(planeVar_mutex_id, osWaitForever);
				// RIGHT
				if ((plane_x < GLCD_WIDTH - 10) && ((joyMsk & 2) != 0))
				{
					plane_x += 10;
				}
				// LEFT
				if ((plane_x > 0) && ((joyMsk & 1) != 0))
				{
					plane_x -= 10;
				}
				// UP
				if ((plane_y > 20) && ((joyMsk & 8) != 0))
				{
					plane_y -= 10;
				}
				// DOWN
				if ((plane_y < GLCD_HEIGHT - 10) && ((joyMsk & 16) != 0))
				{
					plane_y += 10;
				}
				osMutexRelease(planeVar_mutex_id);
			}
			timerTick_01 = 0;
			S_MoveBall(newBall);
			newBall = false;
		}	
		
		if ( timerTick_02 > 12 )
		{
			S_MoveObjects ();
			timerTick_02 = 0;
			
		}
  }

	osThreadTerminate (idThreadPlane);
	osDelay(500);
	
	if (playerScore > machineScore) {
		GLCD_SetForegroundColor (GLCD_COLOR_GREEN);
		GLCD_DrawString ((GLCD_WIDTH-16*9)/2, GLCD_HEIGHT/2-16, "YOU WIN !");
	} else {
		GLCD_SetForegroundColor (GLCD_COLOR_RED);
		GLCD_DrawString ((GLCD_WIDTH-16*11)/2, GLCD_HEIGHT/2-16, "YOU LOSE !");
	}
	osDelay(2000);
	
}
Example #12
0
int main (void) {
  int32_t max_num = LED_GetCount() - 1;
  int32_t num = 0;
  int32_t dir = 1;
  uint32_t keyMsk, adcVal;
  int32_t key  = -1;
  int32_t adc  = -1;

  SystemCoreClockUpdate();

  LED_Initialize();                         /* LED Initialization             */
  ADC_Initialize();                         /* A/D Converter Init             */
  Buttons_Initialize();                     /* Button initialization          */
  GLCD_Initialize();                        /* Initialize the GLCD            */

  SysTick_Config(SystemCoreClock/100);      /* Generate interrupt each 10 ms  */

  GLCD_SetBackgroundColor (GLCD_COLOR_WHITE);
  GLCD_ClearScreen ();

  GLCD_SetBackgroundColor (GLCD_COLOR_BLUE);
  GLCD_SetForegroundColor (GLCD_COLOR_WHITE);
  GLCD_SetFont            (&GLCD_Font_16x24);
  GLCD_DrawString (0*16, 0*24, " STM32303C-EVAL Demo");
  GLCD_DrawString (0*16, 1*24, "  Blinky Example    ");
  GLCD_DrawString (0*16, 2*24, "   www.keil.com     ");
  GLCD_SetBackgroundColor (GLCD_COLOR_WHITE);
  GLCD_SetForegroundColor (GLCD_COLOR_BLUE);

  GLCD_DrawString (0*16, 5*24, "LEDs:               ");
  GLCD_DrawString (0*16, 6*24, "AD value:           ");
  GLCD_DrawString (0*16, 7*24, "Buttons :           ");
  GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY);
  GLCD_DrawString (9*16, 5*24, "0123");

  while (1) {
    /* Force refresh */
    key = -1;
    adc = -1;

    if (LEDOn) {
      LEDOn = 0;
      LED_On (num);                         /* Turn specified LED on          */
      GLCD_SetForegroundColor (GLCD_COLOR_RED);
      GLCD_DrawChar ((9+num)*16, 5*24, numStr[num]);
    }

    if (LEDOff) {
      LEDOff = 0;
      LED_Off (num);                        /* Turn specified LED off         */
      GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY);
      GLCD_DrawChar ((9+num)*16, 5*24, numStr[num]);

      num += dir;                           /* Change LED number              */
      if (dir == 1 && num == max_num) {
        dir = -1;                           /* Change direction to down       */
      }
      else if (num == 0) {
        dir =  1;                           /* Change direction to up         */
      }
    }

    keyMsk = Buttons_GetState();            /* Show buttons state             */
    if (key ^ keyMsk) {
      GLCD_SetForegroundColor (GLCD_COLOR_BLACK);
      if (keyMsk & KEY_USER  )    { GLCD_DrawString (9*16, 7*24, "Key");   }

      GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY);
      if (!(keyMsk & KEY_USER  )) { GLCD_DrawString (9*16, 7*24, "Key");   }
    }

    ADC_StartConversion();                  /* Show A/D conversion bargraph   */
    adcVal = ADC_GetValue();
    if (adc ^ adcVal) {
      adc = adcVal;
      GLCD_SetForegroundColor (GLCD_COLOR_GREEN);
      GLCD_DrawBargraph (9*16, 6*24, 160, 20, (adcVal * 100) / ((1 << ADC_GetResolution()) - 1));
    }
  }
}