Exemple #1
0
static void
ImagestateDrawBevel(ImageState * is, EX_Drawable win,
		    int x, int y, int w, int h)
{
   GC                  gc;

   gc = EXCreateGC(win, 0, NULL);

   ImagestateColorsAlloc(is);

   switch (is->bevelstyle)
     {
     case BEVEL_AMIGA:
	XSetForeground(disp, gc, is->hihi_pixel);
	LINE(0, 0, w - 2, 0);
	LINE(0, 0, 0, h - 2);
	XSetForeground(disp, gc, is->lolo_pixel);
	LINE(1, h - 1, w - 1, h - 1);
	LINE(w - 1, 1, w - 1, h - 1);
	break;
     case BEVEL_MOTIF:
	XSetForeground(disp, gc, is->hi_pixel);
	LINE(0, 0, w - 1, 0);
	LINE(0, 0, 0, h - 1);
	LINE(1, 1, w - 2, 1);
	LINE(1, 1, 1, h - 2);
	XSetForeground(disp, gc, is->lo_pixel);
	LINE(0, h - 1, w - 1, h - 1);
	LINE(w - 1, 1, w - 1, h - 1);
	LINE(1, h - 2, w - 2, h - 2);
	LINE(w - 2, 2, w - 2, h - 2);
	break;
     case BEVEL_NEXT:
	XSetForeground(disp, gc, is->hihi_pixel);
	LINE(0, 0, w - 1, 0);
	LINE(0, 0, 0, h - 1);
	XSetForeground(disp, gc, is->hi_pixel);
	LINE(1, 1, w - 2, 1);
	LINE(1, 1, 1, h - 2);
	XSetForeground(disp, gc, is->lolo_pixel);
	LINE(1, h - 1, w - 1, h - 1);
	LINE(w - 1, 1, w - 1, h - 1);
	XSetForeground(disp, gc, is->lo_pixel);
	LINE(2, h - 2, w - 2, h - 2);
	LINE(w - 2, 2, w - 2, h - 2);
	break;
     case BEVEL_DOUBLE:
	XSetForeground(disp, gc, is->hi_pixel);
	LINE(0, 0, w - 2, 0);
	LINE(0, 0, 0, h - 2);
	XSetForeground(disp, gc, is->lo_pixel);
	LINE(1, 1, w - 3, 1);
	LINE(1, 1, 1, h - 3);
	XSetForeground(disp, gc, is->lo_pixel);
	LINE(1, h - 1, w - 1, h - 1);
	LINE(w - 1, 1, w - 1, h - 1);
	XSetForeground(disp, gc, is->hi_pixel);
	LINE(2, h - 2, w - 2, h - 2);
	LINE(w - 2, 2, w - 2, h - 2);
	break;
     case BEVEL_WIDEDOUBLE:
	XSetForeground(disp, gc, is->hihi_pixel);
	LINE(0, 0, w - 1, 0);
	LINE(0, 0, 0, h - 1);
	XSetForeground(disp, gc, is->hi_pixel);
	LINE(1, 1, w - 2, 1);
	LINE(1, 1, 1, h - 2);
	LINE(3, h - 4, w - 4, h - 4);
	LINE(w - 4, 3, w - 4, h - 4);
	XSetForeground(disp, gc, is->lolo_pixel);
	LINE(1, h - 1, w - 1, h - 1);
	LINE(w - 1, 1, w - 1, h - 1);
	XSetForeground(disp, gc, is->lo_pixel);
	LINE(2, h - 2, w - 2, h - 2);
	LINE(w - 2, 2, w - 2, h - 2);
	LINE(3, 3, w - 4, 3);
	LINE(3, 3, 3, h - 4);
	break;
     case BEVEL_THINPOINT:
	XSetForeground(disp, gc, is->hi_pixel);
	LINE(0, 0, w - 2, 0);
	LINE(0, 0, 0, h - 2);
	XSetForeground(disp, gc, is->lo_pixel);
	LINE(1, h - 1, w - 1, h - 1);
	LINE(w - 1, 1, w - 1, h - 1);
	XSetForeground(disp, gc, is->hihi_pixel);
	LINE(0, 0, 1, 0);
	LINE(0, 0, 0, 1);
	XSetForeground(disp, gc, is->lolo_pixel);
	LINE(w - 2, h - 1, w - 1, h - 1);
	LINE(w - 1, h - 2, w - 1, h - 1);
	break;
     case BEVEL_THICKPOINT:
	XSetForeground(disp, gc, is->hi_pixel);
	RECT(x, y, w - 1, h - 1);
	break;
     default:
	break;
     }

   EXFreeGC(gc);
}
Exemple #2
0
/**
  * @brief  Manages Audio process. 
  * @param  None
  * @retval Audio error
  */
AUDIO_ErrorTypeDef AUDIO_PLAYER_Process(void)
{
  uint32_t bytesread, elapsed_time;
  AUDIO_ErrorTypeDef audio_error = AUDIO_ERROR_NONE;
  static uint32_t prev_elapsed_time = 0xFFFFFFFF;
  uint8_t str[10];  
  
  switch(AudioState)
  {
  case AUDIO_STATE_PLAY:
    if(BufferCtl.fptr >= WaveFormat.FileSize)
    {
      BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
      AudioState = AUDIO_STATE_NEXT;
    }
    
    if(BufferCtl.state == BUFFER_OFFSET_HALF)
    {
      if(f_read(&WavFile, 
                &BufferCtl.buff[0], 
                AUDIO_OUT_BUFFER_SIZE/2, 
                (void *)&bytesread) != FR_OK)
      { 
        BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); 
        return AUDIO_ERROR_IO;       
      } 
      BufferCtl.state = BUFFER_OFFSET_NONE;
      BufferCtl.fptr += bytesread; 
    }
    
    if(BufferCtl.state == BUFFER_OFFSET_FULL)
    {
      if(f_read(&WavFile, 
                &BufferCtl.buff[AUDIO_OUT_BUFFER_SIZE /2], 
                AUDIO_OUT_BUFFER_SIZE/2, 
                (void *)&bytesread) != FR_OK)
      { 
        BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); 
        return AUDIO_ERROR_IO;       
      } 
 
      BufferCtl.state = BUFFER_OFFSET_NONE;
      BufferCtl.fptr += bytesread; 
    }
    
    /* Display elapsed time */
    elapsed_time = BufferCtl.fptr / WaveFormat.ByteRate; 
    if(prev_elapsed_time != elapsed_time)
    {
      prev_elapsed_time = elapsed_time;
      sprintf((char *)str, "[%02d:%02d]", (int)(elapsed_time /60), (int)(elapsed_time%60));
      BSP_LCD_SetTextColor(LCD_COLOR_CYAN); 
      BSP_LCD_DisplayStringAt(263, LINE(8), str, LEFT_MODE);
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 
    }
    break;
    
  case AUDIO_STATE_STOP:
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
    AudioState = AUDIO_STATE_IDLE; 
    audio_error = AUDIO_ERROR_IO;
    break;
    
  case AUDIO_STATE_NEXT:
    if(++FilePos >= AUDIO_GetWavObjectNumber())
    {
      FilePos = 0; 
    }
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
    AUDIO_PLAYER_Start(FilePos);
    break;    
    
  case AUDIO_STATE_PREVIOUS:
    if(--FilePos < 0)
    {
      FilePos = AUDIO_GetWavObjectNumber() - 1; 
    }
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
    AUDIO_PLAYER_Start(FilePos);
    break;   
    
  case AUDIO_STATE_PAUSE:
    BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)"  [PAUSE]", LEFT_MODE);
    BSP_AUDIO_OUT_Pause();
    AudioState = AUDIO_STATE_WAIT;
    break;
    
  case AUDIO_STATE_RESUME:
    BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)"  [PLAY ]", LEFT_MODE);
    BSP_AUDIO_OUT_Resume();
    AudioState = AUDIO_STATE_PLAY;
    break;
    
  case AUDIO_STATE_VOLUME_UP: 
    if( uwVolume <= 90)
    {
      uwVolume += 10;
    }
    BSP_AUDIO_OUT_SetVolume(uwVolume);
    AudioState = AUDIO_STATE_PLAY;
    break;
    
  case AUDIO_STATE_VOLUME_DOWN:    
    if( uwVolume >= 10)
    {
      uwVolume -= 10;
    }
    BSP_AUDIO_OUT_SetVolume(uwVolume);
    AudioState = AUDIO_STATE_PLAY;
    break;
    
  case AUDIO_STATE_WAIT:
  case AUDIO_STATE_IDLE:
  case AUDIO_STATE_INIT:    
  default:
    /* Do Nothing */
    break;
  }
  return audio_error;
}
/**
  * @brief  Displays a maximum of 20 char on the LCD.
  * @param  Line: the Line where to display the character shape .
  * @param  *ptr: pointer to string to display on LCD.
  * @retval None
  */
void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
{
  BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
}
/**
  * @brief  Audio Play demo
  * @param  None
  * @retval None
  */
void AudioPlay_demo (void)
{
  uint8_t ts_status = TS_OK;
  uint32_t *AudioFreq_ptr;
  AudioFreq_ptr = AudioFreq+6; /*AF_48K*/
  uint8_t FreqStr[256] = {0};
  Point Points2[] = {{100, 140}, {160, 180}, {100, 220}};

  uwPauseEnabledStatus = 1; /* 0 when audio is running, 1 when Pause is on */
  uwVolume = AUDIO_DEFAULT_VOLUME;


  if (TouchScreen_IsCalibrationDone() == 0)
  {
    ts_status = Touchscreen_Calibration();
    if(ts_status == TS_OK)
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"Touchscreen calibration success.", CENTER_MODE);
    }
    else
    {
      BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *)"ERROR : touchscreen not yet calibrated.", CENTER_MODE);
      ts_status = TS_ERROR;
    }
  } /* of if (TouchScreen_IsCalibrationDone() == 0) */

  AudioPlay_SetHint();
  BSP_LCD_SetFont(&Font20);


/*  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_SPEAKER, uwVolume, *AudioFreq_ptr) == 0)
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_BOTH, uwVolume, *AudioFreq_ptr) == 0)*/
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_BOTH, uwVolume, *AudioFreq_ptr) == 0)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"  AUDIO CODEC   OK  ", CENTER_MODE);
  }
  else
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"  AUDIO CODEC  FAIL ", CENTER_MODE);
    BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)" Try to reset board ", CENTER_MODE);
  }

  /*
  Start playing the file from a circular buffer, once the DMA is enabled, it is
  always in running state. Application has to fill the buffer with the audio data
  using Transfer complete and/or half transfer complete interrupts callbacks
  (DISCOVERY_AUDIO_TransferComplete_CallBack() or DISCOVERY_AUDIO_HalfTransfer_CallBack()...
  */
  AUDIO_Play_Start((uint32_t *)AUDIO_SRC_FILE_ADDRESS, (uint32_t)AUDIO_FILE_SIZE);

  /* Display the state on the screen */
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"       PLAYING...     ", CENTER_MODE);

  sprintf((char*)FreqStr, "       VOL:    %3lu     ", uwVolume);
  BSP_LCD_DisplayStringAt(0,  LINE(9), (uint8_t *)FreqStr, CENTER_MODE);

  sprintf((char*)FreqStr, "      FREQ: %6lu     ", *AudioFreq_ptr);
  BSP_LCD_DisplayStringAt(0, LINE(10), (uint8_t *)FreqStr, CENTER_MODE);

  BSP_LCD_SetFont(&Font16);
  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 40, (uint8_t *)"Hear nothing ? Have you copied the audio file with STM-LINK UTILITY ?", CENTER_MODE);

  if(ts_status == TS_OK)
  {
    /* Set touchscreen in Interrupt mode and program EXTI accordingly on falling edge of TS_INT pin */
    ts_status = BSP_TS_ITConfig();
    BSP_TEST_APPLI_ASSERT(ts_status != TS_OK);
    Touchscreen_DrawBackground_Circle_Buttons(16);
  }

  BSP_LCD_SetFont(&Font20);

  /* draw play triangle */
  BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  BSP_LCD_FillPolygon(Points2, 3);

/* IMPORTANT:
     AUDIO_Play_Process() is called by the SysTick Handler, as it should be called
     within a periodic process */

  /* Infinite loop */
  while (1)
  {
    BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
    BSP_LCD_SetTextColor(LCD_COLOR_BLUE);

    /* Get the TouchScreen State */
    ts_action = (TS_ActionTypeDef) TouchScreen_GetTouchPosition();

    switch (ts_action)
    {
      case TS_ACT_VOLUME_UP:
        /* Increase volume by 5% */
        if (uwVolume < 95)
          uwVolume += 5;
        else
          uwVolume = 100;
        sprintf((char*)FreqStr, "       VOL:    %3lu     ", uwVolume);
        BSP_AUDIO_OUT_SetVolume(uwVolume);
        BSP_LCD_DisplayStringAt(0, LINE(9), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_VOLUME_DOWN:
        /* Decrease volume by 5% */
        if (uwVolume > 5)
          uwVolume -= 5;
        else
          uwVolume = 0;
        sprintf((char*)FreqStr, "       VOL:    %3lu     ", uwVolume);
        BSP_AUDIO_OUT_SetVolume(uwVolume);
        BSP_LCD_DisplayStringAt(0, LINE(9), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_FREQ_DOWN:
        /*Decrease Frequency */
        if (*AudioFreq_ptr != 8000)
        {
          AudioFreq_ptr--;
          sprintf((char*)FreqStr, "      FREQ: %6lu     ", *AudioFreq_ptr);
          BSP_AUDIO_OUT_Pause();
          BSP_AUDIO_OUT_SetFrequency(*AudioFreq_ptr);
          BSP_AUDIO_OUT_Resume();
          BSP_AUDIO_OUT_SetVolume(uwVolume);
        }
        BSP_LCD_DisplayStringAt(0, LINE(10), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_FREQ_UP:
        /* Increase Frequency */
        if (*AudioFreq_ptr != 96000)
        {
          AudioFreq_ptr++;
          sprintf((char*)FreqStr, "      FREQ: %6lu     ", *AudioFreq_ptr);
          BSP_AUDIO_OUT_Pause();
          BSP_AUDIO_OUT_SetFrequency(*AudioFreq_ptr);
          BSP_AUDIO_OUT_Resume();
          BSP_AUDIO_OUT_SetVolume(uwVolume);
        }

        BSP_LCD_DisplayStringAt(0, LINE(10), (uint8_t *)FreqStr, CENTER_MODE);
        break;
      case TS_ACT_PAUSE:
        /* Set Pause / Resume */
        if (uwPauseEnabledStatus == 1)
        { /* Pause is enabled, call Resume */
          BSP_AUDIO_OUT_Resume();
          uwPauseEnabledStatus = 0;
          BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"       PLAYING...     ", CENTER_MODE);
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
          BSP_LCD_FillPolygon(Points2, 3);
          BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
          BSP_LCD_FillRect(100, 140, 25 , 80);
          BSP_LCD_FillRect(140, 140, 25 , 80);
        }
        else
        { /* Pause the playback */
          BSP_AUDIO_OUT_Pause();
          uwPauseEnabledStatus = 1;
          BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"       PAUSE  ...     ", CENTER_MODE);
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
          BSP_LCD_FillRect(100, 140, 80 , 80);
          BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
          BSP_LCD_FillPolygon(Points2, 3);
        }
        HAL_Delay(200);
        break;

      default:
        break;
    }



    /* Toggle LED4 */
    BSP_LED_Toggle(LED4);

    /* Insert 100 ms delay */
    HAL_Delay(100);
    if (CheckForUserInput() > 0)
    {
      /* Set LED4 */
      BSP_LED_On(LED4);

      BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
      return;
    }
  }
}
bool TeamRobot::main()
{
  {
    SYNC;
    OUTPUT(idProcessBegin, bin, 't');

    DECLARE_DEBUG_DRAWING("representation:RobotPose", "drawingOnField"); // The robot pose
    DECLARE_DEBUG_DRAWING("representation:RobotPose:deviation", "drawingOnField"); // The robot pose
    DECLARE_DEBUG_DRAWING("origin:RobotPose", "drawingOnField"); // Set the origin to the robot's current position
    DECLARE_DEBUG_DRAWING("representation:BallModel", "drawingOnField"); // drawing of the ball model
    DECLARE_DEBUG_DRAWING("representation:CombinedWorldModel", "drawingOnField"); // drawing of the combined world model
    DECLARE_DEBUG_DRAWING("representation:GoalPercept:Field", "drawingOnField"); // drawing of the goal percept
    DECLARE_DEBUG_DRAWING("representation:MotionRequest", "drawingOnField"); // drawing of a request walk vector
    DECLARE_DEBUG_DRAWING("representation:ObstacleModel:Center", "drawingOnField"); //drawing center of obstacle model
    DECLARE_DEBUG_DRAWING("representation:LinePercept:Field", "drawingOnField");

    uint8_t teamColor = 0,
            swapSides = 0;
    MODIFY("teamColor", ownTeamInfo.teamColor);
    MODIFY("swapSides", swapSides);

    if(SystemCall::getTimeSince(robotPoseReceived) < 1000)
      robotPose.draw();
    if(SystemCall::getTimeSince(ballModelReceived) < 1000)
      ballModel.draw();
    if(SystemCall::getTimeSince(combinedWorldModelReceived) < 1000)
      combinedWorldModel.draw();
    if(SystemCall::getTimeSince(goalPerceptReceived) < 1000)
      goalPercept.draw();
    if(SystemCall::getTimeSince(motionRequestReceived) < 1000)
      motionRequest.draw();
    if(SystemCall::getTimeSince(obstacleModelReceived) < 1000)
      obstacleModel.draw();
    if(SystemCall::getTimeSince(linePerceptReceived) < 1000)
      linePercept.draw();

    if(swapSides ^ teamColor)
    {
      ORIGIN("field polygons", 0, 0, pi2); // hack: swap sides!
    }
    fieldDimensions.draw();
    fieldDimensions.drawPolygons(teamColor);

    DECLARE_DEBUG_DRAWING("robotState", "drawingOnField"); // text decribing the state of the robot
    int lineY = 3550;
    DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "batteryLevel: " << robotHealth.batteryLevel << " %");
    DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "role: " << Role::getName(behaviorStatus.role));
    lineY -= 180;
    DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "temperatures: joint " << JointData::getName(robotHealth.jointWithMaxTemperature)<< ":" << robotHealth.maxJointTemperature << " C, cpu: " << robotHealth.cpuTemperature << " C");
    lineY -= 180;
    DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "rates: cognition: " << (int) std::floor(robotHealth.cognitionFrameRate + 0.5f) << " fps, motion: " << (int) std::floor(robotHealth.motionFrameRate + 0.5f) << " fps");
    if(ballModel.timeWhenLastSeen)
    {
      DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "ballLastSeen: " << SystemCall::getRealTimeSince(ballModel.timeWhenLastSeen) << " ms");
    }
    else
    {
      DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "ballLastSeen: never");
    }
    //DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "ballPercept: " << ballModel.lastPerception.position.x << ", " << ballModel.lastPerception.position.y);
    lineY -= 180;
    DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "memory usage: " << robotHealth.memoryUsage << " %");
    if(goalPercept.timeWhenGoalPostLastSeen)
    {
      DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "goalLastSeen: " << SystemCall::getRealTimeSince(goalPercept.timeWhenGoalPostLastSeen) << " ms");
    }
    else
    {
      DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "goalLastSeen: never");
    }

    lineY -= 180;

    DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "load average: " << (float(robotHealth.load[0]) / 10.f) << " " << (float(robotHealth.load[1]) / 10.f) << " " << (float(robotHealth.load[2]) / 10.f));
    DRAWTEXT("robotState", -4100, 0, 150, ColorRGBA(255, 255, 255, 50), robotHealth.robotName);

    DECLARE_DEBUG_DRAWING("robotOffline", "drawingOnField"); // A huge X to display the online/offline state of the robot
    if(SystemCall::getTimeSince(robotPoseReceived) > 500
       || (SystemCall::getTimeSince(isPenalizedReceived) < 1000 && isPenalized)
       || (SystemCall::getTimeSince(hasGroundContactReceived) < 1000 && !hasGroundContact)
       || (SystemCall::getTimeSince(isUprightReceived) < 1000 && !isUpright))
    {
      LINE("robotOffline", -5100, 3600, 5100, -3600, 50, Drawings::ps_solid, ColorRGBA(0xff, 0, 0));
      LINE("robotOffline", 5100, 3600, -5100, -3600, 50, Drawings::ps_solid, ColorRGBA(0xff, 0, 0));
    }
    if(SystemCall::getTimeSince(isPenalizedReceived) < 1000 && isPenalized)
    {
      // Draw a text in red letters to tell that the robot is penalized
      DRAWTEXT("robotState", -2000, 0, 200, ColorRGBA::red, "PENALIZED");
    }
    if(SystemCall::getTimeSince(hasGroundContactReceived) < 1000 && !hasGroundContact)
    {
      // Draw a text in red letters to tell that the robot doesn't have ground contact
      DRAWTEXT("robotState", 300, 0, 200, ColorRGBA::red, "NO GROUND CONTACT");
    }
    if(SystemCall::getTimeSince(isUprightReceived) < 1000 && !isUpright)
    {
      // Draw a text in red letters to tell that the robot is fallen down
      DRAWTEXT("robotState", 300, 0, 200, ColorRGBA::red, "NOT UPRIGHT");
    }

    DEBUG_RESPONSE_ONCE("automated requests:DrawingManager", OUTPUT(idDrawingManager, bin, Global::getDrawingManager()););
    DEBUG_RESPONSE_ONCE("automated requests:DrawingManager3D", OUTPUT(idDrawingManager3D, bin, Global::getDrawingManager3D()););
Exemple #6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;

  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */  

  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  /* Initialize LEDs and LCD available on STM324xG-EVAL board *****************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Initialize the LCD */
  STM324xG_LCD_Init();

  /* Display message on STM324xG-EVAL LCD *************************************/
  /* Clear the LCD */ 
  LCD_Clear(White);

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  LCD_DisplayStringLine(LINE(1), (uint8_t *)MESSAGE2);
  LCD_DisplayStringLine(LINE(2), (uint8_t *)MESSAGE3);

  /* Turn on LEDs available on STM324xG-EVAL **********************************/
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED2);
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOn(LED4);

  /* Add your application code here
     */

  /* Infinite loop */
  while (1)
  {
    /* Toggle LD4 */
    STM_EVAL_LEDToggle(LED4);

    /* Insert 50 ms delay */
    Delay(5);

    /* Toggle LD2 */
    STM_EVAL_LEDToggle(LED2);

    /* Insert 50 ms delay */
    Delay(5);
  }
}
Exemple #7
0
/**
  * @brief  Display Init (LCD or/and USART)
  * @param  None
  * @retval None
  */
static void Display_Init(void)
{
#ifdef PRINT_ON_USART 

 USART_InitTypeDef USART_InitStructure;
  /* USARTx configured as follows:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  STM_EVAL_COMInit(COM1, &USART_InitStructure);

  printf("\n\r ========================================\n");
  printf("\n\r ==== Multiple RNG Generator Example ====\n");
  printf("\n\r ======================================== \n\n\r");
  printf("\n\r  Press key button to generate 8 x 32bit random number\n");
#endif

#ifdef PRINT_ON_LCD  
/* Initialize the LCD */
  LCD_Init();

/* Display message on LCD ***************************************************/
#if defined (USE_STM324x9I_EVAL) 
  /* Initialize the LCD Layers */
  LCD_LayerInit();
  /* Enable The Display */
  LCD_DisplayOn(); 
  /* Set LCD Background Layer  */
  LCD_SetLayer(LCD_BACKGROUND_LAYER);
  /* Clear the Background Layer */ 
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set LCD Foreground Layer  */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);

  /* Configure the transparency for foreground */
  LCD_SetTransparency(100);
#endif /* USE_STM324x9I_EVAL */  
  
  /* Clear the LCD */ 
  LCD_Clear(White);

  /* Set the LCD Text size */
  LCD_SetFont(&FONTSIZE);

  /* Set the LCD Back Color and Text Color*/
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);
  
  LCD_DisplayStringLine(LINE(LINENUM), (uint8_t*)MESSAGE1);
  LCD_DisplayStringLine(LINE(0x16), (uint8_t*)"                                         ");
  
  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);

  LCD_DisplayStringLine(LINE(0), (uint8_t*)MESSAGE2);

  /* Set the LCD Back Color and Text Color*/
  LCD_SetBackColor(White);
  LCD_SetTextColor(Blue); 

  LCD_DisplayStringLine(LINE(3), (uint8_t*)MESSAGE3);
  LCD_DisplayStringLine(LINE(5), (uint8_t*)MESSAGE4);
#endif
}
Exemple #8
0
/**
  * @brief  Manages Audio process. 
  * @param  None
  * @retval Audio error
  */
