-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFTBlink.cpp
85 lines (75 loc) · 1.55 KB
/
FTBlink.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <Arduino.h>
#include <stddef.h>
#include <stdint.h>
#include "FTBlink.h"
FTBlink::FTBlink(void) : TimeOutEvent(500)
{
}
void FTBlink::RegCallBack(void (*On)(void), void (*Off)(void)){
Ft_On = On;
Ft_Off = Off;
}
void FTBlink::attach_ms(uint8_t Count, uint16_t DelayOn, uint16_t DelayOff)
{
FTBCount = Count;
if (Count == 0) {
TaskFtB = TaskFtBStop;
Ft_Off();
}
FTBDelayOff = DelayOff;
FTBDelayOn = DelayOn;
}
void FTBlink::On(void)
{
FTBCount = 0;
TaskFtB = TaskFtBStop;
Ft_On();
}
void FTBlink::Off(void)
{
FTBCount = 0;
TaskFtB = TaskFtBStop;
Ft_Off();
}
uint8_t FTBlink::CountRemain(void){
return FTBCount;
}
void FTBlink::Blink(void)
{
switch (TaskFtB) {
case TaskFtBStop:
if (FTBCount > 0) {
TaskFtB = TaskFtBOn;
FTBPre = 1;
}
break;
case TaskFtBOn:
if (FTBPre == 1) {
FTBPre = 0;
ToEUpdate(FTBDelayOn);
//Nếu timeout > 0 thì mới điều khiển IO
if(FTBDelayOn) Ft_On();
}
if (!ToEExpired()) break;
TaskFtB = TaskFtBOff;
FTBPre = 1;
break;
case TaskFtBOff:
if (FTBPre == 1) {
FTBPre = 0;
ToEUpdate(FTBDelayOff);
//Nếu timeout > 0 thì mới điều khiển IO
if(FTBDelayOff) Ft_Off();
}
if (!ToEExpired()) break;
TaskFtB = TaskFtBOn;
FTBPre = 1;
if (--FTBCount == 0) {
TaskFtB = TaskFtBStop;
} else {
//Muc dich khi >100 thi led nhay mai mai
if (FTBCount > 100) FTBCount++;
}
break;
}
}