Home AMX User Forum AMX General Discussion

TIMELINE_KILL inside TIMELINE_EVENT, Is this a legal operation?

Here is a code fragment. I don't have access to a processor at the moment to test this. Is it legal to kill a timeline while the event is being processed? Also, is timeline_reload allowed in the event handler? Dumb question, how does one maintain the program formatting in a post?


DEFINE_FUNCTION AVR_Send_Cmd(INTEGER nInChar)
{
nRingBuffer[nEndPtr] = nInChar // put the character in the ring buffer

if (nEndPtr != BUFFER_SIZE) // at the end of the buffer
nEndPtr = nEndPtr + 1; // nope
else
nEndPtr = 1; // yup, back to the beginning

if (TIMELINE_ACTIVE(TL1) = 0) // timeline is NOT active (or created)
{
if (nAVR_OnState = 0) // device was off, wait for it to power up
TimeArray[2] = POWERUP_DELAY
TIMELINE_CREATE(TL1, TimeArray, 3, TIMELINE_RELATIVE, TIMELINE_REPEAT) // create the timeline
}
}

(***********************************************************)
(* THE EVENTS GO BELOW *)
(***********************************************************)
DEFINE_EVENT

TIMELINE_EVENT[TL1]
{
SWITCH(Timeline.Sequence) // which time was it?
{
CASE 1: // execute command
{
if (nEndPtr != nStartPtr) // when nEndPtr = StartPtr, then buffer is empty
{
nOutChar = nRingBuffer[nStartPtr] //extract the character
send_string 0, "'Out_char=',itoa(nOutChar),' Start Ptr=',itoa(nStartPtr),' End Ptr=',itoa(nEndPtr)" //debug
if (nStartPtr < BUFFER_SIZE) // at the end of ring?
nStartPtr = nStartPtr + 1; // nope
else
nStartPtr = 1; // yup, back to the begining
}
else
{
timeline_kill(TL1) // finished sending commands, terminate timeline
}
break
}
CASE 2: // do nothing delay time, waiting for device to receive and process command.
{
break
}
CASE 3:
{
if (nAVR_OnState = 0) // device was OFF
{
TimeArray[2] = COMMAND_PACING // normal command pacing
nAVR_OnState = 1 // after 1 pass, the device is on
timeline_reload(TL1,TimeArray,3) // use new times
}
break
}
}
}

Comments

  • JohnMichnrJohnMichnr Posts: 279
    I use Timeline_Kills inside the timeline_event all the time(line).

    Especially if you have a repeating timeline that needs to end once the condition is met.

    Don't know abou tthe timeline_reload - never tried it from nside - why wouldn't it work?
  • annuelloannuello Posts: 294
    pushtoplay wrote: »
    Dumb question, how does one maintain the program formatting in a post?

    Click on the "BB code" at the bottom left. You will see a "code" item in the list.
  • Thanks guys!
    keith
  • DHawthorneDHawthorne Posts: 4,584
    I seem to vaguely recall having trouble in the past killing a timeline from within ... not that it didn't work, but that it generated a run-time error. I think it got fixed in subsequent firmware revisions. I've also noticed you get run-time errors if you try to kill a timeline that isn't actually running, so I got in the habit of checking it first ... though I suspect they may have corrected that as well. My point? Give it a try, see what happens. Worst case you have to move a line or two of code around.
  • JohnMichnrJohnMichnr Posts: 279
    DHawthorne wrote: »
    I've also noticed you get run-time errors if you try to kill a timeline that isn't actually running, so I got in the habit of checking it first ... though I suspect they may have corrected that as well. .

    Yeah I started checking each time for timeline_active before killing just to avoid the run time errors. I think that is still an issue
Sign In or Register to comment.