AUDIO_ErrorTypeDef AUDIO_Process(void)
{
  uint32_t bytesread, elapsed_time; 
  static uint32_t prev_elapsed_time = 0xFFFFFFFF;
  uint8_t str[10];
  AUDIO_ErrorTypeDef error_state = AUDIO_ERROR_NONE;   
  
  switch(audio_state)
  {
  case AUDIO_STATE_PLAY:
    if(buffer_ctl.fptr >= wav_info.FileSize)
    {
      error_state = AUDIO_ERROR_EOF;
    }
    
    if(buffer_ctl.offset == BUFFER_OFFSET_HALF)
    {
      if(MTP_GetData(file_pos, 
                     buffer_ctl.fptr,
                     AUDIO_BUFFER_SIZE /2, 
                     &buffer_ctl.buff[0],
                     &bytesread)> 0)
      { 
        error_state = AUDIO_ERROR_IO;       
      } 
      buffer_ctl.offset = BUFFER_OFFSET_NONE;
      buffer_ctl.fptr += bytesread; 
    }
    
    if(buffer_ctl.offset == BUFFER_OFFSET_FULL)
    {
      if(MTP_GetData(file_pos, 
                     buffer_ctl.fptr,
                     AUDIO_BUFFER_SIZE /2, 
                     &buffer_ctl.buff[AUDIO_BUFFER_SIZE /2],
                     &bytesread)> 0)
      { 
        error_state = AUDIO_ERROR_IO;       
      } 
      buffer_ctl.offset = BUFFER_OFFSET_NONE;
      buffer_ctl.fptr += bytesread; 
    }

    /* Display elapsed time */
    elapsed_time = buffer_ctl.fptr / wav_info.ByteRate; 
    if(prev_elapsed_time != elapsed_time)
    {
      prev_elapsed_time = elapsed_time;
      sprintf((char *)str, "[%02lu:%02lu]", elapsed_time /60, elapsed_time%60);
      BSP_LCD_SetTextColor(LCD_COLOR_CYAN); 
      BSP_LCD_DisplayStringAt(263, LINE(8), str, LEFT_MODE);
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 
    }
    break;
    
  case AUDIO_STATE_STOP:
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
    audio_state = AUDIO_STATE_IDLE; 
    error_state = AUDIO_ERROR_IO;
    break;
    
  case AUDIO_STATE_NEXT:
    if(++file_pos >= MTP_GetWavObjectNumber())
    {
      file_pos = 0; 
    }
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
    AUDIO_Start(file_pos);
    break;    
    
  case AUDIO_STATE_PREVIOUS:
    if(--file_pos < 0)
    {
      file_pos = MTP_GetWavObjectNumber() - 1; 
    }
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
    AUDIO_Start(file_pos);
    break;   
    
  case AUDIO_STATE_PAUSE:
    BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)"  [PAUSE]", LEFT_MODE);
    BSP_AUDIO_OUT_Pause();
    audio_state = AUDIO_STATE_WAIT;
    break;
    
  case AUDIO_STATE_RESUME:
    BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)"  [PLAY ]", LEFT_MODE);
    BSP_AUDIO_OUT_Resume();
    audio_state = AUDIO_STATE_PLAY;
    break;
    
  case AUDIO_STATE_VOLUME_UP: 
    if(uwVolume <= 90)
    {
      uwVolume += 10;
    }
    BSP_AUDIO_OUT_SetVolume(uwVolume);
    audio_state = AUDIO_STATE_PLAY;
    break;
    
  case AUDIO_STATE_VOLUME_DOWN:    
    if(uwVolume >= 10)
    {
      uwVolume -= 10;
    }
    BSP_AUDIO_OUT_SetVolume(uwVolume);
    audio_state = AUDIO_STATE_PLAY;
    break;
    
  case AUDIO_STATE_WAIT:
  case AUDIO_STATE_CONFIG:    
  case AUDIO_STATE_IDLE:
  case AUDIO_STATE_INIT:    
  default:
    /* Do Nothing */
    break;
  }
  return error_state;
}
Exemple #9
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_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  LIS302DL_Reset();

  /* SET USER Key */
  /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */
  EXTILine0_Config();

  /* Initialize the LCD */
  STM32f4_Discovery_LCD_Init();
  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetTextColor(LCD_COLOR_BLUE);

  DCMI_Control_IO_Init();

  LCD_DisplayStringLine(LINE(2), "   Camera Init..");
		   
  /* OV9655 Camera Module configuration */
  if (DCMI_OV9655Config() == 0x00)
  {
    LCD_DisplayStringLine(LINE(2), "                ");
    LCD_SetDisplayWindow(0, 0, 320, 240);
    LCD_WriteRAM_Prepare();

    /* Start Image capture and Display on the LCD *****************************/
    /* Enable DMA transfer */
    DMA_Cmd(DMA2_Stream1, ENABLE);

    /* Enable DCMI interface */
    DCMI_Cmd(ENABLE); 

    /* Start Image capture */ 
    DCMI_CaptureCmd(ENABLE);   

    /*init the picture count*/
    init_picture_count();

    KeyPressFlg = 0;
    while (1)
    {
      /* Insert 100ms delay */
      Delay(100);

      if (KeyPressFlg) {
        KeyPressFlg = 0;
        /* press user KEY take a photo */
        if (capture_Flag == ENABLE) {
          DCMI_CaptureCmd(DISABLE);
          capture_Flag = DISABLE;
          Capture_Image_TO_Bmp();
          LCD_SetDisplayWindow(0, 0, 320, 240);
          LCD_WriteRAM_Prepare();
          DCMI_CaptureCmd(ENABLE);
          capture_Flag = ENABLE;
        }			
      }
    }  
  } else {
    LCD_SetTextColor(LCD_COLOR_RED);

    LCD_DisplayStringLine(LINE(2), "Camera Init.. fails");    
    LCD_DisplayStringLine(LINE(4), "Check the Camera HW ");    
    LCD_DisplayStringLine(LINE(5), "  and try again ");

    /* Go to infinite loop */
    while (1);      
  }
}
Exemple #10
0
void Redbull_Init()
{
  char buff[128] = { 0 };

  USART_STDIO_Init();
  Delay_Init();
  Button_GPIO_Config();

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

  STM3210E_LCD_Init();
  LCD_SetFont(&Font8x12);
  LCD_SetColors(LCD_COLOR_WHITE, LCD_COLOR_BLACK);

  LCD_WriteRAM_Prepare();

  for (int i = 0; i < (320 * 240); i++)
  {
    LCD_WriteRAM(LCD_COLOR_WHITE);
  }
  for (int i = 0; i < (320 * 240); i++)
  {
    LCD_WriteRAM(LCD_COLOR_BLACK);
  }

  LCD_DisplayStringLine(LINE(0), (uint8_t*) " initializing REDBULL");
  LCD_DisplayStringLine(LINE(1), (uint8_t*) " CPU ...............................");
  sprintf(buff, "ARM Cortex-M3 @ %dMHz", (int) SystemCoreClock / 1000000);
  printRight(1, buff);
  LCD_DisplayStringLine(LINE(2), (uint8_t*) " LCD ............................320x240");

  LCD_DisplayStringLine(LINE(3), (uint8_t*) " LED ..................................");

  LED_Init();
  toggleLED(LED1_PIN, 0);
  toggleLED(LED2_PIN, LED1_PIN);
  toggleLED(LED3_PIN, LED2_PIN);
  toggleLED(LED4_PIN, LED3_PIN);
  toggleLED(LED5_PIN, LED4_PIN);
  toggleLED(LED4_PIN, LED5_PIN);
  toggleLED(LED3_PIN, LED4_PIN);
  toggleLED(LED2_PIN, LED3_PIN);
  toggleLED(LED1_PIN, LED2_PIN);
  toggleLED(0, LED1_PIN);

  printRight(3, "5");

  LCD_DisplayStringLine(LINE(4), (uint8_t*) " RTC ................");
  RTC_Init();
  RTC_t rtc = { .year = 2011, .month = 12, .mday = 19, .hour = 21, .min = 00 };
  //RTC_SetTime(&rtc);
  RTC_GetTime(&rtc);
  sprintf(buff, "%04d/%02d/%02d %02d:%02d:%02d", rtc.year, rtc.month, rtc.mday, rtc.hour, rtc.min, rtc.sec);
  printRight(4, buff);

  LCD_DisplayStringLine(LINE(5), (uint8_t*) " USB .................................");
  Set_USBClock();
  Set_System();
  USB_Interrupts_Config();
  USB_Init();
  printRight(5, "ok");

  //IS61LV25616 (512KB)
  LCD_DisplayStringLine(LINE(6), (uint8_t*) " SRAM ................................");
  SRAM_Init();
  uint32_t* RAM = (uint32_t*) Bank1_SRAM3_ADDR;
  uint8_t TESTOK = 1;
  for (uint32_t i = 0; i < (512 * 1024) / 4; i++)
  {
    RAM[i] = i;
  }
  for (uint32_t i = 0; i < (512 * 1024) / 4; i++)
  {
    if (RAM[i] != i)
    {
      TESTOK = 0;
    }
    RAM[i] = 0;
  }

  if (TESTOK)
  {
    printRight(6, "IS61LV25616 512KB");
  }
  else
  {
    printRight(6, "fail");
  }

  //M29W128F (2MB)
  LCD_DisplayStringLine(LINE(7), (uint8_t*) " NOR .................................");
  NOR_Init();
  NOR_IDTypeDef norid;
  NOR_ReadID(&norid);
  printRight(7, "MX29LV160D 2MB");

  //HY27UF081G2A (128MB)
  LCD_DisplayStringLine(LINE(8), (uint8_t*) " NAND ................................");
  NAND_Init();
  NAND_IDTypeDef nandid;
  NAND_ReadID(&nandid);
  printRight(8, "HY27UF081G2A 128MB");

  LCD_DisplayStringLine(LINE(9), (uint8_t*) " SDIO ................................");
  SD_Init();
  SD_CardInfo cardinfo;
  SD_GetCardInfo(&cardinfo);
  printRight(9, "ok");

}
Exemple #11
0
void
vappend(int ch, int cnt, int indent)
{
	int i;
	unsigned char *gcursor;
	bool escape;
	int repcnt, savedoomed;
	short oldhold = hold;
	int savecnt = cnt;
	line *startsrcline;
	int startsrccol, endsrccol;
	int gotNL = 0;
	int imultlinecnt = 0;
	int omultlinecnt = 0;

	if ((savecnt > 1) && (ch == 'o' || ch == 'O')) {
		omultlinecnt = 1;
	}
#ifdef XPG6
	if ((savecnt > 1) && (ch == 'a' || ch == 'A' || ch == 'i' || ch == 'I'))
		imultlinecnt = 1;
#endif /* XPG6 */

	/*
	 * Before a move in hardopen when the line is dirty
	 * or we are in the middle of the printed representation,
	 * we retype the line to the left of the cursor so the
	 * insert looks clean.
	 */

	if (ch != 'o' && state == HARDOPEN && (rubble || !ateopr())) {
		rubble = 1;
		gcursor = cursor;
		i = *gcursor;
		*gcursor = ' ';
		wcursor = gcursor;
		(void) vmove();
		*gcursor = i;
	}
	/*
	 * If vrep() passed indent = 0, this is the 'r' command,
	 * so don't autoindent until the last char.
	 */
	vaifirst = indent == 0;

	/*
	 * Handle replace character by (eventually)
	 * limiting the number of input characters allowed
	 * in the vgetline routine.
	 */
	if (ch == 'r')
		repcnt = 2;
	else
		repcnt = 0;

	/*
	 * If an autoindent is specified, then
	 * generate a mixture of blanks to tabs to implement
	 * it and place the cursor after the indent.
	 * Text read by the vgetline routine will be placed in genbuf,
	 * so the indent is generated there.
	 */
	if (value(vi_AUTOINDENT) && indent != 0) {
		unsigned char x;
		gcursor = genindent(indent);
		*gcursor = 0;
		vgotoCL(nqcolumn(lastchr(linebuf, cursor), genbuf)); 
	} else {
		gcursor = genbuf;
		*gcursor = 0;
		if (ch == 'o')
			vfixcurs();
	}

	/*
	 * Prepare for undo.  Pointers delimit inserted portion of line.
	 */
	vUA1 = vUA2 = cursor;

	/*
	 * If we are not in a repeated command and a ^@ comes in
	 * then this means the previous inserted text.
	 * If there is none or it was too long to be saved,
	 * then beep() and also arrange to undo any damage done
	 * so far (e.g. if we are a change.)
	 */
	switch (ch) {
	case 'r':
		break;
	case 'a':
		/*
		 * TRANSLATION_NOTE
		 *	"A" is a terse mode message corresponding to
		 *	"APPEND MODE".
		 *	Translated message of "A" must be 1 character (not byte).
		 *	Or, just leave it.
		 */
		if (value(vi_TERSE)) {
			vshowmode(gettext("A"));
		} else {
			vshowmode(gettext("APPEND MODE"));
		}
		break;
	case 's':
		/*
		 * TRANSLATION_NOTE
		 *	"S" is a terse mode message corresponding to
		 *	"SUBSTITUTE MODE".
		 *	Translated message of "S" must be 1 character (not byte).
		 *	Or, just leave it.
		 */
		if (value(vi_TERSE)) {
			vshowmode(gettext("S"));
		} else {
			vshowmode(gettext("SUBSTITUTE MODE"));
		}
		break;
	case 'c':
		/*
		 * TRANSLATION_NOTE
		 *	"C" is a terse mode message corresponding to
		 *	"CHANGE MODE".
		 *	Translated message of "C" must be 1 character (not byte).
		 *	Or, just leave it.
		 */
		if (value(vi_TERSE)) {
			vshowmode(gettext("C"));
		} else {
			vshowmode(gettext("CHANGE MODE"));
		}
		break;
	case 'R':
		/*
		 * TRANSLATION_NOTE
		 *	"R" is a terse mode message corresponding to
		 *	"REPLACE MODE".
		 *	Translated message of "R" must be 1 character (not byte).
		 *	Or, just leave it.
		 */
		if (value(vi_TERSE)) {
			vshowmode(gettext("R"));
		} else {
			vshowmode(gettext("REPLACE MODE"));
		}
		break;
	case 'o':
		/*
		 * TRANSLATION_NOTE
		 *	"O" is a terse mode message corresponding to
		 *	"OPEN MODE".
		 *	Translated message of "O" must be 1 character (not byte).
		 *	Or, just leave it.
		 */
		if (value(vi_TERSE)) {
			vshowmode(gettext("O"));
		} else {
			vshowmode(gettext("OPEN MODE"));
		}
		break;
	case 'i':
		/*
		 * TRANSLATION_NOTE
		 *	"I" is a terse mode message corresponding to
		 *	"INSERT MODE" and the following "INPUT MODE".
		 *	Translated message of "I" must be 1 character (not byte).
		 *	Or, just leave it.
		 */
		if (value(vi_TERSE)) {
			vshowmode(gettext("I"));
		} else {
			vshowmode(gettext("INSERT MODE"));
		}
		break;
	default:
		/*
		 * TRANSLATION_NOTE
		 *	"I" is a terse mode message corresponding to
		 *	"INPUT MODE" and the previous "INSERT MODE".
		 *	Translated message of "I" must be 1 character (not byte).
		 *	Or, just leave it.
		 */
		if (value(vi_TERSE)) {
			vshowmode(gettext("I"));
		} else {
			vshowmode(gettext("INPUT MODE"));
		}
	}
	ixlatctl(1);
	if ((vglobp && *vglobp == 0) || peekbr()) {
		if (INS[128] == 0200) {
			(void) beep();
			if (!splitw)
				ungetkey('u');
			doomed = 0;
			hold = oldhold;
			return;
		}
		/*
		 * Unread input from INS.
		 * An escape will be generated at end of string.
		 * Hold off n^^2 type update on dumb terminals.
		 */
		vglobp = INS;
		inscdcnt = INSCDCNT;
		hold |= HOLDQIK;
	} else if (vglobp == 0) {
		/*
		 * Not a repeated command, get
		 * a new inserted text for repeat.
		 */
		INS[0] = 0;
		INS[128] = 0;
		INSCDCNT = 0;
	}

	/*
	 * For wrapmargin to hack away second space after a '.'
	 * when the first space caused a line break we keep
	 * track that this happened in gobblebl, which says
	 * to gobble up a blank silently.
	 */
	gobblebl = 0;

	startsrcline = dot;
	startsrccol = cursor - linebuf;

	/*
	 * Text gathering loop.
	 * New text goes into genbuf starting at gcursor.
	 * cursor preserves place in linebuf where text will eventually go.
	 */
	if (*cursor == 0 || state == CRTOPEN)
		hold |= HOLDROL;
	for (;;) {
		if (ch == 'r' && repcnt == 0)
			escape = 0;
		else {
			ixlatctl(1);
			/*
			 * When vgetline() returns, gcursor is
			 * pointing to '\0' and vgetline() has
			 * read an ESCAPE or NL.
			 */
			gcursor = vgetline(repcnt, gcursor, &escape, ch);
			if (escape == '\n') {
				gotNL = 1;
#ifdef XPG6
				if (ch == 'r') {
					/*
					 * XPG6 assertion 313 [count]r\n :
					 * Arrange to set cursor correctly.
					 */
					endsrccol = gcursor - genbuf - 1;
				}
#endif /* XPG6 */
			} else {
				/*
				 * Upon escape, gcursor is pointing to '\0'
				 * terminating the string in genbuf.
				 */
				endsrccol = gcursor - genbuf - 1;
			}
			ixlatctl(0);

			/*
			 * After an append, stick information
			 * about the ^D's and ^^D's and 0^D's in
			 * the repeated text buffer so repeated
			 * inserts of stuff indented with ^D as backtab's
			 * can work.
			 */
			if (HADUP)
				addtext("^");
			else if (HADZERO)
				addtext("0");
			if(!vglobp)
				INSCDCNT = CDCNT;
			while (CDCNT > 0) {
				addtext("\004");
				CDCNT--;
			}
			if (gobbled)
				addtext(" ");
			addtext(ogcursor);
		}
		repcnt = 0;

		/*
		 * Smash the generated and preexisting indents together
		 * and generate one cleanly made out of tabs and spaces
		 * if we are using autoindent and this isn't 'r' command.
		 */
		if (!vaifirst && value(vi_AUTOINDENT)) {
			i = fixindent(indent);
			if (!HADUP)
				indent = i;
			gcursor = strend(genbuf);
		}

		/*
		 * Set cnt to 1 to avoid repeating the text on the same line.
		 * Do this for commands 'i', 'I', 'a', and 'A', if we're
		 * inserting anything with a newline for XPG6.  Always do this
		 * for commands 'o' and 'O'.
		 */
		if ((imultlinecnt && gotNL) || omultlinecnt) {
			cnt = 1;
		}

		/*
		 * Limit the repetition count based on maximum
		 * possible line length; do output implied
		 * by further count (> 1) and cons up the new line
		 * in linebuf.
		 */
		cnt = vmaxrep(ch, cnt);
		/*
		 * cursor points to linebuf
		 * Copy remaining old text (cursor) in original
		 * line to after new text (gcursor + 1) in genbuf.
		 */
		CP(gcursor + 1, cursor);
		/*
		 * For [count] r \n command, when replacing [count] chars
		 * with '\n', this loop replaces [count] chars with "".
		 */
		do {
			/* cp new text (genbuf) into linebuf (cursor) */
			CP(cursor, genbuf);
			if (cnt > 1) {
				int oldhold = hold;

				Outchar = vinschar;
				hold |= HOLDQIK;
				viprintf("%s", genbuf);
				hold = oldhold;
				Outchar = vputchar;
			}
			/* point cursor after new text in linebuf */
			cursor += gcursor - genbuf;
		} while (--cnt > 0);
		endim();
		vUA2 = cursor;
		/* add the remaining old text after the cursor */
		if (escape != '\n')
			CP(cursor, gcursor + 1);

		/*
		 * If doomed characters remain, clobber them,
		 * and reopen the line to get the display exact.
		 * eg. c$ to change to end of line
		 */
		if (state != HARDOPEN) {
			DEPTH(vcline) = 0;
			savedoomed = doomed;
			if (doomed > 0) {
				int cind = cindent();

				physdc(cind, cind + doomed);
				doomed = 0;
			}
			if(MB_CUR_MAX > 1)
				rewrite = _ON;
			i = vreopen(LINE(vcline), lineDOT(), vcline);
			if(MB_CUR_MAX > 1)
				rewrite = _OFF;
#ifdef TRACE
			if (trace)
				fprintf(trace, "restoring doomed from %d to %d\n", doomed, savedoomed);
#endif
			if (ch == 'R')
				doomed = savedoomed;
		}

		/*
		 * Unless we are continuing on to another line
		 * (got a NL), break out of the for loop (got
		 * an ESCAPE).
		 */
		if (escape != '\n') {
			vshowmode("");
			break;
		}

		/*
		 * Set up for the new line.
		 * First save the current line, then construct a new
		 * first image for the continuation line consisting
		 * of any new autoindent plus the pushed ahead text.
		 */
		killU();
		addtext(gobblebl ? " " : "\n");
		/* save vutmp (for undo state) into temp file */
		vsave();
		cnt = 1;
		if (value(vi_AUTOINDENT)) {
			if (value(vi_LISP))
				indent = lindent(dot + 1);
			else
			     if (!HADUP && vaifirst)
				indent = whitecnt(linebuf);
			vaifirst = 0;
			strcLIN(vpastwh(gcursor + 1));
			gcursor = genindent(indent);
			*gcursor = 0;
			if (gcursor + strlen(linebuf) > &genbuf[LBSIZE - 2])
				gcursor = genbuf;
			CP(gcursor, linebuf);
		} else {
			/*
			 * Put gcursor at start of genbuf to wipe
			 * out previous line in preparation for
			 * the next vgetline() loop.
			 */
			CP(genbuf, gcursor + 1);
			gcursor = genbuf;
		}

		/*
		 * If we started out as a single line operation and are now
		 * turning into a multi-line change, then we had better yank
		 * out dot before it changes so that undo will work
		 * correctly later.
		 */
		if (FIXUNDO && vundkind == VCHNG) {
			vremote(1, yank, 0);
			undap1--;
		}

		/*
		 * Now do the append of the new line in the buffer,
		 * and update the display, ie: append genbuf to
		 * the file after dot.  If slowopen
		 * we don't do very much.
		 */
		vdoappend(genbuf);
		vundkind = VMANYINS;
		vcline++;
		if (state != VISUAL)
			vshow(dot, NOLINE);
		else {
			i += LINE(vcline - 1);
			vopen(dot, i);
			if (value(vi_SLOWOPEN))
				vscrap();
			else
				vsync1(LINE(vcline));
		}
		switch (ch) {
		case 'r':
			break;
		case 'a':
			if (value(vi_TERSE)) {
				vshowmode(gettext("A"));
			} else {
				vshowmode(gettext("APPEND MODE"));
			}
			break;
		case 's':
			if (value(vi_TERSE)) {
				vshowmode(gettext("S"));
			} else {
				vshowmode(gettext("SUBSTITUTE MODE"));
			}
			break;
		case 'c':
			if (value(vi_TERSE)) {
				vshowmode(gettext("C"));
			} else {
				vshowmode(gettext("CHANGE MODE"));
			}
			break;
		case 'R':
			if (value(vi_TERSE)) {
				vshowmode(gettext("R"));
			} else {
				vshowmode(gettext("REPLACE MODE"));
			}
			break;
		case 'i':
			if (value(vi_TERSE)) {
				vshowmode(gettext("I"));
			} else {
				vshowmode(gettext("INSERT MODE"));
			}
			break;
		case 'o':
			if (value(vi_TERSE)) {
				vshowmode(gettext("O"));
			} else {
				vshowmode(gettext("OPEN MODE"));
			}
			break;
		default:
			if (value(vi_TERSE)) {
				vshowmode(gettext("I"));
			} else {
				vshowmode(gettext("INPUT MODE"));
			}
		}
		strcLIN(gcursor);
		/* zero genbuf */
		*gcursor = 0;
		cursor = linebuf;
		vgotoCL(nqcolumn(cursor - 1, genbuf));
	} /* end for (;;) loop in vappend() */

	if (imultlinecnt && gotNL) {
		imultlinerep(savecnt, startsrcline, startsrccol, endsrccol);
	} else if (omultlinecnt) {
		omultlinerep(savecnt, startsrcline, endsrccol);
#ifdef XPG6
	} else if (savecnt > 1 && ch == 'r' && gotNL) {
		/*
		 * XPG6 assertion 313 & 254 : Position cursor for [count]r\n
		 * then insert [count -1] newlines.
		 */
		endsrccol = gcursor - genbuf - 1;
		rmultlinerep(savecnt, endsrccol);
#endif /* XPG6 */
	}

	/*
	 * All done with insertion, position the cursor
	 * and sync the screen.
	 */
	hold = oldhold;
	if ((imultlinecnt && gotNL) || omultlinecnt) {
		fixdisplay();
#ifdef XPG6
	} else if (savecnt > 1 && ch == 'r' && gotNL) {
		fixdisplay();
		/*
		 * XPG6 assertion 313 & 254 [count]r\n : Set flag to call
		 * fixdisplay() after operate() has finished.  To be sure that
		 * the text (after the last \n followed by an indent) is always
		 * displayed, fixdisplay() is called right before getting
		 * the next command.
		 */
		redisplay = 1;
#endif /* XPG6 */
	} else if (cursor > linebuf) {
		cursor = lastchr(linebuf, cursor);
#ifdef XPG6
		/*
		 * XPG6 assertion 313 & 254 [count]r\n :
		 * For 'r' command, when the replacement char causes new
		 * lines to be created, point cursor to first non-blank.
		 * The old code, ie: cursor = lastchr(linebuf, cursor);
		 * set cursor to the blank before the first non-blank
		 * for r\n
		 */
		if (ch == 'r' && gotNL && isblank((int)*cursor))
			++cursor;
#endif /* XPG6 */
	}
	if (state != HARDOPEN)
		vsyncCL();
	else if (cursor > linebuf)
		back1();
	doomed = 0;
	wcursor = cursor;
	(void) vmove();
}
/**
  * @brief  This function handles External line 5 to 9 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI9_5_IRQHandler(void)
{
  uint8_t index = 0;
	uint32_t tmp = 0, tmp1 = 0;
  if((EXTI_GetITStatus(RIGHT_BUTTON_EXTI_LINE) != RESET) )
  {
    /* Set the LCD Back Color */
    LCD_SetBackColor(White);
    StartEvent = 0;
    /* Reset Counter*/
    RTCAlarmCount = 0;
    
    /* Disable the alarm */
    RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
    
    /* Display Char on the LCD : XXX% */
    LCD_DisplayChar(40,110,0x30);
    LCD_DisplayChar(40,88, 0x30);
    LCD_DisplayChar(40,66, 0x30);
    LCD_DisplayChar(40,44, 0x25);
    
    for (index = 0; index < 100 ; index++)
    {
      if ((index % 2) ==0)
      {
        /* Set the LCD Text Color */
        LCD_SetTextColor(Blue);
        LCD_DrawLine(70 + (index/2) , 120 - (index/2)  , 101 - (index + 1) ,Horizontal);
        /* Set the LCD Text Color */
        LCD_SetTextColor(White);
        LCD_DrawLine(170 - (index/2) , 120 - (index/2)  , 101 - (index + 1) ,Horizontal);
        
      }
    } 
    /* Displays MESSAGE6 on line 5 */
    LCD_SetFont(&Font12x12);
    /* Set the LCD Back Color */
    LCD_SetBackColor(Blue);
    LCD_SetTextColor(White);
    LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE6);
    LCD_SetFont(&Font16x24);
    /* Set the LCD Text Color */
    LCD_SetTextColor(Black); 
    
    /* Clear the RIGHT EXTI  pending bit */
    EXTI_ClearITPendingBit(RIGHT_BUTTON_EXTI_LINE);  
  }
    
    
    if(EXTI_GetITStatus(DOWN_BUTTON_EXTI_LINE) != RESET)
  {
    
    if(RTCAlarmCount == 0)
    {
      SecondNumb--;
      if(SecondNumb < 15) SecondNumb = 15; 
      
      tmp = (uint32_t) (SecondNumb/60);
      tmp1 =   SecondNumb -(tmp*60);
      LCD_SetFont(&Font16x24); 
      /* Set the LCD text color */
      LCD_SetTextColor(Blue);
      /* Set the LCD Back Color */
      LCD_SetBackColor(White);
      LCD_DisplayStringLine(95, (uint8_t*) "         ");  
      /* Display Char on the LCD : XXX% */       
      LCD_DisplayChar(95,294, (tmp / 10) +0x30);
      LCD_DisplayChar(95,278, (tmp  % 10 ) +0x30);
      LCD_DisplayChar(95,262, ':');
      LCD_DisplayChar(95,246, (tmp1 / 10) +0x30);
      LCD_DisplayChar(95,230, (tmp1  % 10 ) +0x30);
    }
    
    /* Clear the RIGHT EXTI  pending bit */
    EXTI_ClearITPendingBit(DOWN_BUTTON_EXTI_LINE); 
  }
  
  if (EXTI_GetITStatus(UP_BUTTON_EXTI_LINE) != RESET)
  {
    if(RTCAlarmCount == 0)
    {
      SecondNumb++;
      
      tmp = (uint32_t) (SecondNumb/60);
      tmp1 =   SecondNumb -(tmp*60);
      
      LCD_SetFont(&Font16x24);
      /* Set the LCD text color */
      LCD_SetTextColor(Blue);
      /* Set the LCD Back Color */
      LCD_SetBackColor(White);
      LCD_DisplayStringLine(95, (uint8_t*) "         "); 
      /* Display Char on the LCD : XXX% */       
      LCD_DisplayChar(95,294, (tmp / 10) +0x30);
      LCD_DisplayChar(95,278, (tmp  % 10 ) +0x30);
      LCD_DisplayChar(95,262, ':');
      LCD_DisplayChar(95,246, (tmp1 / 10) +0x30);
      LCD_DisplayChar(95,230, (tmp1  % 10 ) +0x30);
      
    }
    /* Clear the EXTI Line 11 */
    EXTI_ClearITPendingBit(UP_BUTTON_EXTI_LINE);
  }
}
Exemple #13
0
/*
 * Insert character c at current cursor position.
 * Multi-character inserts occur only as a result
 * of expansion of tabs (i.e. inssize == 1 except
 * for tabs) and code assumes this in several place
 * to make life simpler.
 */
int
vinschar(int c)
/*	int c;		/\* mjm: char --> int */
{
	register int i;
	register cell *tp;
	char	*OIM;
	bool	OXN;
	int	noim, filler = 0;

	insmc1 = colsc(c) - 1;
	if ((!IM || !EI) && ((hold & HOLDQIK) || !value(REDRAW) || value(SLOWOPEN))) {
		/*
		 * Don't want to try to use terminal
		 * insert mode, or to try to fake it.
		 * Just put the character out; the screen
		 * will probably be wrong but we will fix it later.
		 */
		if (c == '\t') {
			vgotab();
			return c;
		}
		vputchar(c);
#ifdef	MB
		if (insmc1 == 0 && (vtube0[destcol]&(TRIM|MULTICOL))==MULTICOL)
			vtube0[destcol] = INVBIT;
#endif	/* MB */
		if (DEPTH(vcline) * WCOLS + !value(REDRAW) >
		    (destline - LINE(vcline)) * WCOLS + destcol)
			return c;
		/*
		 * The next line is about to be clobbered
		 * make space for another segment of this line
		 * (on an intelligent terminal) or just remember
		 * that next line was clobbered (on a dumb one
		 * if we don't care to redraw the tail.
		 */
		if (AL) {
			vnpins(0);
		} else {
			c = LINE(vcline) + DEPTH(vcline);
			if (c < LINE(vcline + 1) || c > WBOT)
				return c;
			i = destcol;
			vinslin(c, 1, vcline);
			DEPTH(vcline)++;
			vigoto(c, i);
			vprepins();
		}
		return c;
	}
	/*
	 * Compute the number of positions in the line image of the
	 * current line.  This is done from the physical image
	 * since that is faster.  Note that we have no memory
	 * from insertion to insertion so that routines which use
	 * us don't have to worry about moving the cursor around.
	 */
	if (*vtube0 == 0)
		linend = 0;
	else {
		/*
		 * Search backwards for a non-null character
		 * from the end of the displayed line.
		 */
		i = WCOLS * DEPTH(vcline);
		if (i == 0)
			i = WCOLS;
		tp = vtube0 + i;
		while (*--tp == 0)
			if (--i == 0)
				break;
		linend = i + insmc1;
	}

	/*
	 * We insert at a position based on the physical location
	 * of the output cursor.
	 */
	inscol = destcol + (destline - LINE(vcline)) * WCOLS;
	insmc0 = 0;
#ifdef	MB
	i = 0;
	while (inscol+i < LBSIZE && vtube0[inscol+i]&MULTICOL &&
			(vtube0[inscol+insmc0+i]&(MULTICOL|TRIM)) != MULTICOL)
		i++;
	while (inscol+insmc0+i < LBSIZE &&
			(vtube0[inscol+insmc0+i]&(MULTICOL|TRIM)) == MULTICOL)
		insmc0++;
#endif	/* MB */
	if (c == '\t') {
		/*
		 * Characters inserted from a tab must be
		 * remembered as being part of a tab, but we can't
		 * use QUOTE here since we really need to print blanks.
		 * QUOTE|' ' is the representation of this.
		 */
		inssiz = tabcol(inscol+insmc0, value(TABSTOP)) - inscol - insmc0;
		c = ' ' | QUOTE;
	} else
		inssiz = 1;

	/*
	 * If the text to be inserted is less than the number
	 * of doomed positions, then we don't need insert mode,
	 * rather we can just typeover.
	 */
	if (inssiz + insmc1 <= doomed) {
		endim();
		if (inscol + insmc0 != linend)
			doomed -= inssiz + insmc1;
#ifdef	MB
		if (insmc1 == 0 && c != '\t' &&
				vtube0[inscol+insmc0] & MULTICOL)
			vtube0[inscol+insmc0] = INVBIT;
#endif	/* MB */
		do
			vputchar(c);
		while (--inssiz);
		return c;
	}

	/*
	 * Have to really do some insertion, thus
	 * stake out the bounds of the first following
	 * group of tabs, computing starting position,
	 * ending position, and the number of ``spaces'' therein
	 * so we can tell how much it will squish.
	 */
	tp = vtube0 + inscol + insmc0;
	for (i = inscol + insmc0; i < linend; i++) {
		if (*tp++ & QUOTE) {
			--tp;
			break;
		}
	}
	tabstart = tabend = i;
	tabslack = 0;
	while (tabend < linend) {
		i = *tp++;
		if ((i & QUOTE) == 0)
			break;
		if ((i & (TRIM|MULTICOL)) == 0)
			tabslack++;
		tabsize++;
		tabend++;
	}
	tabsize = tabend - tabstart;

	/*
	 * For HP's and DM's, e.g. tabslack has no meaning.
	 */
	if (!IN)
		tabslack = 0;
#ifdef IDEBUG
	if (trace) {
		fprintf(trace, "inscol %d, inssiz %d, tabstart %d, ",
			inscol, inssiz, tabstart);
		fprintf(trace, "tabend %d, tabslack %d, linend %d\n",
			tabend, tabslack, linend);
	}
#endif
	OIM = IM;
	OXN = XN;
	noim = 0;
#ifdef	MB
	if (mb_cur_max > 1) {
		if (destcol + 1 + insmc1 == WCOLS + 1) {
			noim = 1;
			if (insmc1 == 1 && insmc0 == 0)
				filler = 1;
		}
		for (i = inscol; vtube0[i]; i++)
			if (i + 1 >= WCOLS && vtube0[i] & MULTICOL) {
				noim = 1;
				break;
			}
	}
#endif	/* MB */
	if (noim) {
		endim();
		IM = 0;
		XN = 0;
	}

	/*
	 * The real work begins.
	 */
	slakused = 0;
	shft = 0;
	if (tabsize) {
		/*
		 * There are tabs on this line.
		 * If they need to expand, then the rest of the line
		 * will have to be shifted over.  In this case,
		 * we will need to make sure there are no ``spaces''
		 * in the rest of the line (on e.g. CONCEPT-100)
		 * and then grab another segment on the screen if this
		 * line is now deeper.  We then do the shift
		 * implied by the insertion.
		 */
		if (inssiz >= doomed + tabcol(tabstart, value(TABSTOP)) - tabstart) {
			if (IN)
				vrigid();
			vneedpos(value(TABSTOP));
			vishft();
		}
	} else if (inssiz + insmc1 > doomed)
		/*
		 * No tabs, but line may still get deeper.
		 */
		vneedpos(inssiz + insmc1 - doomed);
	/*
	 * Now put in the inserted characters.
	 */
	viin(c);

	/*
	 * Now put the cursor in its final resting place.
	 */
	destline = LINE(vcline);
	destcol = inscol + inssiz + insmc1 + filler;
	vcsync();
	if (IM != OIM) {
		IM = OIM;
		XN = OXN;
	}
	return c;
}
Exemple #14
0
/*
 * Delete display positions stcol through endcol.
 * Amount of use of special terminal features here is limited.
 */
