/* Private functions ---------------------------------------------------------*/
static portTASK_FUNCTION( vPlayBottonTask, pvParameters ) {
  int status = INIT;

	/* The parameters are not used. */
	( void ) pvParameters;
  
  for(;;) {
    switch (status) {
      case INIT: {
        /* Turn off the lamps */
        LAMP_OFF();
        /* Disable play button interrupt */
        DISABLE_PLAY_BUTTON_IT();
        /* Clean play button semaphore */
        while (pdTRUE == xSemaphoreTake(xBottonSemaphore, 0));
        while (Bit_RESET == PLAY_BUTTON_STATUS()) {
          vTaskDelay((TickType_t)10);
        }
        vTaskDelay((TickType_t)START_DELAY_MS);
        /* Enable play button interrupt */
        ENABLE_PLAY_BUTTON_IT();
        status = IDLE;
        break;
      }
      case IDLE: {
        /* Occur when play button is pressed */        
        if (pdTRUE == xSemaphoreTake(xBottonSemaphore, portMAX_DELAY)) {
          /* Skip the key jitter step */
          vTaskDelay((TickType_t)KEY_JITTER_DELAY_MS);
          /* Check whether the button was pressed */
          if (Bit_RESET == PLAY_BUTTON_STATUS()) {
            status = ACTION;
          } else {/* Enable play button interrupt */
            ENABLE_PLAY_BUTTON_IT();
          }
        }
        break;
      }
      case ACTION: {
        /* Turn on the lamps */
        LAMP_ON();
        /* Play audio */
        player_play_file(PLAY_BUTTON_AUDIO, 0);
        status = FINISH;
        break;
      }
      case FINISH: {
        /* Reset logic */
        if (pdTRUE == xSemaphoreTake(xResetSemaphore, portMAX_DELAY)) {
          status = INIT;
        }
        break;
      }
    }
  }
}
Example #2
0
File: cmus.c Project: Aseeker/cmus
void cmus_play_file(const char *filename)
{
	struct track_info *ti;

	cache_lock();
	ti = cache_get_ti(filename, 0);
	cache_unlock();
	if (!ti) {
		error_msg("Couldn't get file information for %s\n", filename);
		return;
	}

	player_play_file(ti);
}