/* * Function that runs a countdown between stimulations. It doesn't really show the countdown to the user * * count = number of seconds of the countdown */ private void showCountDown(int count) { countdown = count; // Set the global variable 'countdown' screenState = screen_states.COUNTDOWN; // Set the screen to countdown mode timer1.Interval = 1000; // Interval between each tick (ms) timer1.Enabled = true; // Enable the timer timer1.Start(); // Start the countdown }
private void showCountDown(int count) { countdown = count; screenState = screen_states.COUNTDOWN; label_countDown.Visible = true; label_countDown.Text = countdown.ToString(); timer1.Interval = 1000; // voltar pra 1000 timer1.Enabled = true; timer1.Start(); }
private void button_start_Click(object sender, EventArgs e) { if (testStep == test_step.STOPPED) { button_start.Visible = false; testStep = test_step.TEXTURE_IMAGES; screenState = screen_states.COUNTDOWN; sequenceIndex = 1; showCountDown(5); button_status.Focus(); } }
/* * Event called whrn the button 'Start' is pressed. * It changes the system's states in order to start the protocol. */ private void button_start_Click(object sender, EventArgs e) { if (testStep == test_step.STOPPED) { button_start.Visible = false; // Hide the button testStep = test_step.TEXTURE_IMAGES; // Change the stimulation state screenState = screen_states.COUNTDOWN; // Change the screen state sequenceIndex = 1; // Set the first texture of the sequence updateTexture(sequenceIndex); // Transfer the spike data to uC showCountDown(5); // Start the countdown button_status.Focus(); // Focus on a hidden button } }
/* * Starts the Stimulation when the uC is already updated */ private void startStimulation() { timer1.Stop(); checkSerialState(); if (serial_States != serial_states.UPDATED) { MessageBox.Show("Something is wrong with the connection\nEstado: " + serial_States.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); // ************************** COLOCAR QUE FUNCÃO FINALIZA O PROTOCOLO E FECHA A TELA ********** endStimulation(false); Application.Exit(); return; } // Set the uC to start the stimulation telaSpikes.ESPSerial.WriteLine(Protocolos.iniciar); // Wait the uC for confirming the stimulation start do { checkSerialState(); } while (serial_States != serial_states.INITIATED); // Start the stimulation after the uC confirm if (testStep == test_step.STIMULATION_ON) { timer1.Interval = texture_duration; // Set the timer for the stimulation duration control interval.Start(); // Start the stopwatch screenState = screen_states.CROSS; // Change the screen state to appear the Cross label_countDown.Visible = true; label_countDown.Text = "+"; timer1.Start(); //Start the timer for the stimulation of 'texture_duration' seconds } }
private void startStimulation() { timer1.Stop(); checkSerialState(); if (serial_States != serial_states.UPDATED) { MessageBox.Show("Something is wrong with the connection\nEstado: " + serial_States.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); // ************************** COLOCAR QUE FUNCÃO FINALIZA O PROTOCOLO E FECHA A TELA ********** return; } telaSpikes.ESPSerial.WriteLine(Protocolos.iniciar); timer1.Interval = 7300; do { checkSerialState(); } while (serial_States != serial_states.INITIATED); interval.Start(); screenState = screen_states.CROSS; label_countDown.Visible = true; label_countDown.Text = "+"; progressBar_cross.Visible = true; progressBar_cross.Value = 0; increment_progBar.Resume(); timer1.Start(); // Inicia o timer de 7.3 s label_counter.Text = (textureSeqIndex + 1).ToString(); button_status.BackColor = Color.Red; }
private void timer1_Tick(object sender, EventArgs e) { switch (screenState) { case screen_states.COUNTDOWN: countdown--; if (countdown == 0) { timer1.Stop(); if (testStep == test_step.TEXTURE_IMAGES) { label_countDown.Visible = false; screenState = screen_states.IMAGE; showTextures(); } else if (testStep == test_step.WAITING_FOR_START) { testStep = test_step.STIMULATION_ON; Console.WriteLine("Before start"); startStimulation(); Console.WriteLine("Started"); } else if (testStep == test_step.STIMULATION_ON) { startStimulation(); } break; } label_countDown.Text = countdown.ToString(); break; case screen_states.IMAGE: if (sequenceIndex == 3) { sequenceIndex = 0; timer1.Stop(); testStep = test_step.WAITING_FOR_START; pictureBox_textura.Image = null; screenState = screen_states.COUNTDOWN; showCountDown(10); sequenceIndex = 0; updateTexture(); break; } timer1.Stop(); timer1.Enabled = false; screenState = screen_states.COUNTDOWN; pictureBox_textura.Image = null; showCountDown(5); sequenceIndex++; break; case screen_states.CROSS: endStimulation(false); break; } }
/* * The function called each time a tick occurs in the timer1 * * If the screen is in COUNTDOWN state, it decreases the 'countdown' variable each tick. * When it reached 0, it starts an stimulation according to the 'test_step' state * * If the screen is in IMAGE state, it removes the image from the screen and restart the countdown */ private void timer1_Tick(object sender, EventArgs e) { switch (screenState) { // COUNTDOWN is the screen state where the screen is black case screen_states.COUNTDOWN: countdown--; if (countdown == 0) { timer1.Stop(); if (testStep == test_step.TEXTURE_IMAGES) // Step of showing the textures with images { screenState = screen_states.IMAGE; // Change the scren state startStimulation(); // Start the stimulation with the texture image showTextures(); // Show the texture image } // After showing images and before starting the 15 stimualtions sequence else if (testStep == test_step.WAITING_FOR_START) { testStep = test_step.STIMULATION_ON; // Change test step Console.WriteLine("Before start"); startStimulation(); // Start the first stimulation of the 15 sequence Console.WriteLine("Started"); } // The 15 sequence has already started else if (testStep == test_step.STIMULATION_ON) { startStimulation(); } break; } break; case screen_states.IMAGE: // When showing the texture images endStimulation(false); // Stop the stimulation // If it is the last image, pass to the next step of the protocol if (sequenceIndex == 3) { sequenceIndex = 0; // Reset the sequence timer1.Stop(); testStep = test_step.WAITING_FOR_START; // Chenge the protocol step pictureBox_textura.Image = null; // Removes the image from the screen screenState = screen_states.COUNTDOWN; // Updates the screen state showCountDown(10); // Start a 10 seconds countdown sequenceIndex = 0; updateTexture(0); // Load the texture into the uC break; } // If its not the last image, set a seconds countdown before the next image timer1.Stop(); timer1.Enabled = false; screenState = screen_states.COUNTDOWN; pictureBox_textura.Image = null; updateTexture(sequenceIndex); showCountDown(5); sequenceIndex++; break; case screen_states.CROSS: // The 15 sequence stimulations endStimulation(false); // Stop the stimulation and prepare for the next break; } }