Advertisement
odilonafonso

TimerMultiTask.h

Jul 13th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. /*
  2.  * TimerMultiTask.h
  3.  *
  4.  *      Author: odilon
  5.  *  Created on: 27/11/2015
  6.  *  Modified    13/07/2016
  7.  *  code for ESP8266
  8.  *  based: http://www.switchdoc.com/2015/10/iot-esp8266-timer-tutorial-arduino-ide/
  9.  */
  10. #ifndef TIMERMULTITASK_H
  11. #define TIMERMULTITASK_H
  12.  
  13. #if defined (ARDUINO_ARCH_ESP8266)
  14. extern "C" {
  15. #include "user_interface.h"
  16. }
  17. #else
  18. #include <Arduino.h>
  19. #include <TimerOne.h>
  20. #endif
  21.  
  22. #define TICTAC_SIZE 5   //taskArray size
  23.  
  24. /*
  25.  * task structure
  26.  *
  27.  */
  28. struct TicTac {
  29.     int tic;            //boom size
  30.     int tac;            //boom count
  31.     void (*call)();     //user function()
  32.     bool tictacEnabled; //task enabled
  33. };
  34. typedef struct TicTac tictac;
  35.  
  36. class TimerMultiTask {
  37.     public:
  38.         /*
  39.          * Constructor.
  40.          *
  41.          * @param boom - the period in microseconds to pause for
  42.          *
  43.          */
  44.         TimerMultiTask();
  45.  
  46.         /**
  47.          * Set the BOOM period  
  48.          *
  49.          * @boom unsigned long
  50.          */
  51.         void setBOOM(unsigned long boom);
  52.  
  53.         /**
  54.          * Add a tic stopper  
  55.          *
  56.          * @tic integer
  57.          */
  58.         int add(int, void (*)());
  59.  
  60.         /**
  61.          * Enable(or re-ebable) the task
  62.          *
  63.          * @taskId integer
  64.          */
  65.         bool enable(int taskId);
  66.  
  67.         /**
  68.          * Disable the task
  69.          *
  70.          * @taskId integer
  71.          */
  72.         bool disable(int taskId);
  73.  
  74.         /**
  75.          * Clear the TicTac struct of a task
  76.          *
  77.          * @taskId integer
  78.          */
  79.         bool clear(int taskId);
  80. };
  81.  
  82. #endif /* TIMERMULTITASK_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement