forked from DaniFoldi/Async_Operations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsync_Operations.h
53 lines (46 loc) · 1.52 KB
/
Async_Operations.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Async_Operations.h library for running time-consuming tasks without blocking the main thread
* Created by Dániel Földi (05. August 2020)
*/
#ifndef Async_Operations_Header
#define Async_Operations_Header
#include "Arduino.h"
class Async_Operations {
public:
Async_Operations(long long *steps, int stepCount);
Async_Operations(long long *steps, int stepCount, int repeat);
Async_Operations(long long *steps, int stepCount, int repeat, int pin);
Async_Operations(long long *steps, int stepCount, int repeat, int pin, bool initialState);
Async_Operations(long long *steps, int stepCount, int repeat, int pin, bool initialState, bool endState);
void start();
void restart();
void stop();
void pause();
void play();
bool getPaused();
bool getRunning();
int getRepeatCount();
bool getState();
void update();
void setStateChangeCallback(void (*stateChangeCallback)(void));
void deleteStateChangeCallback();
void setLoopCallback(void (*loopCallback)(void));
void deleteLoopCallback();
private: // order as in constructor
long long *steps;
int stepCount;
int step;
int pin = -1;
bool running = false;
long long startTime = 0;
long long lastUpdate = 0;
int initialRepeat = 0;
bool initialState = true;
bool endState = false;
bool state;
int repeat;
long long remaining;
void (*stateChangeCallback)(void) = nullptr;
void (*loopCallback)(void) = nullptr;
};
#endif