static void check_device_task(struct state_machine_context *state_m) { Ai_player_flag_t player_flag_temp; static uint32_t old_status = 0; static t_cpu_time get_play_time_timer = { .timer_state = CPU_TIMER_STATE_STOPPED }; // By default, the command executed is asynchronous. state_m->async_cmd = true; switch (state_m->state) { // This state id the entry point of the check device function. case STATE_CHECK_DEVICE_ENTRY_POINT: state_m->cmd_status = true; if (usb_device_get_state() != DEVICE_STATE_READY) { state_m->async_cmd = false; state_m->state = STATE_DEVICE_DISCONNECTED; break; } if( cpu_is_timer_stopped(&get_play_time_timer) ) { cpu_set_timeout(cpu_ms_2_cy(ELAPSED_TIME_TIMER_VALUE_MS, FCPU_HZ), &get_play_time_timer); ai_async_audio_ctrl_status(); state_m->state = STATE_CHECK_DEVICE_UPDATE_STATUS; } else { if( cpu_is_timeout(&get_play_time_timer) ) { cpu_stop_timeout(&get_play_time_timer); } state_m->async_cmd = false; player_flag_temp.all = old_status; update_player_status(state_m, (Ai_player_flag_t *) &player_flag_temp); state_m->state = state_m->recorded_state; } break; // This state update the elapsed time of the current track being played. case STATE_CHECK_DEVICE_UPDATE_STATUS: state_m->async_cmd = false; player_flag_temp.all = ai_async_cmd_out_u32(); update_player_status(state_m, (Ai_player_flag_t *) &player_flag_temp); // The transitional states such as "new file played" can not be kept in the saved status. // Otherwise, we will send during 'ELAPSED_TIME_TIMER_VALUE_MS' second(s) a saved status with // the "new_file_played" event, leading do a full redisplay of the metadata information and audio // cracks. In other words, the saved status needs to keep the states (play/pause/...), not the events. player_flag_temp.new_file_played = 0; player_flag_temp.new_directory = 0; old_status = player_flag_temp.all; state_m->state = state_m->recorded_state; break; default: return; } // Error management if (state_m->cmd_status == false) state_m->state = STATE_DEVICE_DISCONNECTED; }
/** * \brief Update status of all players. */ void ptb::frame_play_story::update_all_players_status() { update_player_status(1, m_first_player_status); if ( game_variables::get_players_count() == 2 ) update_player_status(2, m_second_player_status); else { m_second_player_status.score_text->set_text( gettext("No player") ); m_second_player_status.lives_text->set_text( "0" ); m_second_player_status.stone_text->set_text( "0" ); m_second_player_status.energy->set_length(100); m_second_player_status.energy->set_level(0); m_second_player_status.energy->set_max_level(100); update_power (false, "gfx/ui/air-power.png", m_second_player_status.air_power); update_power (false, "gfx/ui/fire-power.png", m_second_player_status.fire_power); update_power (false, "gfx/ui/water-power.png", m_second_player_status.water_power); } } // frame_play_story::update_all_players_status()