View unanswered posts | View active topics It is currently Thu Sep 18, 2014 10:38 pm






Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
In-function Task Handling 
Author Message
Rookie

Joined: Fri Apr 08, 2011 4:31 pm
Posts: 11
Post Re: In-function Task Handling
This function came about because our team was having major problems with occasionally pressing the wrong button, and having to wait for 3+ seconds for it to end. When this happened in a competition, where time is crucial, it usually resulted in us losing. The handleTask() function is another attempt at making a universal killswitch for any running event longer than 2 seconds, while making it simple to use.


Fri Nov 04, 2011 4:52 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: In-function Task Handling
Ah I see. So it means you implement all your commands in separate tasks and you want to kill or start a task by the joystick button. Well, one way to get around this is to use macros instead of function.
Code:
#define handleTask1(taskName, button)   \
        if (joy1Btn(button) && \
            (getTaskState(taskName) == taskStateStopped)) \
        { \
            StartTask(taskName); \
        } \
        else if (joy1Btn(KButton) && \
                 (getTaskState(taskName) == taskStateRunning)) \
        { \
            StopTask(taskName); \
            allStop(); \
        }

#define handleTask2(taskName, button)   \
        if (joy2Btn(button) && \
            (getTaskState(taskName) == taskStateStopped)) \
        { \
            StartTask(taskName); \
        } \
        else if (joy2Btn(KButton) && \
                 (getTaskState(taskName) == taskStateRunning)) \
        { \
            StopTask(taskName); \
            allStop(); \
        }


Last edited by MHTS on Fri Nov 04, 2011 6:14 pm, edited 3 times in total.



Fri Nov 04, 2011 5:31 pm
Profile
Rookie

Joined: Fri Apr 08, 2011 4:31 pm
Posts: 11
Post Re: In-function Task Handling
It works!! Thank you very much!


Fri Nov 04, 2011 5:49 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.