Advertisement
thorium90

Task_v1.2.cpp

Oct 21st, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. /*
  2.    ___|  _)  | _)       _)                         ___|                    
  3.  \___ \   |  |  |   __|  |  |   |  __ `__ \       |       _ \    __|  __ \  
  4.        |  |  |  |  (     |  |   |  |   |   |      |      (   |  |     |   |
  5.  _____/  _| _| _| \___| _| \__,_| _|  _|  _|     \____| \___/  _|     .__/  
  6.                                                                      _|  
  7. Code source libre de droit. Si vous utilisez mon code, merci à vous d'en préciser la source.
  8.  
  9. Date : 21/10/2011
  10. Auteur : Silicium Corp
  11. */
  12. #include "Task.h"
  13.  
  14. //===============================================================
  15. Task::Task(unsigned int unitCycle)
  16. {
  17.     cycleTimeBak = unitCycle;
  18.     reset();
  19. }
  20. //===============================================================
  21. void Task::reset()
  22. {
  23.     lastTime =  -9999999;
  24.     setCycleTime(cycleTimeBak);
  25.     onPause = true;
  26.     elapsedCycle = 0;
  27.     lastTick = 0;
  28.     elapsedTime = 0;
  29. }
  30. //===============================================================
  31. unsigned long Task::tick()
  32. {
  33.     currentTimeMicro = micros();
  34.     elapsedTime = currentTimeMicro - lastTick;
  35.     lastTick = currentTimeMicro;
  36.     return(elapsedTime);
  37. }
  38. //===============================================================
  39. boolean Task::isOutOfDate()
  40. {
  41.     currentTime = millis();
  42.     if(currentTime - lastTime >= cycleTime)
  43.     {
  44.         lastTime = currentTime;
  45.         elapsedCycle++;
  46.         return (!onPause);
  47.     }
  48.     else
  49.     {
  50.         return (false);
  51.     }
  52. }
  53. //===============================================================
  54. void Task::setCycleTime(unsigned int unitCycle)
  55. {
  56.     cycleTime = unitCycle;
  57. }
  58. //===============================================================
  59. int Task::getElapsedCycle()
  60. {
  61.     return (elapsedCycle);
  62. }
  63. //===============================================================
  64. unsigned int Task::getCycleTime()
  65. {
  66.     return (cycleTime);
  67. }
  68. //===============================================================
  69. boolean Task::isSleeping()
  70. {
  71.     return (onPause);
  72. }
  73. //===============================================================
  74. void Task::run()
  75. {
  76.     onPause = false;
  77. }
  78. //===============================================================
  79. void Task::standby()
  80. {
  81.     onPause = true;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement