Jedi Engineer
Jedi Engineer

Reputation: 493

How do I put a delay in a case structure without delaying my loop?

Sorry, I am not allowed to post my full program - company rules.

I've got a portion of my program that reads a script file and reads in a timer value to the file. I need that value to pause the reading in of the next line from the script file, and the only way I'm aware of doing that is like this:

Loop Timer

where the scan from string function retrieves the time in milliseconds and inserts it into the delay function. The problem with this is, it delays my main loop, and I have other timed functions running simultaneously based on previous commands issued from the same script file that may take more time to run. IS there any way to instantiate this, within a case structure, that will pause the reading of the next command, and let the main loop continue?

My script reader has an event handler so that the rest of my program will run without it until called.

Script Event

This feeds directly into the nested case statements that feeds data directly to the timer. Any help is appreciated!

Upvotes: 1

Views: 1533

Answers (1)

sweber
sweber

Reputation: 2986

If I understand correctly:

  • You have a loop running some tasks all the time without interruption
  • Sometimes, a button is pressed, which will cause a special task being executed between two iterations of the loop.
  • A special task is to disable the button for some seconds

This is accomplished by the following simplified code.

  • When the button is clicked and the command from the file is WAIT 30, the current time plus 30s is written to the shift register, and the button is disabled grayed out. That is, the user can't click it, and he even sees this!
  • When the button is not clicked within 100ms, the Timeout case is executed. (again and again and again...) There, all the tasks which should run always, live. That case also checks if the current time is greater than the time in the shift register, and re-enables the button again.

enter image description here

Upvotes: 1

Related Questions