void
physdc(int stcol, int endcol)
{
	register cell *tp, *up;
	cell *tpe = NULL;
	register int i;
	register int nc = endcol - stcol;

#ifdef IDEBUG
	if (trace)
		tfixnl(), fprintf(trace, "physdc(%d, %d)\n", stcol, endcol);
#endif
	if (!DC || nc <= 0)
		return;
	if (IN) {
		/*
		 * CONCEPT-100 like terminal.
		 * If there are any ``spaces'' in the material to be
		 * deleted, then this is too hard, just retype.
		 */
		vprepins();
		up = vtube0 + stcol;
		i = nc;
		do {
			if ((*up++ & (QUOTE|TRIM)) == QUOTE)
				return;
		} while (--i);
		i = 2 * nc;
		do {
			if (*up == 0 || (*up++ & QUOTE) == QUOTE)
				return;
		} while (--i);
		vgotoCL(stcol);
	} else {
		/*
		 * HP like delete mode.
		 * Compute how much text we are moving over by deleting.
		 * If it appears to be faster to just retype
		 * the line, do nothing and that will be done later.
		 * We are assuming 2 output characters per deleted
		 * characters and that clear to end of line is available.
		 */
		i = stcol / WCOLS;
		if (i != endcol / WCOLS)
			return;
		i += LINE(vcline);
		stcol %= WCOLS;
		endcol %= WCOLS;
		up = vtube[i]; tp = up + endcol; tpe = up + WCOLS;
		while (tp < tpe && *tp)
			tp++;
		if (tp - (up + stcol) < 2 * nc)
			return;
		vgoto(i, stcol);
	}

	/*
	 * Go into delete mode and do the actual delete.
	 * Padding is on DC itself.
	 */
	godm();
	for (i = nc; i > 0; i--)
		vputp(DC, DEPTH(vcline));
	vputp(ED, 0);

	/*
	 * Straighten up.
	 * With CONCEPT like terminals, characters are pulled left
	 * from first following null.  HP like terminals shift rest of
	 * this (single physical) line rigidly.
	 */
	if (IN) {
		up = vtube0 + stcol;
		tp = vtube0 + endcol;
		while (i = *tp++) {
			if ((i & (QUOTE|TRIM)) == QUOTE)
				break;
			*up++ = i;
		}
		do
			*up++ = i;
		while (--nc);
	} else {
		copy(up + stcol, up + endcol,
				(WCOLS - endcol) * sizeof *up);
		vclrcell(tpe - nc, nc);
	}
}
Exemple #15
0
void OptionsList::Load( RString sType, PlayerNumber pn )
{
	TOP_MENU.Load( sType, "TopMenu" );

	m_pn = pn;
	m_bStartIsDown = false;

	m_Codes.Load( sType );

	m_Cursor.Load( THEME->GetPathG(sType, "cursor") );
	m_Cursor->SetName( "Cursor" );
	ActorUtil::LoadAllCommands( *m_Cursor, sType );
	this->AddChild( m_Cursor );

	vector<RString> asDirectLines;
	split( DIRECT_LINES, ",", asDirectLines, true );
	FOREACH( RString, asDirectLines, s )
		m_setDirectRows.insert( *s );

	vector<RString> setToLoad;
	split( TOP_MENUS, ",", setToLoad );
	m_setTopMenus.insert( setToLoad.begin(), setToLoad.end() );

	while( !setToLoad.empty() )
	{
		RString sLineName = *setToLoad.begin();
		setToLoad.erase( setToLoad.begin() );

		if( m_Rows.find(sLineName) != m_Rows.end() )
			continue;

		RString sRowCommands = LINE(sLineName);
		Commands cmds;
		ParseCommands( sRowCommands, cmds, false );

		OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds );
		if( pHand == NULL )
		{
			LuaHelpers::ReportScriptErrorFmt("Invalid OptionRowHandler '%s' in %s::Line%s", cmds.GetOriginalCommandString().c_str(), m_sName.c_str(), sLineName.c_str());
			continue;
		}

		m_Rows[sLineName] = pHand;
		m_asLoadedRows.push_back( sLineName );

		for( size_t i = 0; i < pHand->m_Def.m_vsChoices.size(); ++i )
		{
			RString sScreen = pHand->GetScreen(i);
			if( !sScreen.empty() )
				setToLoad.push_back( sScreen );
		}
	}

	for( int i = 0; i < 2; ++i )
	{
		m_Row[i].SetName( "OptionsList" );
		m_Row[i].Load( this, "OptionsList" );
		ActorUtil::LoadAllCommands( m_Row[i], sType );
		this->AddChild( &m_Row[i] );
	}

	this->PlayCommand( "TweenOff" );
	this->FinishTweening();
}
/**
  * @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_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 

  RTC_TimeTypeDef  RTC_TimeStruct;   
  RTC_TimeTypeDef  RTC_TimeStructureInit;
  RTC_TimeTypeDef  RTC_StampTimeStruct;
  
  /* Configure the external interrupt "RIGHT" and "LEFT" buttons */
  STM_EVAL_PBInit(BUTTON_RIGHT,BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_LEFT,BUTTON_MODE_EXTI);
  
  /* Configure the RTC peripheral by selecting the clock source.*/
  RTC_Config();
  
  /* LCD Display init  */
  Display_Init();
  
  /* Configure the RTC tamper register : To Clear all the Backup data register */
  RTC_TamperConfig();

  /* Initialize time Stucture */
  RTC_TimeStructInit(&RTC_TimeStruct); 

  /* Infinite loop */
  while (1)
  {
    /* Set the LCD Back Color and text size */
    LCD_SetFont(&Font16x24);
    LCD_SetBackColor(White);
    
    /* Check on the event 'start' */
    if(StartEvent != 0x0)
    {  
      /* Get the RTC sub second fraction */
      SecondFraction = (((256 - (uint32_t)RTC_GetSubSecond()) * 1000) / 256);
      
      /* Get the Curent time */
      RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
      
      /* Refresh : Display the curent time and the sub second on the LCD  */
      RTC_Time_Display(37, Black , RTC_Get_Time(SecondFraction , &RTC_TimeStruct));
    }
    else
    {
      /* Re-initialize the Display time on the LCD */
      RTC_Time_InitDisplay();
    }  
    
    /* Left button is pressed */
      if (Button_State == LEFT_ON)
      {
        /* Enable Tamper interrupt */
      RTC_ITConfig(RTC_IT_TAMP, ENABLE);
      /* Enabale the tamper 1 */
      RTC_TamperCmd(RTC_Tamper_1 , ENABLE);
      
      /* Set the LCD Back Color */
      LCD_SetBackColor(White);
      
      /* Clear the LCD line 5 */
      LCD_ClearLine(Line5);
      
      /* Get the current time */
      RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructureInit);
      CurrentTimeSec = (RTC_TimeStructureInit.RTC_Hours * 3600) + (RTC_TimeStructureInit.RTC_Minutes * 60) +
        RTC_TimeStructureInit.RTC_Seconds;     
      
      /* start count */
      StartEvent = 0x1;
      /* Reinitialize Button_State variable */
      Button_State = 0; 
      }
    /* Right button is pressed */
      else if (Button_State == RIGHT_ON)
      {
        uint16_t Colorx;
      
      if (BackupIndex < 5)
      {
        if((uint8_t)(BackupIndex% 2) != 0x0)
        { 
          /* Set LCD backcolor*/
          LCD_SetBackColor(Blue2);
          Colorx = White;
        }
        else
        {
          /* Set LCD backcolor*/
          LCD_SetBackColor(Cyan);
          Colorx = Black;
        }
        SubSecFrac = 0;
        /* Get the Current sub second and time */
        SubSecFrac = (((256 - (uint32_t)RTC_GetSubSecond()) * 1000) / 256);
        
        RTC_GetTime(RTC_Format_BIN, &RTC_StampTimeStruct);
        
        LCD_SetFont(&Font16x24);
        /* Display result on the LCD */
        RTC_Time_Display( LINE(3 + BackupIndex), Colorx, RTC_Get_Time(SubSecFrac , &RTC_StampTimeStruct) ); 
        
        if (BackupIndex < 2)
        {
          /* Save time register  to Backup register ( the first 5 register is reserved for time) */
          RTC_WriteBackupRegister(BKPDataReg[BackupIndex],(uint32_t)RTC->TR);
        
          /* Save sub second time stamp register ( the latest 6 register is reserved for time) */
          RTC_WriteBackupRegister(BKPDataReg[BackupIndex + 2], SubSecFrac);
        }
        
      }
      else
      {
        /* the backup register is full with 10trials */
        /* Set the LCD Back Color */
        LCD_SetBackColor(White);
        LCD_SetFont(&Font12x12);
        /* Set the LCD Text Color */
        LCD_SetTextColor(Red); 
        LCD_DisplayStringLine(LINE(16), (uint8_t *)MESSAGE4);
        LCD_DisplayStringLine(LINE(17), (uint8_t *)MESSAGE5);
        
      }  
      BackupIndex++;
      /* Set the LCD Back Color */
      LCD_SetBackColor(White);  
      /* Reinitialize Button_State variable */
      Button_State = 0; 
      }
   
   /* TAMPER button is pressed */
   else if (Button_RTC == RTC_TAMP)
   {
     /* Set the LCD Back Color */
    LCD_SetBackColor(White);
    LCD_SetFont(&Font16x24);
    /* Clear LCD line 5 to 9 */
    for (i=0; i < 5; i++)
    {  
      /* Clear all the LCD lignes from 3 to 7 */
      LCD_ClearLine(LINE(3+i));
    }
    
    /* reset Counter */
    BackupIndex = 0 ;
    
    /* Enetr to idle */
    StartEvent =0x0;
    
    LCD_SetFont(&Font12x12);
    RTC_Time_InitDisplay();
    
    LCD_SetFont(&Font12x12);
    LCD_ClearLine(LINE(16));
    LCD_ClearLine(LINE(17));
    
    /* Enable Tamper interrupt */
    RTC_ITConfig(RTC_IT_TAMP, DISABLE);
    /* Enabale the tamper 1 */
    RTC_TamperCmd(RTC_Tamper_1 , DISABLE);
    /* Reinitialize Button_RTC variable */
    Button_RTC = 0; 
   }
  }
}
Exemple #17
0
int main(void){
	
	//configure push-button interrupts
	PB_Config();
	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);

	
	
	//======You need to develop the following functions======
	//Note: these are just placeholders; function definitions are at bottom of this file
	//configure real-time clock
	RTC_Config();
	
	//configure external push-buttons and interrupts
	ExtPB_Config();
	ExtPBNum2();
	
	
	//main program
	
	LCD_Clear(LCD_COLOR_WHITE);
		
	//line=0;
	//Display a string in one line, on the first line (line=0)
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Init EEPROM...");
	//line++;
	
	//i2c_init(); //initialize the i2c chip
	sEE_Init();  

	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "done..."); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Writing...");
	//line++;
	
	
	/* First write in the memory followed by a read of the written data --------*/
  /* Write on I2C EEPROM from memLocation */
  //sEE_WriteBuffer(&Tx1_Buffer, memLocation,1); 

  /* Wait for EEPROM standby state */
  //sEE_WaitEepromStandbyState();  
 
  
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Reading...");
  /* Read from I2C EEPROM from memLocation */
  //sEE_ReadBuffer(&Rx1_Buffer, memLocation, (uint16_t *)(&NumDataRead)); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Comparing...");  
	//line++;
	
	
	//if(Tx1_Buffer== Rx1_Buffer){
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Success!");  
	//}else{
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Mismatch!"); 
	//}
	
	//main loop
	while(1){
		RTC_GetTime(RTC_Format_BIN,&RTC_TimeStructure);
		hours = RTC_TimeStructure.RTC_Hours;
		minutes = RTC_TimeStructure.RTC_Minutes;
		seconds = RTC_TimeStructure.RTC_Seconds;

		sprintf(time,"%0.2d:%0.2d:%0.2d",hours,minutes,seconds);
		LCD_DisplayStringLine(LINE(6),  (uint8_t *) time); 
		
		if(UBPressed == 1){
			
			toBeSaved = time[7];
			sEE_WriteBuffer(&toBeSaved, memLocation+1,1); 
			sEE_WaitEepromStandbyState();  
			
			sEE_ReadBuffer(&Rx1_Buffer, memLocation+1, (uint16_t *)(&NumDataRead)); 
			saved[0] = Rx1_Buffer;

			
			
			LCD_DisplayStringLine(LINE(7),  (uint8_t *) saved);
			
			UBPressed = 0;
			PB_Config();
			
		}
		if(EB1Pressed == 1 && state == 0){
			state = 1;
			EB1Pressed = 0;
			ExtPB_Config();
		}
		if(EB1Pressed == 1 && state == 1){
			state = 2;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 2){
			state = 3;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 3){
			state = 0;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB2Pressed == 1 && state == 1){
			
			RTC_TimeStructure.RTC_Hours = hours + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 2){
			
			RTC_TimeStructure.RTC_Minutes = minutes + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 3){
			
			RTC_TimeStructure.RTC_Seconds = seconds + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		
	}
}
	//================================================================================
	//!	メソッド名	CENEMY_SHADOG::opeRun
	//
	//	機能		走行時操作
	//	更新		2009/01/19		<新規>
	//================================================================================
	void
	CENEMY_SHADOG::opeRun(void)
	{
	//	重力効果
		this->opeEffectGravity();
	//	足音
		this->soundStep();

	//	移動する値を確保
		float	moveValue	= this->fWallSpace + this->getMoveQuantity() + 100.0f;

	//	行動範囲から出ようとしたら待機
		if(	!this->actionArea.intersect(
				this->calcNextLoc(moveValue, &LINE(eUD_NO, eLR_NO, ADVENT_FRONTHIT))))
		{
		//	方向転換
			switch(this->way)
			{
				case eADCW_LEFT:	this->way = eADCW_RIGHT_TURN;	break;
				case eADCW_RIGHT:	this->way = eADCW_LEFT_TURN;	break;
			}
			this->changeAction(eESHADOGA_WAIT);
			return;
		}

		else
	//	突進し、壁に当たったら待機
		if(	this->stageG->intersect(this, ADVENT_FRONTHIT, moveValue))
		{
		//	方向転換
			switch(this->way)
			{
				case eADCW_LEFT:	this->way = eADCW_RIGHT_TURN;	break;
				case eADCW_RIGHT:	this->way = eADCW_LEFT_TURN;	break;
			}
			this->changeAction(eESHADOGA_WAIT);
			return;
		}
		else
	//	プレイヤーに当たったら、ダメージ
		if(	(*this->player)->intersect(this, ADVENT_FRONTHIT, this->getMoveQuantity()))
		{
			(*this->player)->reactionMessage(eREAMSG_ENEMY_ATTACK_LV1);
		}

	//	ここまで来たら、移動
		ADVENT_FRONTMOVE;

	//	フレームが一定まで上がったら待機
		this->iFrameCnt++;
		if(	this->iFrameCnt > 1000)
		{
			this->changeAction(eESHADOGA_WAIT);
		}

	//	プレイヤーが近かったら、ジャンプ
	//	半径を広げる
		if(	(*this->player)->intersectRadius(this, 1000.0f))
		{
			this->changeAction(eESHADOGA_JUMP);
		}
	}
Exemple #19
0
/**
  * @brief  Manages Audio process.
  * @param  None
  * @retval Audio error
  */
AUDIO_ErrorTypeDef AUDIO_PLAYER_Process(void)
{
    uint32_t bytesread, elapsed_time;
    AUDIO_ErrorTypeDef audio_error = AUDIO_ERROR_NONE;
    static uint32_t prev_elapsed_time = 0xFFFFFFFF;
    uint8_t str[10];

    switch(AudioState)
    {
    case AUDIO_STATE_PLAY:
        if(BufferCtl.fptr >= WaveFormat.FileSize)
        {
            BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
            AudioState = AUDIO_STATE_NEXT;
        }

        if(BufferCtl.state == BUFFER_OFFSET_HALF)
        {
            if(f_read(&WavFile,
                      &BufferCtl.buff[0],
                      AUDIO_OUT_BUFFER_SIZE/2,
                      (void *)&bytesread) != FR_OK)
            {
                BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
                return AUDIO_ERROR_IO;
            }
            BufferCtl.state = BUFFER_OFFSET_NONE;
            BufferCtl.fptr += bytesread;
        }

        if(BufferCtl.state == BUFFER_OFFSET_FULL)
        {
            if(f_read(&WavFile,
                      &BufferCtl.buff[AUDIO_OUT_BUFFER_SIZE /2],
                      AUDIO_OUT_BUFFER_SIZE/2,
                      (void *)&bytesread) != FR_OK)
            {
                BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
                return AUDIO_ERROR_IO;
            }

            BufferCtl.state = BUFFER_OFFSET_NONE;
            BufferCtl.fptr += bytesread;
        }

        /* Display elapsed time */
        elapsed_time = BufferCtl.fptr / WaveFormat.ByteRate;
        if(prev_elapsed_time != elapsed_time)
        {
            prev_elapsed_time = elapsed_time;
            sprintf((char *)str, "[%02d:%02d]", (int)(elapsed_time /60), (int)(elapsed_time%60));
            BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
            BSP_LCD_DisplayStringAt(263, LINE(8), str, LEFT_MODE);
            BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        }

        /* Update audio state machine according to touch acquisition */
        AUDIO_AcquireTouchButtons();
        break;

    case AUDIO_STATE_STOP:
        BSP_LCD_SetTextColor(LCD_COLOR_RED);
        BSP_LCD_FillRect(TOUCH_STOP_XMIN, TOUCH_STOP_YMIN , /* Stop rectangle */
                         TOUCH_STOP_XMAX - TOUCH_STOP_XMIN,
                         TOUCH_STOP_YMAX - TOUCH_STOP_YMIN);
        BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
        AudioState = AUDIO_STATE_IDLE;
        audio_error = AUDIO_ERROR_IO;
        break;

    case AUDIO_STATE_NEXT:
        if(++FilePos >= AUDIO_GetWavObjectNumber())
        {
            FilePos = 0;
        }
        BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
        AUDIO_PLAYER_Start(FilePos);
        break;

    case AUDIO_STATE_PREVIOUS:
        if(--FilePos < 0)
        {
            FilePos = AUDIO_GetWavObjectNumber() - 1;
        }
        BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
        AUDIO_PLAYER_Start(FilePos);
        break;

    case AUDIO_STATE_PAUSE:
        BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
        BSP_LCD_DisplayStringAt(250, LINE(9), (uint8_t *)"  [PAUSE]", LEFT_MODE);
        BSP_LCD_SetTextColor(LCD_COLOR_RED);    /* Display red pause rectangles */
        BSP_LCD_FillRect(TOUCH_PAUSE_XMIN, TOUCH_PAUSE_YMIN , 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);
        BSP_LCD_FillRect(TOUCH_PAUSE_XMIN + 20, TOUCH_PAUSE_YMIN, 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);
        BSP_AUDIO_OUT_Pause();
        AudioState = AUDIO_STATE_WAIT;
        break;

    case AUDIO_STATE_RESUME:
        BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
        BSP_LCD_DisplayStringAt(250, LINE(9), (uint8_t *)"  [PLAY ]", LEFT_MODE);
        /* Display blue cyan pause rectangles */
        BSP_LCD_FillRect(TOUCH_PAUSE_XMIN, TOUCH_PAUSE_YMIN , 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);
        BSP_LCD_FillRect(TOUCH_PAUSE_XMIN + 20, TOUCH_PAUSE_YMIN, 15, TOUCH_PAUSE_YMAX - TOUCH_PAUSE_YMIN);
        BSP_AUDIO_OUT_Resume();
        AudioState = AUDIO_STATE_PLAY;
        break;

    case AUDIO_STATE_VOLUME_UP:
        if( uwVolume <= 90)
        {
            uwVolume += 10;
        }
        BSP_AUDIO_OUT_SetVolume(uwVolume);
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        sprintf((char *)str,  "Volume : %lu ", uwVolume);
        BSP_LCD_DisplayStringAtLine(9, str);
        AudioState = AUDIO_STATE_PLAY;
        break;

    case AUDIO_STATE_VOLUME_DOWN:
        if( uwVolume >= 10)
        {
            uwVolume -= 10;
        }
        BSP_AUDIO_OUT_SetVolume(uwVolume);
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        sprintf((char *)str,  "Volume : %lu ", uwVolume);
        BSP_LCD_DisplayStringAtLine(9, str);
        AudioState = AUDIO_STATE_PLAY;
        break;

    case AUDIO_STATE_WAIT:
    case AUDIO_STATE_IDLE:
    case AUDIO_STATE_INIT:
    default:
        /* Update audio state machine according to touch acquisition */
        AUDIO_AcquireTouchButtons();
        break;
    }
    return audio_error;
}
/**
  * @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_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */
  
  /* Initialize the LCD */
  STM32072B_LCD_Init();      
  
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
    
  LCD_SetFont(&Font12x12);
  
  /* Display Messages on the the LCD */  
  LCD_DisplayStringLine(LINE(0x3), (uint8_t *)MESSAGE2);
  
  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);
  
  /* Configure Push button key */
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); 
     
  /* CAN configuration */
  CAN_Config();
  
  /* Infinite loop */
  while(1)
  {
    while(STM_EVAL_PBGetState(BUTTON_TAMPER) == TAMPER_PRESSED)
    { 
      if(KeyNumber == 41) KeyNumber = 0;
      
      Display_TransmittedMsg(KeyNumber);
      
      KeyNumber++;
      
      Delay();
      
      while(STM_EVAL_PBGetState(BUTTON_TAMPER) != TAMPER_NOT_PRESSED)
      {
      }
    }
      if (MsgReceived != 0)
        {
            /* Display received the 6 messages on tghe LCD */
            Display_ReceivedMsg();
            MsgReceived = 0;
     
        }
  }
}
Exemple #21
0
void ClassicCostumeRenderer::procC64(Codec1 &v1, int actor) {
	const byte *mask, *src;
	byte *dst;
	byte len;
	int y;
	uint height;
	byte color, pcolor;
	bool rep;

	y = v1.y;
	src = _srcptr;
	dst = v1.destptr;
	len = v1.replen;
	color = v1.repcolor;
	height = _height;

	v1.skip_width /= 8;

	// Set up the palette data
	byte palette[4] = { 0, 0, 0, 0 };
	if (_vm->getCurrentLights() & LIGHTMODE_actor_use_colors) {
		if (_vm->_game.id == GID_MANIAC) {
			palette[1] = v1MMActorPalatte1[actor];
			palette[2] = v1MMActorPalatte2[actor];
		} else {
			// Adjust for C64 version of Zak McKracken
			palette[1] = (_vm->_game.platform == Common::kPlatformC64) ? 10 : 8;
			palette[2] = _palette[actor];
		}
	} else {
		palette[2] = 11;
		palette[3] = 11;
	}
	mask = v1.mask_ptr;

	if (len)
		goto StartPos;

	do {
		len = *src++;
		if (len & 0x80)
			color = *src++;
	StartPos:;
		rep = (len & 0x80) != 0;
		len &= 0x7f;
		while (len--) {
			if (!rep)
				color = *src++;

			if (0 <= y && y < _out.h && 0 <= v1.x && v1.x < _out.w) {
				if (!_mirror) {
					LINE(0, 0); LINE(2, 2); LINE(4, 4); LINE(6, 6);
				} else {
					LINE(6, 0); LINE(4, 2); LINE(2, 4); LINE(0, 6);
				}
			}
			dst += _out.pitch;
			y++;
			mask += _numStrips;
			if (!--height) {
				if (!--v1.skip_width)
					return;
				height = _height;
				y = v1.y;
				v1.x += 8 * v1.scaleXstep;
				if (v1.x < 0 || v1.x >= _out.w)
					return;
				mask = v1.mask_ptr;
				v1.destptr += 8 * v1.scaleXstep;
				dst = v1.destptr;
			}
		}
	} while (1);
}
Exemple #22
0
const char *
mdoc_a2att(const char *p)
{

	LINE("v1",	"Version\\~1 AT&T UNIX");
	LINE("v2",	"Version\\~2 AT&T UNIX");
	LINE("v3",	"Version\\~3 AT&T UNIX");
	LINE("v4",	"Version\\~4 AT&T UNIX");
	LINE("v5",	"Version\\~5 AT&T UNIX");
	LINE("v6",	"Version\\~6 AT&T UNIX");
	LINE("v7",	"Version\\~7 AT&T UNIX");
	LINE("32v",	"Version\\~32V AT&T UNIX");
	LINE("III",	"AT&T System\\~III UNIX");
	LINE("V",	"AT&T System\\~V UNIX");
	LINE("V.1",	"AT&T System\\~V Release\\~1 UNIX");
	LINE("V.2",	"AT&T System\\~V Release\\~2 UNIX");
	LINE("V.3",	"AT&T System\\~V Release\\~3 UNIX");
	LINE("V.4",	"AT&T System\\~V Release\\~4 UNIX");

	return NULL;
}
Exemple #23
0
/**
  * @brief  Initialize resources used for this demo. 
  * @param  None
  * @retval Digit value
  */
uint8_t Demo_Init(void)
{
  __IO uint32_t tmpValue = 0;
  PressedKey = NOKEY;
  
 /* Configure the IO Expander */
  if(IOE_Config() == IOE_OK)
  { 
    LCD_DisplayStringLine(LINE(6), (uint8_t*)"IO Expander OK          ");
    Delay(0xFF);
  }
  else
  {
    LCD_SetTextColor(LCD_COLOR_RED);  
    LCD_DisplayStringLine(LINE(6), (uint8_t*)"IO Expander FAILED Please Reset the board");
    while (1);
  }

  /* Enable the Joystick interrupt */
  IOE_ITConfig(IOE_ITSRC_JOYSTICK);

  Demo_LCD_Clear();
  LCD_DisplayStringLine(LINE(6), (uint8_t*)"Main Menu:              ");
  LCD_DisplayStringLine(LINE(7), (uint8_t*)"==========");
  LCD_DisplayStringLine(LINE(8), (uint8_t*)"Use UP and DOWN Buttons to Navigate");
  LCD_DisplayStringLine(LINE(9), (uint8_t*)"Use SEL Button to Select Image Format");

  LCD_DisplayStringLine(LINE(11), (uint8_t*)"Select the Image Format:");
  Display_Menu(ValueMin, ValueMax);

  while (1)
  {
    /* If "UP" pushbutton is pressed */
    if (PressedKey == UP)
    {
      PressedKey = NOKEY;
      
      /* Increase the value of the digit */
      if (tmpValue == ValueMin)
      {
        tmpValue = ValueMax - 1;
      }
      else
      {
        tmpValue--;
      }
      /* Display new Menu */
      Display_Menu(tmpValue, ValueMax);
    }
    /* If "DOWN" pushbutton is pressed */
    if (PressedKey == DOWN)
    {
      PressedKey = NOKEY;
      
      /* Decrease the value of the digit */
      if (tmpValue == (ValueMax - 1))
      {
        tmpValue = ValueMin;
      }
      else
      {
        tmpValue++;
      }
      /* Display new Menu */
      Display_Menu(tmpValue, ValueMax);
    }
    /* If "SEL" pushbutton is pressed */
    if (PressedKey == SEL)
    {
      PressedKey = NOKEY;

      /* Return the digit value and exit */
      return (ImageFormat_TypeDef)tmpValue;
    }
  }
}
Exemple #24
0
void
vappend(int ch, int cnt, int indent)
{
	register int i;
	register char *gcursor;
	bool escape;
	int repcnt, savedoomed;
	short oldhold = hold;

	/*
	 * Before a move in hardopen when the line is dirty
	 * or we are in the middle of the printed representation,
	 * we retype the line to the left of the cursor so the
	 * insert looks clean.
	 */
	if (ch != 'o' && state == HARDOPEN && (rubble || !ateopr())) {
		rubble = 1;
		gcursor = cursor;
		i = *gcursor;
		*gcursor = ' ';
		wcursor = gcursor;
		vmove();
		*gcursor = i;
	}
	vaifirst = indent == 0;

	/*
	 * Handle replace character by (eventually)
	 * limiting the number of input characters allowed
	 * in the vgetline routine.
	 */
	if (ch == 'r')
		repcnt = 2;
	else
		repcnt = 0;

	/*
	 * If an autoindent is specified, then
	 * generate a mixture of blanks to tabs to implement
	 * it and place the cursor after the indent.
	 * Text read by the vgetline routine will be placed in genbuf,
	 * so the indent is generated there.
	 */
	if (value(AUTOINDENT) && indent != 0) {
		gcursor = genindent(indent);
		*gcursor = 0;
		vgotoCL(qcolumn(cursor - 1, genbuf));
	} else {
		gcursor = genbuf;
		*gcursor = 0;
		if (ch == 'o')
			vfixcurs();
	}

	/*
	 * Prepare for undo.  Pointers delimit inserted portion of line.
	 */
	vUA1 = vUA2 = cursor;

	/*
	 * If we are not in a repeated command and a ^@ comes in
	 * then this means the previous inserted text.
	 * If there is none or it was too long to be saved,
	 * then beep() and also arrange to undo any damage done
	 * so far (e.g. if we are a change.)
	 */
	if ((vglobp && *vglobp == 0) || peekbr()) {
		if ((INS[0] & (OVERBUF|TRIM)) == OVERBUF) {
			beep();
			if (!splitw)
				ungetkey('u');
			doomed = 0;
			hold = oldhold;
			return;
		}
		/*
		 * Unread input from INS.
		 * An escape will be generated at end of string.
		 * Hold off n^^2 type update on dumb terminals.
		 */
		vglobp = INS;
		hold |= HOLDQIK;
	} else if (vglobp == 0)
		/*
		 * Not a repeated command, get
		 * a new inserted text for repeat.
		 */
		INS[0] = 0;

	/*
	 * For wrapmargin to hack away second space after a '.'
	 * when the first space caused a line break we keep
	 * track that this happened in gobblebl, which says
	 * to gobble up a blank silently.
	 */
	gobblebl = 0;

	/*
	 * Text gathering loop.
	 * New text goes into genbuf starting at gcursor.
	 * cursor preserves place in linebuf where text will eventually go.
	 */
	if (*cursor == 0 || state == CRTOPEN)
		hold |= HOLDROL;
	for (;;) {
		if (ch == 'r' && repcnt == 0)
			escape = 0;
		else {
			gcursor = vgetline(repcnt, gcursor, &escape, ch);

			/*
			 * After an append, stick information
			 * about the ^D's and ^^D's and 0^D's in
			 * the repeated text buffer so repeated
			 * inserts of stuff indented with ^D as backtab's
			 * can work.
			 */
			if (HADUP)
				addtext("^");
			else if (HADZERO)
				addtext("0");
			while (CDCNT > 0)
				addtext("\204"), CDCNT--;
			if (gobbled)
				addtext(" ");
			addtext(ogcursor);
		}
		repcnt = 0;

		/*
		 * Smash the generated and preexisting indents together
		 * and generate one cleanly made out of tabs and spaces
		 * if we are using autoindent.
		 */
		if (!vaifirst && value(AUTOINDENT)) {
			i = fixindent(indent);
			if (!HADUP)
				indent = i;
			gcursor = strend(genbuf);
		}

		/*
		 * Limit the repetition count based on maximum
		 * possible line length; do output implied
		 * by further count (> 1) and cons up the new line
		 * in linebuf.
		 */
		cnt = vmaxrep(ch, cnt);
		CP(gcursor + 1, cursor);
		do {
			CP(cursor, genbuf);
			if (cnt > 1) {
				int oldhold = hold;

				Outchar = vinschar;
				hold |= HOLDQIK;
				ex_printf("%s", genbuf);
				hold = oldhold;
				Outchar = vputchar;
			}
			cursor += gcursor - genbuf;
		} while (--cnt > 0);
		endim();
		vUA2 = cursor;
		if (escape != '\n')
			CP(cursor, gcursor + 1);

		/*
		 * If doomed characters remain, clobber them,
		 * and reopen the line to get the display exact.
		 */
		if (state != HARDOPEN) {
			DEPTH(vcline) = 0;
			savedoomed = doomed;
			if (doomed > 0) {
				register int cind = cindent();

				physdc(cind, cind + doomed);
				doomed = 0;
			}
			i = vreopen(LINE(vcline), lineDOT(), vcline);
#ifdef TRACE
			if (trace)
				fprintf(trace, "restoring doomed from %d to %d\n", doomed, savedoomed);
#endif
			if (ch == 'R')
				doomed = savedoomed;
		}

		/*
		 * All done unless we are continuing on to another line.
		 */
		if (escape != '\n')
			break;

		/*
		 * Set up for the new line.
		 * First save the current line, then construct a new
		 * first image for the continuation line consisting
		 * of any new autoindent plus the pushed ahead text.
		 */
		killU();
		addtext(gobblebl ? " " : "\n");
		vsave();
		cnt = 1;
		if (value(AUTOINDENT)) {
#ifdef LISPCODE
			if (value(LISP))
				indent = lindent(dot + 1);
			else
#endif
			     if (!HADUP && vaifirst)
				indent = whitecnt(linebuf);
			vaifirst = 0;
			strcLIN(vpastwh(gcursor + 1));
			gcursor = genindent(indent);
			*gcursor = 0;
			if (gcursor + strlen(linebuf) > &genbuf[LBSIZE - 2])
				gcursor = genbuf;
			CP(gcursor, linebuf);
		} else {
			CP(genbuf, gcursor + 1);
			gcursor = genbuf;
		}

		/*
		 * If we started out as a single line operation and are now
		 * turning into a multi-line change, then we had better yank
		 * out dot before it changes so that undo will work
		 * correctly later.
		 */
		if (FIXUNDO && vundkind == VCHNG) {
			vremote(1, (void (*)(int))yank, 0);
			undap1--;
		}

		/*
		 * Now do the append of the new line in the buffer,
		 * and update the display.  If slowopen
		 * we don't do very much.
		 */
		vdoappend(genbuf);
		vundkind = VMANYINS;
		vcline++;
		if (state != VISUAL)
			vshow(dot, NOLINE);
		else {
			/* TODO: Initialized? (ck) */
			i += LINE(vcline - 1);
			vopen(dot, i);
			if (value(SLOWOPEN))
				vscrap();
			else
				vsync1(LINE(vcline));
		}
		strcLIN(gcursor);
		*gcursor = 0;
		cursor = linebuf;
		vgotoCL(qcolumn(cursor - 1, genbuf));
	}

	/*
	 * All done with insertion, position the cursor
	 * and sync the screen.
	 */
	hold = oldhold;
	if (cursor > linebuf)
		cursor--;
	if (state != HARDOPEN)
		vsyncCL();
	else if (cursor > linebuf)
		back1();
	doomed = 0;
	wcursor = cursor;
	vmove();
}
/**
  * @brief  Manages Audio process.
  * @param  None
  * @retval Audio error
  */
