|
@ -34,6 +34,10 @@ |
|
|
#include "screen.h" |
|
|
#include "screen.h" |
|
|
#include "led.h" |
|
|
#include "led.h" |
|
|
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
int rom_phy_get_vdd33(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4); |
|
|
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -42,6 +46,7 @@ char weatherStr[32]; |
|
|
RTC_DATA_ATTR static int boot_count = 0; |
|
|
RTC_DATA_ATTR static int boot_count = 0; |
|
|
RTC_DATA_ATTR struct tm alarmTime; |
|
|
RTC_DATA_ATTR struct tm alarmTime; |
|
|
RTC_DATA_ATTR bool alarmArmed = false; |
|
|
RTC_DATA_ATTR bool alarmArmed = false; |
|
|
|
|
|
RTC_DATA_ATTR bool displaySleep = true; |
|
|
|
|
|
|
|
|
//Create a new Basecamp instance called iot
|
|
|
//Create a new Basecamp instance called iot
|
|
|
Basecamp iot; |
|
|
Basecamp iot; |
|
@ -107,6 +112,9 @@ void setup() { |
|
|
if (timeinfo.tm_year < (2016 - 1900)) { |
|
|
if (timeinfo.tm_year < (2016 - 1900)) { |
|
|
// time not set
|
|
|
// time not set
|
|
|
} |
|
|
} |
|
|
|
|
|
strftime(timeStr, sizeof(timeStr), "%H:%M", &timeinfo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char strftime_buf[64]; |
|
|
char strftime_buf[64]; |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); |
|
|
Serial.print("Current time: "); Serial.println(strftime_buf); |
|
|
Serial.print("Current time: "); Serial.println(strftime_buf); |
|
@ -117,7 +125,7 @@ void setup() { |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); |
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); |
|
|
Serial.print(" Alarm time: "); Serial.println(strftime_buf); |
|
|
Serial.print(" Alarm time: "); Serial.println(strftime_buf); |
|
|
|
|
|
|
|
|
if (-seconds > secondsToSleep) suspend(); |
|
|
if (!alarmArmed || -seconds > secondsToSleep) suspend(); |
|
|
else if (-seconds > 5*60) suspend(5*60); |
|
|
else if (-seconds > 5*60) suspend(5*60); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -227,6 +235,16 @@ void suspend(uint32_t secondsToSleep) { |
|
|
//
|
|
|
//
|
|
|
////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals
|
|
|
////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals
|
|
|
|
|
|
|
|
|
|
|
|
if (!displaySleep) { |
|
|
|
|
|
u8g2.begin(); |
|
|
|
|
|
u8g2.clearBuffer(); |
|
|
|
|
|
u8g2.sendBuffer(); |
|
|
|
|
|
u8g2.setFont(u8g2_font_inb19_mf); |
|
|
|
|
|
u8g2.drawStr(0, 20, timeStr); |
|
|
|
|
|
// ToDo: set rtc gpio resistors
|
|
|
|
|
|
esp_sleep_enable_timer_wakeup(1000000LL * 60); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//send the ESP into deep sleep
|
|
|
//send the ESP into deep sleep
|
|
|
esp_deep_sleep_start(); |
|
|
esp_deep_sleep_start(); |
|
|
} |
|
|
} |
|
@ -235,8 +253,8 @@ void suspend() { |
|
|
time_t now; |
|
|
time_t now; |
|
|
time(&now); |
|
|
time(&now); |
|
|
double seconds = difftime(now, mktime(&alarmTime)); |
|
|
double seconds = difftime(now, mktime(&alarmTime)); |
|
|
if (-seconds > secondsToSleep) suspend(secondsToSleep); |
|
|
if (-seconds > secondsToSleep || !alarmArmed) suspend(secondsToSleep); |
|
|
else if (-seconds > 5*60) suspend(5*60); |
|
|
else suspend(5*60); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void setAlarmTime(struct tm time) { |
|
|
void setAlarmTime(struct tm time) { |
|
@ -309,8 +327,12 @@ void loop() |
|
|
if (alarmArmed && seconds >= -2*5*60) stayAwake = true; |
|
|
if (alarmArmed && seconds >= -2*5*60) stayAwake = true; |
|
|
if (!mp3.playing && millis() - lastButtonPress >= 60*1000 && !stayAwake) suspend(); |
|
|
if (!mp3.playing && millis() - lastButtonPress >= 60*1000 && !stayAwake) suspend(); |
|
|
|
|
|
|
|
|
|
|
|
int voltage = rom_phy_get_vdd33(); |
|
|
|
|
|
Serial.printf("voltage: %d\n", voltage); |
|
|
|
|
|
|
|
|
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); |
|
|
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); |
|
|
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); |
|
|
sprintf(weatherStr, "%.1f°C %.1f%% %dmV", bme280.readTemperature(), bme280.readHumidity(), voltage); |
|
|
|
|
|
// sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());
|
|
|
|
|
|
|
|
|
Serial.print("Free Heap: "); |
|
|
Serial.print("Free Heap: "); |
|
|
Serial.println(ESP.getFreeHeap()); |
|
|
Serial.println(ESP.getFreeHeap()); |
|
|