Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
base.cpp
Go to the documentation of this file.
1#include <WiFiClientSecure.h>
2#include "base.h"
3
5{
6 pinMode(EPD_EN, OUTPUT);
7 pinMode(EPD_RST, OUTPUT);
8 pinMode(SD_EN, OUTPUT);
9 pinMode(BATT_EN, OUTPUT);
10 pinMode(PCF_INT, INPUT); // Required to lower power consumption
11
12 pinMode(BUTTON_1_PIN, INPUT_PULLUP);
13 pinMode(BUTTON_2_PIN, INPUT_PULLUP);
14 pinMode(BUTTON_3_PIN, INPUT_PULLUP);
15 pinMode(BUTTON_4_PIN, INPUT_PULLUP);
16
17 return 0;
18}
19
21{
22 // Power up EPD
23 digitalWrite(EPD_EN, LOW);
24 digitalWrite(EPD_RST, LOW);
25 delay(50);
26 digitalWrite(EPD_RST, HIGH);
27 delay(50);
28
29 return 0;
30}
31
33{
34 digitalWrite(EPD_EN, HIGH);
35 digitalWrite(EPD_RST, LOW);
36 delay(50);
37 digitalWrite(EPD_RST, HIGH);
38
39 return 0;
40}
41
43{
44 // Power up SD
45 digitalWrite(SD_EN, LOW);
46 if (!SD.begin(SD_CS)) {
47 Serial.println("SD failed!");
48 return -1;
49 }
50
51 return 0;
52}
53
55{
56 // Power down SD
57 digitalWrite(SD_EN, HIGH);
58
59 return 0;
60}
61
63{
65 disable_sd();
66 // TODO: Add disable functions for Batt
67 digitalWrite(BATT_EN, HIGH);
68
69 return 0;
70}
71
73{
74 // Turn off everything
76
77 esp_sleep_enable_timer_wakeup(sleep_time_us);
78 Serial.printf("Timer wakeup after %lld microseconds...", sleep_time_us);
79
80 // Go to sleep
81 esp_deep_sleep_start();
82
83 return 0;
84}
85
87{
88 // Turn off everything
90
91 esp_sleep_enable_ext0_wakeup((gpio_num_t)gpio_num, 0); //1 = High, 0 = Low
92 Serial.printf("Button wakeup on pin %d", gpio_num);
93 // Go to sleep
94 esp_deep_sleep_start();
95
96 return 0;
97}
98
99int8_t PaperdinkDeviceBaseClass::deep_sleep_timer_button_wakeup(uint64_t sleep_time_us, uint8_t gpio_num)
100{
101 // Turn off everything
103
104 esp_sleep_enable_timer_wakeup(sleep_time_us);
105 esp_sleep_enable_ext0_wakeup((gpio_num_t)gpio_num, 0); //1 = High, 0 = Low
106 Serial.printf("Timer wakeup after %lld us or button on pin %d", sleep_time_us, gpio_num);
107 // Go to sleep
108 esp_deep_sleep_start();
109
110 return 0;
111}
112
113int8_t PaperdinkDeviceBaseClass::connect_wifi(const char *ssid, const char *password, uint8_t attempts)
114{
115 WiFi.begin(ssid, password);
116
117 while (WiFi.status() != WL_CONNECTED) {
118 delay(500);
119 Serial.print(".");
120 if (!attempts--)
121 return -1;
122 }
123 Serial.println("Connected");
124
125 return 0;
126}
127
128int8_t PaperdinkDeviceBaseClass::connect_wifi(const char *ssid, const char *password)
129{
130 return connect_wifi(ssid, password, 40);
131}
int8_t disable_everything()
Definition base.cpp:62
int8_t deep_sleep_timer_wakeup(uint64_t sleep_time_us)
Definition base.cpp:72
virtual int8_t enable_display()
Definition base.cpp:20
virtual int8_t disable_display()
Definition base.cpp:32
int8_t connect_wifi(const char *ssid, const char *password, uint8_t attempts)
Definition base.cpp:113
int8_t deep_sleep_button_wakeup(uint8_t gpio_num)
Definition base.cpp:86
int8_t deep_sleep_timer_button_wakeup(uint64_t sleep_time_us, uint8_t gpio_num)
Definition base.cpp:99
#define BUTTON_3_PIN
#define BUTTON_1_PIN
#define SD_EN
#define EPD_EN
#define PCF_INT
#define BUTTON_4_PIN
#define SD_CS
#define EPD_RST
#define BUTTON_2_PIN
#define BATT_EN