AUDIO_ErrorTypeDef AUDIO_Process(void)
{
  int32_t diff;
  uint32_t bytesread, elapsed_time;
  static uint32_t prev_elapsed_time = 0xFFFFFFFF;
  uint8_t str[10];
  AUDIO_ErrorTypeDef error_state = AUDIO_ERROR_NONE;

  switch(audio_state)
  {
  case AUDIO_STATE_PLAY:
    if((BufferCtl.out_ptr = USBH_AUDIO_GetOutOffset(&hUSBHost)) < 0) /* End of file */
    {
      audio_state = AUDIO_STATE_NEXT;
    }
    else if(BufferCtl.out_ptr >= (AUDIO_BLOCK_SIZE * AUDIO_BLOCK_NBR)) /* End of buffer */
    {
      USBH_AUDIO_ChangeOutBuffer(&hUSBHost, &BufferCtl.buff[0]);
    }
    else
    {
      diff = BufferCtl.out_ptr - BufferCtl.in_ptr;

      if(diff < 0)
      {
        diff = AUDIO_BLOCK_SIZE * AUDIO_BLOCK_NBR + diff;
      }

      if(diff >= (AUDIO_BLOCK_SIZE * AUDIO_BLOCK_NBR / 2))
      {
        BufferCtl.in_ptr += AUDIO_BLOCK_SIZE;

        if(BufferCtl.in_ptr >= (AUDIO_BLOCK_SIZE * AUDIO_BLOCK_NBR))
        {
          BufferCtl.in_ptr = 0;
        }

        if(f_read(&WavFile,
                  &BufferCtl.buff[BufferCtl.in_ptr],
                  AUDIO_BLOCK_SIZE,
                  (void *)&bytesread) != FR_OK)
        {
          error_state = AUDIO_ERROR_IO;
        }
      }
    }

    /* Display elapsed time */
    elapsed_time = WavFile.fptr / WavInfo.ByteRate;
    if(prev_elapsed_time != elapsed_time)
    {
      prev_elapsed_time = elapsed_time;
      sprintf((char *)str, "[%02lu:%02lu]", elapsed_time /60, elapsed_time%60);
      BSP_LCD_SetTextColor(LCD_COLOR_CYAN);
      BSP_LCD_DisplayStringAt(263, LINE(8), str, LEFT_MODE);
      BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
    }
    break;

  case AUDIO_STATE_NEXT:
    if(++FilePos >= FileList.ptr)
    {
      FilePos = 0;
    }
    USBH_AUDIO_Stop(&hUSBHost);
    AUDIO_Start(FilePos);
    break;

  case AUDIO_STATE_PREVIOUS:
    if(--FilePos < 0)
    {
      FilePos = FileList.ptr - 1;
    }
    USBH_AUDIO_Stop(&hUSBHost);
    AUDIO_Start(FilePos);
    break;

  case AUDIO_STATE_PAUSE:
    BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)"  [PAUSE]", LEFT_MODE);
    USBH_AUDIO_Suspend(&hUSBHost);
    audio_state = AUDIO_STATE_WAIT;
    break;

  case AUDIO_STATE_RESUME:
    BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)"  [PLAY ]", LEFT_MODE);
    USBH_AUDIO_Resume(&hUSBHost);
    audio_state = AUDIO_STATE_PLAY;
    break;

  case AUDIO_STATE_VOLUME_UP:
    USBH_AUDIO_SetVolume(&hUSBHost, VOLUME_UP);
    audio_state = AUDIO_STATE_PLAY;
    break;

  case AUDIO_STATE_VOLUME_DOWN:
    USBH_AUDIO_SetVolume(&hUSBHost, VOLUME_DOWN);
    audio_state = AUDIO_STATE_PLAY;
    break;

  case AUDIO_STATE_ERROR:
    BSP_LCD_SetTextColor(LCD_COLOR_RED);
    BSP_LCD_DisplayStringAt(178, LINE(8), (uint8_t *)"[Unsupported Format]", LEFT_MODE);
    audio_state = AUDIO_STATE_INIT;
    break;

  case AUDIO_STATE_WAIT:
  case AUDIO_STATE_CONFIG:
  case AUDIO_STATE_IDLE:
  case AUDIO_STATE_INIT:
  default:
    break;
  }
  return error_state;
}
void CameraMatrix::draw() const
{
  DECLARE_DEBUG_DRAWING("representation:CameraMatrix:Image", "drawingOnImage"); // Shows the robot coordinate system
  DECLARE_DEBUG_DRAWING("representation:CameraMatrix:Field", "drawingOnField"); // Shows the robot coordinate system

  COMPLEX_DRAWING("representation:CameraMatrix:Field",
  {
    CameraInfo cameraInfo;
    if(Blackboard::getInstance().exists("CameraInfo"))
      cameraInfo = (const CameraInfo&) Blackboard::getInstance()["CameraInfo"];
    Vector2<int> pointOnField[6];
    // calculate the projection of the four image corners to the ground
    Transformation::imageToRobot(0, 0, *this, cameraInfo, pointOnField[0]);
    Transformation::imageToRobot(cameraInfo.width, 0, *this, cameraInfo, pointOnField[1]);
    Transformation::imageToRobot(cameraInfo.width, cameraInfo.height, *this, cameraInfo, pointOnField[2]);
    Transformation::imageToRobot(0, cameraInfo.height, *this, cameraInfo, pointOnField[3]);

    // calculate a line 15 pixels below the horizon in the image
    Geometry::Line horizon = Geometry::calculateHorizon(*this, cameraInfo);
    Geometry::Line lineBelowHorizon;
    Vector2<> vertLineDirection(-horizon.direction.y, horizon.direction.x);
    lineBelowHorizon.direction = horizon.direction;
    lineBelowHorizon.base = horizon.base;
    lineBelowHorizon.base += vertLineDirection * 15.0f;

    // calculate the projection to the ground of the intersection points of the line parallel to the horizon and the image borders
    Vector2<int> beginPoint;
    Vector2<int> endPoint;
    if(Geometry::getIntersectionPointsOfLineAndRectangle(
      Vector2<int>(0, 0), Vector2<int>(cameraInfo.width - 1, cameraInfo.height - 1), lineBelowHorizon, beginPoint, endPoint))
    {
      Transformation::imageToRobot(beginPoint.x, beginPoint.y, *this, cameraInfo, pointOnField[4]);
      Transformation::imageToRobot(endPoint.x, endPoint.y, *this, cameraInfo, pointOnField[5]);
      LINE("representation:CameraMatrix:Field", pointOnField[4].x, pointOnField[4].y, pointOnField[5].x, pointOnField[5].y, 30, Drawings::ps_solid, ColorRGBA::yellow);
    }

    // determine the boundary of all the points that were projected to the ground
    Boundary<int> boundary(-10000, +10000);
    if(pointOnField[0].x != 0 || pointOnField[0].y != 0) {boundary.add(pointOnField[0]); CIRCLE("representation:CameraMatrix:Field", pointOnField[0].x, pointOnField[0].y, 100, 50, Drawings::ps_solid, ColorRGBA::white, Drawings::bs_null, ColorRGBA::white); }
    if(pointOnField[1].x != 0 || pointOnField[1].y != 0) {boundary.add(pointOnField[1]); CIRCLE("representation:CameraMatrix:Field", pointOnField[1].x, pointOnField[1].y, 100, 50, Drawings::ps_solid, ColorRGBA::white, Drawings::bs_null, ColorRGBA::white); }
    if(pointOnField[2].x != 0 || pointOnField[2].y != 0) {boundary.add(pointOnField[2]); CIRCLE("representation:CameraMatrix:Field", pointOnField[2].x, pointOnField[2].y, 100, 50, Drawings::ps_solid, ColorRGBA::white, Drawings::bs_null, ColorRGBA::white); }
    if(pointOnField[3].x != 0 || pointOnField[3].y != 0) {boundary.add(pointOnField[3]); CIRCLE("representation:CameraMatrix:Field", pointOnField[3].x, pointOnField[3].y, 100, 50, Drawings::ps_solid, ColorRGBA::white, Drawings::bs_null, ColorRGBA::white); }
    if(pointOnField[4].x != 0 || pointOnField[4].y != 0) {boundary.add(pointOnField[4]); CIRCLE("representation:CameraMatrix:Field", pointOnField[4].x, pointOnField[4].y, 100, 50, Drawings::ps_solid, ColorRGBA::yellow, Drawings::bs_null, ColorRGBA::yellow); }
    if(pointOnField[5].x != 0 || pointOnField[5].y != 0) {boundary.add(pointOnField[5]); CIRCLE("representation:CameraMatrix:Field", pointOnField[5].x, pointOnField[5].y, 100, 50, Drawings::ps_solid, ColorRGBA::yellow, Drawings::bs_null, ColorRGBA::yellow); }

    LINE("representation:CameraMatrix:Field", boundary.x.min, boundary.y.min, boundary.x.max, boundary.y.min, 30, Drawings::ps_solid, ColorRGBA::red);
    LINE("representation:CameraMatrix:Field", boundary.x.max, boundary.y.min, boundary.x.max, boundary.y.max, 30, Drawings::ps_solid, ColorRGBA::yellow);
    LINE("representation:CameraMatrix:Field", boundary.x.max, boundary.y.max, boundary.x.min, boundary.y.max, 30, Drawings::ps_solid, ColorRGBA::blue);
    LINE("representation:CameraMatrix:Field", boundary.x.min, boundary.y.max, boundary.x.min, boundary.y.min, 30, Drawings::ps_solid, ColorRGBA::white);

    // fill the bounding rectangle with coordinate system lines (and reproject it to the image)
    int spacing = 100;
    for(int xx = boundary.x.min - boundary.x.min % spacing + spacing ; xx <= boundary.x.max; xx += spacing)
    {
      LINE("representation:CameraMatrix:Field", xx, boundary.y.min, xx, boundary.y.max, 5, Drawings::ps_solid, ColorRGBA::white);
    }
    for(int yy = boundary.y.min - boundary.y.min % spacing + spacing ; yy <= boundary.y.max; yy += spacing)
    {
      LINE("representation:CameraMatrix:Field", boundary.x.min, yy, boundary.x.max, yy, 5, Drawings::ps_solid, ColorRGBA::white);
    }
  });// end complex drawing
Exemple #27
0
int main(void)
{

            CanTxMsg TxMessage;
  float X_offset =0.0f,Y_offset =0.0f,Z_offset =0.0f;
  float test_float=0.0f; uint8_t test_int=0;
  float GyX =0.0f, GyY =0.0f, GyZ =0.0f;
  float GyX_prev=0.0f,GyY_prev=0.0f,GyZ_prev=0.0f;
      uint16_t x_len=240;
      uint16_t y_len=320;

      uint16_t i=0;
      uint16_t buffer_screen[x_len][y_len];

      /* For gyro receiving  */
     float receivedGyro1=0,receivedGyro1_prev=0;
     float receivedGyro2=0,receivedGyro2_prev=0;
     float receivedGyro3=0,receivedGyro3_prev=0;
     uint8_t *ptr = & receivedGyro1;


      // uint16_t *buf_ptr = &buffer_screen;
      float runner=-8.0;

      rectangular_t rect1;
      rectangular_t prev_rect;
      rectangular_t rect_screen;


    char lcd_text_main[100];

    /* LCD Initialization */
    lcd_init();
    lcd_drawBackground(20,60,250);
    //lcd_drawBGPersimmon(20, 60, 250);



    /* LED Initialization */
    LED_Initialization();

    /* CAN Initialization */
    CAN2_Config();
    CAN2_NVIC_Config();

    /* MEMS Initialization */
    Demo_GyroConfig();

    Delay_1us(10000);
      #define CALIBRATE_COUNT 1000
      for (i=0;i<CALIBRATE_COUNT ;i++){
        Demo_GyroReadAngRate (Buffer);
        X_offset+= Buffer[0];
        Y_offset+= Buffer[1];
        Z_offset+= Buffer[2];
      }

      X_offset = X_offset/ (float)CALIBRATE_COUNT;
      Y_offset = Y_offset/ (float)CALIBRATE_COUNT;
      Z_offset = Z_offset/ (float)CALIBRATE_COUNT;


        rect_screen.xlen = x_len;
        rect_screen.ylen = y_len;
        rect_screen.xpos = 0;
        rect_screen.ypos = 0;

        #define NEEDLE_RADIUS 65
        #define NEEDLE_BASE_WIDTH 14
        #define NEEDLE_FRAME_THICKNESS 5
        
        #define NEEDLE1_CENTER_X 80
        #define NEEDLE1_CENTER_Y 100

        #define NEEDLE2_CENTER_X 80
        #define NEEDLE2_CENTER_Y 200

        #define NEEDLE3_CENTER_X 80
        #define NEEDLE3_CENTER_Y 300

        /* Drawing Needle frame 1 */
        LCD_SetLayer(LCD_BACKGROUND_LAYER);

        DrawThickCircle(NEEDLE1_CENTER_X ,NEEDLE1_CENTER_Y,NEEDLE_RADIUS+NEEDLE_FRAME_THICKNESS, 4,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
       
        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        DrawThickCircle(NEEDLE1_CENTER_X ,NEEDLE1_CENTER_Y,NEEDLE_BASE_WIDTH, 6,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        
        LCD_SetLayer(LCD_BACKGROUND_LAYER);
        LCD_SetColors(ASSEMBLE_RGB(20, 60, 250),LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE1_CENTER_X- NEEDLE_RADIUS-NEEDLE_FRAME_THICKNESS*2,NEEDLE1_CENTER_Y+ NEEDLE_BASE_WIDTH+3,NEEDLE_RADIUS*2+NEEDLE_FRAME_THICKNESS*4,NEEDLE_RADIUS);

        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE1_CENTER_X- NEEDLE_RADIUS,NEEDLE1_CENTER_Y+ NEEDLE_BASE_WIDTH,NEEDLE_RADIUS*2,NEEDLE_FRAME_THICKNESS-1);

        /* Drawing Needle frame 2 */
        LCD_SetLayer(LCD_BACKGROUND_LAYER);

        DrawThickCircle(NEEDLE2_CENTER_X ,NEEDLE2_CENTER_Y,NEEDLE_RADIUS+NEEDLE_FRAME_THICKNESS, 4,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
       
        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        DrawThickCircle(NEEDLE2_CENTER_X ,NEEDLE2_CENTER_Y,NEEDLE_BASE_WIDTH, 6,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        
        LCD_SetLayer(LCD_BACKGROUND_LAYER);
        LCD_SetColors(ASSEMBLE_RGB(20, 60, 250),LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE2_CENTER_X- NEEDLE_RADIUS-NEEDLE_FRAME_THICKNESS*2,NEEDLE2_CENTER_Y+ NEEDLE_BASE_WIDTH+3,NEEDLE_RADIUS*2+NEEDLE_FRAME_THICKNESS*4,NEEDLE_RADIUS);

        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE2_CENTER_X- NEEDLE_RADIUS,NEEDLE2_CENTER_Y+ NEEDLE_BASE_WIDTH,NEEDLE_RADIUS*2,NEEDLE_FRAME_THICKNESS-1);


        /* Drawing Needle frame 2 */
        LCD_SetLayer(LCD_BACKGROUND_LAYER);

        DrawThickCircle(NEEDLE3_CENTER_X ,NEEDLE3_CENTER_Y,NEEDLE_RADIUS+NEEDLE_FRAME_THICKNESS, 4,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
       
        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        DrawThickCircle(NEEDLE3_CENTER_X ,NEEDLE3_CENTER_Y,NEEDLE_BASE_WIDTH, 6,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        
        LCD_SetLayer(LCD_BACKGROUND_LAYER);
        LCD_SetColors(ASSEMBLE_RGB(20, 60, 250),LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE3_CENTER_X- NEEDLE_RADIUS-NEEDLE_FRAME_THICKNESS*2,NEEDLE3_CENTER_Y+ NEEDLE_BASE_WIDTH+3,NEEDLE_RADIUS*2+NEEDLE_FRAME_THICKNESS*4,NEEDLE_RADIUS);

        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE3_CENTER_X- NEEDLE_RADIUS,NEEDLE3_CENTER_Y+ NEEDLE_BASE_WIDTH,NEEDLE_RADIUS*2,NEEDLE_FRAME_THICKNESS-1);

        /* Clear drawing buffer */
        PadRectangular(&buffer_screen,x_len,y_len,LCD_COLOR_WHITE, &rect_screen);




      while(1)
      {

        board_ID = PIN_ID_Read();

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        sprintf(lcd_text_main," CAN Demo ID:%d    ",board_ID);
        LCD_DisplayStringLine(LINE(0), (uint8_t*)lcd_text_main);

        Demo_GyroReadAngRate (Buffer);

        //Delay_1us(1000);

        /* MEMS Filtering */
        #define LP_ALPHA 0.1f
        GyX = GyX*(1.0f - LP_ALPHA) + (Buffer[0] - X_offset)*LP_ALPHA;
        GyY = GyY*(1.0f - LP_ALPHA) + (Buffer[1] - Y_offset)*LP_ALPHA;
        GyZ = GyZ*(1.0f - LP_ALPHA) + (Buffer[2] - Z_offset)*LP_ALPHA;

        if(GyX >  90.0f)  GyX =  90.0f;
        if(GyX < -90.0f)  GyX = -90.0f;
        if(GyY >  90.0f)  GyY =  90.0f;
        if(GyY <  -90.0f) GyY = -90.0f;
        if(GyZ >  90.0f)  GyZ =  90.0f;
        if(GyZ < -90.0f)  GyZ = -90.0f;

        /* Start drawing rectangular */
        prev_rect = rect1;

        rect1.xlen = 25;
        rect1.ylen = 30;
        rect1.xpos = x_len/2+ (int16_t)(GyY)-10;
        rect1.ypos = y_len/2 + (int16_t)(GyX)-10;


        if(board_ID == 1){


          MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_GREEN,NEEDLE1_CENTER_X,NEEDLE1_CENTER_Y,-GyZ,-GyZ_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);

        }else if(board_ID == 2){

          MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_GREEN,NEEDLE2_CENTER_X,NEEDLE2_CENTER_Y,-GyZ,-GyZ_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);

        }else {

          MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_GREEN,NEEDLE3_CENTER_X,NEEDLE3_CENTER_Y,-GyZ,-GyZ_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);

        }

            CAN2_TransmitGyro(board_ID,GyZ);

            /* Received Data */
            if( can2_rx_isr_flag ==1){

              do{

            if( can2_rx_isr_flag ==1){
                  can2RxMessage = CAN2_PassRXMessage();
                  can2_rx_isr_flag=0;
                }else{

                  CAN_Receive(CAN2, CAN_FIFO0, &can2RxMessage);
                }
                  GPIO_ToggleBits(GPIOG,GPIO_Pin_14);

                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];


                    if(( can2RxMessage.ExtId &   0x0000FFFF) == 1){
                        ptr = & receivedGyro1;
                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];


                        MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_RED,NEEDLE1_CENTER_X,NEEDLE1_CENTER_Y,-receivedGyro1,-receivedGyro1_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);
                        
                    receivedGyro1_prev = receivedGyro1;
                    }else if (( can2RxMessage.ExtId & 0x0000FFFF) == 2){
                        ptr = & receivedGyro2;
                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];
                        MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_RED,NEEDLE2_CENTER_X,NEEDLE2_CENTER_Y,-receivedGyro2,-receivedGyro2_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);
                        
                    receivedGyro2_prev = receivedGyro2;
                    }else if (( can2RxMessage.ExtId & 0x0000FFFF) == 3){
                        ptr = & receivedGyro3;
                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];
                        MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_RED,NEEDLE3_CENTER_X,NEEDLE3_CENTER_Y,-receivedGyro3,-receivedGyro3_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);
                        
                    receivedGyro3_prev = receivedGyro3;
                    }
                  // LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
                  // sprintf(lcd_text_main," ID :%d         ", can2RxMessage.StdId);
                  // LCD_DisplayStringLine(LINE(1), (uint8_t*)lcd_text_main);
                  // LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
                  // sprintf(lcd_text_main," Data :%f        ", receivedGyro);
                  // LCD_DisplayStringLine(LINE(2), (uint8_t*)lcd_text_main);
                }while(CAN_MessagePending(CAN2, CAN_FIFO0) > 0);



            }



          // {
          //   uint8_t status=0;



          //   while(CAN_TransmitStatus(CAN2, 0) != CAN_TxStatus_Ok ){

          //     status = CAN_TransmitStatus(CAN2, 0);
          //        if(status == CAN_TxStatus_Failed){

          //         GPIO_ToggleBits(GPIOG,GPIO_Pin_14);


          //        }
          //  }

          // }
            // TxMessage.StdId = (uint32_t)board_ID;
            // TxMessage.RTR = CAN_RTR_DATA;
            // TxMessage.IDE = CAN_ID_STD;
            // TxMessage.DLC = 8;
            // TxMessage.Data[0] = 0x01;
            // TxMessage.Data[1] = 0x01;
            // TxMessage.Data[2] = 0x01;
            // TxMessage.Data[3] = 0x01;
            // TxMessage.Data[4] = 0x01;
            // TxMessage.Data[5] = 0x01;
            // TxMessage.Data[6] = 0x01;
            // TxMessage.Data[7] = 0x01;
            // CAN_Transmit(CAN2, &TxMessage);

        //CAN2_TransmitGyro(test_int++,test_float);

        test_float += 0.1f;

        GyX_prev = GyX;
        GyZ_prev = GyZ;
        GyY_prev = GyY;

        runner += 1.0f;


        /* Faster method */
        //MoveAndUpdateRectangular(LCD_FOREGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_BLACK,&prev_rect, &rect1);
        
        /* Regular method */
        // PadRectangular(&buffer_screen,x_len,y_len,LCD_COLOR_WHITE, &prev_rect);
        // PadRectangular(&buffer_screen,x_len,y_len,LCD_COLOR_BLACK, &rect1);
         //DrawBufferToScreen(LCD_FOREGROUND_LAYER,buf_ptr,0,0, x_len,y_len);

      }

    
  
}
ScreenOptionsMaster::ScreenOptionsMaster( const CString &sClassName ):
	ScreenOptions( sClassName )
{
	LOG->Trace("ScreenOptionsMaster::ScreenOptionsMaster(%s)", m_sName.c_str() );

	/* If this file doesn't exist, leave the music alone (eg. ScreenPlayerOptions music sample
	 * left over from ScreenSelectMusic).  If you really want to play no music, add a redir
	 * to _silent. */
	CString MusicPath = THEME->GetPathToS( ssprintf("%s music", m_sName.c_str()), true );
	if( MusicPath != "" )
		SOUND->PlayMusic( MusicPath );

	CStringArray asLineNames;
	split( LINE_NAMES, ",", asLineNames );
	if( asLineNames.empty() )
		RageException::Throw( "%s::LineNames is empty.", m_sName.c_str() );


	CStringArray Flags;
	split( OPTION_MENU_FLAGS, ";", Flags, true );
	InputMode im = INPUTMODE_INDIVIDUAL;
	bool Explanations = false;
	
	unsigned i;
	for( i = 0; i < Flags.size(); ++i )
	{
		CString &flag = Flags[i];
		flag.MakeLower();

		if( flag == "together" )
			im = INPUTMODE_SHARE_CURSOR;
		else if( flag == "explanations" )
			Explanations = true;
		else if( flag == "forceallplayers" )
		{
			FOREACH_PlayerNumber( pn )
				GAMESTATE->m_bSideIsJoined[pn] = true;
			GAMESTATE->m_MasterPlayerNumber = PlayerNumber(0);
		}
		else if( flag == "smnavigation" )
			SetNavigation( NAV_THREE_KEY_MENU );
		else if( flag == "toggle" || flag == "firstchoicegoesdown" )
			SetNavigation( PREFSMAN->m_bArcadeOptionsNavigation? NAV_TOGGLE_THREE_KEY:NAV_TOGGLE_FIVE_KEY );
	}

	m_OptionRowAlloc = new OptionRowData[asLineNames.size()];
	for( i = 0; i < asLineNames.size(); ++i )
	{
		OptionRowData &row = m_OptionRowAlloc[i];
		
		vector<ParsedCommand> vCommands;
		ParseCommands( LINE(asLineNames[i]), vCommands );
		
		if( vCommands.size() < 1 )
			RageException::Throw( "Parse error in %s::Line%i", m_sName.c_str(), i+1 );

		OptionRowHandler hand;
		for( unsigned part = 0; part < vCommands.size(); ++part)
		{
			ParsedCommand& command = vCommands[part];

			HandleParams;

			const CString name = sParam(0);

			if( !name.CompareNoCase("list") )
			{
				SetList( row, hand, sParam(1), row.name );
			}
			else if( !name.CompareNoCase("steps") )
			{
				SetStep( row, hand );
				row.name = "Steps";
			}
			else if( !name.CompareNoCase("conf") )
			{
				SetConf( row, hand, sParam(1), row.name );
			}
			else if( !name.CompareNoCase("characters") )
			{
				SetCharacter( row, hand );
				row.name = "Characters";
			}
			else
				RageException::Throw( "Unexpected type '%s' in %s::Line%i", name.c_str(), m_sName.c_str(), i );

			CheckHandledParams;
		}

		// TRICKY:  Insert a down arrow as the first choice in the row.
		if( m_OptionsNavigation == NAV_TOGGLE_THREE_KEY )
		{
			row.choices.insert( row.choices.begin(), ENTRY_NAME("NextRow") );
			hand.ListEntries.insert( hand.ListEntries.begin(), ModeChoice() );
		}

		OptionRowHandlers.push_back( hand );
	}

	ASSERT( OptionRowHandlers.size() == asLineNames.size() );

	Init( im, m_OptionRowAlloc, asLineNames.size() );
}
/**
  * @brief  Displays a maximum of 20 char on the LCD.
  * @param  Line: the Line where to display the character shape .
  * @param  *ptr: pointer to string to display on LCD.
  * #param	mode: The display mode.
  *                This parameter can be one of the following values:
  *                @arg CENTER_MODE
  *                @arg RIGHT_MODE
  *                @arg LEFT_MODE
  * @retval None
  */
