-
Notifications
You must be signed in to change notification settings - Fork 6
/
utils.ino
88 lines (79 loc) · 2.52 KB
/
utils.ino
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
85
86
87
88
/************************************************************************************
* some useful utilities
************************************************************************************/
/************************************************************************************
* Will return a string that is used to display the time since the last reception
* of a valid packet.
************************************************************************************/
String getDuration(unsigned long lastReceived, bool shortStr)
{
String res="";
unsigned long durationMillis = millis() - lastReceived;
unsigned long seconds = durationMillis / 1000;
unsigned long minutes = seconds / 60;
unsigned long hours = minutes / 60;
unsigned long days = hours / 24;
res.concat("(");
if (days > 0)
{
res += days;
if (shortStr)
res.concat(" days)");
else
res.concat(" days ago)");
return res;
}
if (hours > 0)
{
res += hours;
if (shortStr)
res.concat("hr ago)");
else
res.concat(" hours ago)");
return res;
}
if (minutes > 0)
{
res += minutes;
if (shortStr)
res.concat("m ago)");
else
res.concat(" minutes ago)");
return res;
}
if (seconds > 0)
{
res += seconds;
if (shortStr)
res.concat("s ago)");
else
res.concat(" seconds ago)");
return res;
}
return "";
}
#if defined(FLASH_PIN)
/************************************************************************************
* Setup the flash pin if it was defined in the settings file
************************************************************************************/
void setupFlashPin()
{
pinMode(FLASH_PIN, OUTPUT);
digitalWrite(FLASH_PIN,LOW);
}
/************************************************************************************
* enable the FLASH_PIN for 300ms
************************************************************************************/
void flashPin()
{
digitalWrite(FLASH_PIN, HIGH);
pinMillis = millis();
}
/************************************************************************************
* disable the FLASH_PIN
************************************************************************************/
void disablePin()
{
digitalWrite(FLASH_PIN, LOW);
}
#endif