-
Notifications
You must be signed in to change notification settings - Fork 4
/
upoff.h
108 lines (91 loc) · 2.9 KB
/
upoff.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
uPoff
@copyright 2020 Florian Knodt, www.adlerweb.info
*/
#include <Arduino.h>
#include "Wire.h"
#ifndef UPOFF_NORTC
#include <Rtc_Pcf8563.h>
#endif
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#elif defined(__AVR__)
#include <avr/sleep.h>
#endif
#ifndef UPOFF__H
#define UPOFF__H
class UPOFF{
private:
/**
* Pin unsed to keep power on
*/
int _uPoffOnPin;
public:
#ifndef UPOFF_NORTC
/**
* RTC access
*/
Rtc_Pcf8563 rtc;
#endif
/**
* Turn power off
*/
void off(void);
/**
* Keep power on
* @param int Pin used to keep power on ("ON")
* @return bool always false
*/
bool on(int onPin);
#ifndef UPOFF_NORTC
/**
* Check reason for wakeup
* @return bool true = timed wake; false = external wake
*/
bool rtcCheckReason(void);
/**
* Keep power on
* @param int Pin used to keep power on ("ON")
* @param bool Use I²C if true
* @return bool true = timed wake; false = external wake
*/
bool on(int onPin, bool i2c);
#if defined(ESP8266) or defined(ESP32)
/**
* Keep power on
* @param int Pin used to keep power on ("ON")
* @param int Pin used for I²C SDA
* @param int Pin used for I²C SCL
* @return bool true = timed wake; false = external wake
*/
bool on(int onPin, int sda, int scl);
#endif
/**
* Check if RTC is running without a problem
*/
bool isValid(bool checkVolt=true);
/**
* Set RTC date and time
* @param year Year
* @param month Month
* @param day Day
* @param hour Hour
* @param minute Minute
* @param second Second
*/
void setTime(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
/**
* Get RTC date and time
* @return String current time in YYYY-mm-dd HH:MM:SS
*/
String getTime(void);
/**
* Turn power off and set timer
* @param unsigned long seconds to wake
*/
void off(unsigned long seconds);
#endif
};
#endif /* UPOFF__H */