void BSP_LCD_DisplayStringAtLineMode(uint16_t Line, uint8_t *ptr, Text_AlignModeTypdef mode)
{
  BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, mode);
}
void
MBFrameToField(int16_t data[6 * 64])
{
	int16_t tmp[8];

	/* left blocks */

	/* 1=2, 2=4, 4=8, 8=1 */
	MOVLINE(tmp, LINE(0, 1));
	MOVLINE(LINE(0, 1), LINE(0, 2));
	MOVLINE(LINE(0, 2), LINE(0, 4));
	MOVLINE(LINE(0, 4), LINE(2, 0));
	MOVLINE(LINE(2, 0), tmp);

	/* 3=6, 6=12, 12=9, 9=3 */
	MOVLINE(tmp, LINE(0, 3));
	MOVLINE(LINE(0, 3), LINE(0, 6));
	MOVLINE(LINE(0, 6), LINE(2, 4));
	MOVLINE(LINE(2, 4), LINE(2, 1));
	MOVLINE(LINE(2, 1), tmp);

	/* 5=10, 10=5 */
	MOVLINE(tmp, LINE(0, 5));
	MOVLINE(LINE(0, 5), LINE(2, 2));
	MOVLINE(LINE(2, 2), tmp);

	/* 7=14, 14=13, 13=11, 11=7 */
	MOVLINE(tmp, LINE(0, 7));
	MOVLINE(LINE(0, 7), LINE(2, 6));
	MOVLINE(LINE(2, 6), LINE(2, 5));
	MOVLINE(LINE(2, 5), LINE(2, 3));
	MOVLINE(LINE(2, 3), tmp);

	/* right blocks */

	/* 1=2, 2=4, 4=8, 8=1 */
	MOVLINE(tmp, LINE(1, 1));
	MOVLINE(LINE(1, 1), LINE(1, 2));
	MOVLINE(LINE(1, 2), LINE(1, 4));
	MOVLINE(LINE(1, 4), LINE(3, 0));
	MOVLINE(LINE(3, 0), tmp);

	/* 3=6, 6=12, 12=9, 9=3 */
	MOVLINE(tmp, LINE(1, 3));
	MOVLINE(LINE(1, 3), LINE(1, 6));
	MOVLINE(LINE(1, 6), LINE(3, 4));
	MOVLINE(LINE(3, 4), LINE(3, 1));
	MOVLINE(LINE(3, 1), tmp);

	/* 5=10, 10=5 */
	MOVLINE(tmp, LINE(1, 5));
	MOVLINE(LINE(1, 5), LINE(3, 2));
	MOVLINE(LINE(3, 2), tmp);

	/* 7=14, 14=13, 13=11, 11=7 */
	MOVLINE(tmp, LINE(1, 7));
	MOVLINE(LINE(1, 7), LINE(3, 6));
	MOVLINE(LINE(3, 6), LINE(3, 5));
	MOVLINE(LINE(3, 5), LINE(3, 3));
	MOVLINE(LINE(3, 3), tmp);
}