Skip to content

Commit

Permalink
Add support for Watchy V3 and fixed compilation errors with arduion-e…
Browse files Browse the repository at this point in the history
…sp32 v3.0.x
  • Loading branch information
sqfmi committed Jul 2, 2024
1 parent 667d867 commit 7747dcc
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 33 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Watchy",
"version": "1.4.10",
"version": "1.4.11",
"description": "Watchy - An Open Source E-Paper Watch by SQFMI",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Watchy
version=1.4.10
version=1.4.11
author=SQFMI
maintainer=SQFMI
sentence=Watchy - An Open Source E-Paper Watch by SQFMI
Expand Down
2 changes: 1 addition & 1 deletion src/BLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class otaCallback : public BLECharacteristicCallbacks {
};

void otaCallback::onWrite(BLECharacteristic *pCharacteristic) {
std::string rxData = pCharacteristic->getValue();
String rxData = pCharacteristic->getValue();
if (!updateFlag) { // If it's the first packet of OTA since bootup, begin OTA
// Serial.println("Begin FW Update");
esp_ota_begin(esp_ota_get_next_update_partition(NULL), OTA_SIZE_UNKNOWN,
Expand Down
1 change: 0 additions & 1 deletion src/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// Link: https://github.com/sqfmi/Watchy

#include "Display.h"
#include "config.h"

RTC_DATA_ATTR bool displayFullInit = true;

Expand Down
2 changes: 2 additions & 0 deletions src/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#pragma once

#include <GxEPD2_EPD.h>
#include "driver/gpio.h"
#include "config.h"

class WatchyDisplay : public GxEPD2_EPD
{
Expand Down
72 changes: 59 additions & 13 deletions src/Watchy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include "Watchy.h"

WatchyRTC Watchy::RTC;
#ifdef ARDUINO_ESP32S3_DEV
Watchy32KRTC Watchy::RTC;
#define ACTIVE_LOW 0
#else
WatchyRTC Watchy::RTC;
#define ACTIVE_LOW 1
#endif
GxEPD2_BW<WatchyDisplay, WatchyDisplay::HEIGHT> Watchy::display(
WatchyDisplay{});

Expand All @@ -20,14 +26,22 @@ RTC_DATA_ATTR char lastSSID[30];
void Watchy::init(String datetime) {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause(); // get wake up reason
Wire.begin(SDA, SCL); // init i2c
#ifdef ARDUINO_ESP32S3_DEV
Wire.begin(WATCHY_V3_SDA, WATCHY_V3_SCL); // init i2c
#else
Wire.begin(SDA, SCL); // init i2c
#endif
RTC.init();

// Init the display since is almost sure we will use it
display.epd2.initWatchy();

switch (wakeup_reason) {
#ifdef ARDUINO_ESP32S3_DEV
case ESP_SLEEP_WAKEUP_TIMER: // RTC Alarm
#else
case ESP_SLEEP_WAKEUP_EXT0: // RTC Alarm
#endif
RTC.read(currentTime);
switch (guiState) {
case WATCHFACE_STATE:
Expand Down Expand Up @@ -70,7 +84,18 @@ void Watchy::init(String datetime) {
void Watchy::deepSleep() {
display.hibernate();
RTC.clearAlarm(); // resets the alarm flag in the RTC

#ifdef ARDUINO_ESP32S3_DEV
esp_sleep_enable_ext1_wakeup(
BTN_PIN_MASK,
ESP_EXT1_WAKEUP_ANY_LOW); // enable deep sleep wake on button press

rtc_clk_32k_enable(true);
//rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL);
struct tm timeinfo;
getLocalTime(&timeinfo);
int secToNextMin = 60 - timeinfo.tm_sec;
esp_sleep_enable_timer_wakeup(secToNextMin * uS_TO_S_FACTOR);
#else
// Set GPIOs 0-39 to input to avoid power leaking out
const uint64_t ignore = 0b11110001000000110000100111000010; // Ignore some GPIOs due to resets
for (int i = 0; i < GPIO_NUM_MAX; i++) {
Expand All @@ -83,6 +108,8 @@ void Watchy::deepSleep() {
esp_sleep_enable_ext1_wakeup(
BTN_PIN_MASK,
ESP_EXT1_WAKEUP_ANY_HIGH); // enable deep sleep wake on button press
#endif

esp_deep_sleep_start();
}

Expand Down Expand Up @@ -173,7 +200,7 @@ void Watchy::handleButtonPress() {
if (millis() - lastTimeout > 5000) {
timeout = true;
} else {
if (digitalRead(MENU_BTN_PIN) == 1) {
if (digitalRead(MENU_BTN_PIN) == ACTIVE_LOW) {
lastTimeout = millis();
if (guiState ==
MAIN_MENU_STATE) { // if already in menu, then select menu item
Expand Down Expand Up @@ -205,7 +232,7 @@ void Watchy::handleButtonPress() {
} else if (guiState == FW_UPDATE_STATE) {
updateFWBegin();
}
} else if (digitalRead(BACK_BTN_PIN) == 1) {
} else if (digitalRead(BACK_BTN_PIN) == ACTIVE_LOW) {
lastTimeout = millis();
if (guiState ==
MAIN_MENU_STATE) { // exit to watch face if already in menu
Expand All @@ -217,7 +244,7 @@ void Watchy::handleButtonPress() {
} else if (guiState == FW_UPDATE_STATE) {
showMenu(menuIndex, false); // exit to menu if already in app
}
} else if (digitalRead(UP_BTN_PIN) == 1) {
} else if (digitalRead(UP_BTN_PIN) == ACTIVE_LOW) {
lastTimeout = millis();
if (guiState == MAIN_MENU_STATE) { // increment menu index
menuIndex--;
Expand All @@ -226,7 +253,7 @@ void Watchy::handleButtonPress() {
}
showFastMenu(menuIndex);
}
} else if (digitalRead(DOWN_BTN_PIN) == 1) {
} else if (digitalRead(DOWN_BTN_PIN) == ACTIVE_LOW) {
lastTimeout = millis();
if (guiState == MAIN_MENU_STATE) { // decrement menu index
menuIndex++;
Expand Down Expand Up @@ -323,6 +350,7 @@ void Watchy::showAbout() {
display.print(voltage);
display.println("V");

#ifndef ARDUINO_ESP32S3_DEV
display.print("Uptime: ");
RTC.read(currentTime);
time_t b = makeTime(bootTime);
Expand All @@ -337,7 +365,9 @@ void Watchy::showAbout() {
display.print(hours);
display.print("h");
display.print(minutes);
display.println("m");
display.println("m");
#endif

if(WIFI_CONFIGURED){
display.print("SSID: ");
display.println(lastSSID);
Expand Down Expand Up @@ -379,11 +409,19 @@ void Watchy::setTime() {

RTC.read(currentTime);

#ifdef ARDUINO_ESP32S3_DEV
uint8_t minute = currentTime.Minute;
uint8_t hour = currentTime.Hour;
uint8_t day = currentTime.Day;
uint8_t month = currentTime.Month;
uint8_t year = currentTime.Year;
#else
int8_t minute = currentTime.Minute;
int8_t hour = currentTime.Hour;
int8_t day = currentTime.Day;
int8_t month = currentTime.Month;
int8_t year = tmYearToY2k(currentTime.Year);
#endif

int8_t setIndex = SET_HOUR;

Expand All @@ -398,21 +436,21 @@ void Watchy::setTime() {

while (1) {

if (digitalRead(MENU_BTN_PIN) == 1) {
if (digitalRead(MENU_BTN_PIN) == ACTIVE_LOW) {
setIndex++;
if (setIndex > SET_DAY) {
break;
}
}
if (digitalRead(BACK_BTN_PIN) == 1) {
if (digitalRead(BACK_BTN_PIN) == ACTIVE_LOW) {
if (setIndex != SET_HOUR) {
setIndex--;
}
}

blink = 1 - blink;

if (digitalRead(DOWN_BTN_PIN) == 1) {
if (digitalRead(DOWN_BTN_PIN) == ACTIVE_LOW) {
blink = 1;
switch (setIndex) {
case SET_HOUR:
Expand All @@ -435,7 +473,7 @@ void Watchy::setTime() {
}
}

if (digitalRead(UP_BTN_PIN) == 1) {
if (digitalRead(UP_BTN_PIN) == ACTIVE_LOW) {
blink = 1;
switch (setIndex) {
case SET_HOUR:
Expand Down Expand Up @@ -519,7 +557,11 @@ void Watchy::setTime() {
tmElements_t tm;
tm.Month = month;
tm.Day = day;
#ifdef ARDUINO_ESP32S3_DEV
tm.Year = year;
#else
tm.Year = y2kYearToTm(year);
#endif
tm.Hour = hour;
tm.Minute = minute;
tm.Second = 0;
Expand Down Expand Up @@ -548,7 +590,7 @@ void Watchy::showAccelerometer() {

unsigned long currentMillis = millis();

if (digitalRead(BACK_BTN_PIN) == 1) {
if (digitalRead(BACK_BTN_PIN) == ACTIVE_LOW) {
break;
}

Expand Down Expand Up @@ -693,12 +735,16 @@ weatherData Watchy::_getWeatherData(String cityID, String lat, String lon, Strin
}

float Watchy::getBatteryVoltage() {
#ifdef ARDUINO_ESP32S3_DEV
return analogReadMilliVolts(BATT_ADC_PIN) / 1000.0f * ADC_VOLTAGE_DIVIDER;
#else
if (RTC.rtcType == DS3231) {
return analogReadMilliVolts(BATT_ADC_PIN) / 1000.0f *
2.0f; // Battery voltage goes through a 1/2 divider.
} else {
return analogReadMilliVolts(BATT_ADC_PIN) / 1000.0f * 2.0f;
}
#endif
}

uint8_t Watchy::getBoardRevision() {
Expand Down
23 changes: 21 additions & 2 deletions src/Watchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@
#include <Fonts/FreeMonoBold9pt7b.h>
#include "DSEG7_Classic_Bold_53.h"
#include "Display.h"
#include "WatchyRTC.h"
#include "BLE.h"
#include "bma.h"
#include "config.h"
#include "esp_chip_info.h"
#ifdef ARDUINO_ESP32S3_DEV
#include "Watchy32KRTC.h"
#include "soc/rtc.h"
#include "soc/rtc_io_reg.h"
#include "soc/sens_reg.h"
#include "esp_sleep.h"
#include "rom/rtc.h"
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "time.h"
#include "esp_sntp.h"
#define uS_TO_S_FACTOR 1000000ULL //Conversion factor for micro seconds to seconds
#define ADC_VOLTAGE_DIVIDER ((360.0f+100.0f)/360.0f) //Voltage divider at battery ADC
#else
#include "WatchyRTC.h"
#endif

typedef struct weatherData {
int8_t temperature;
Expand Down Expand Up @@ -47,7 +62,11 @@ typedef struct watchySettings {

class Watchy {
public:
static WatchyRTC RTC;
#ifdef ARDUINO_ESP32S3_DEV
static Watchy32KRTC RTC;
#else
static WatchyRTC RTC;
#endif
static GxEPD2_BW<WatchyDisplay, WatchyDisplay::HEIGHT> display;
tmElements_t currentTime;
watchySettings settings;
Expand Down
Loading

0 comments on commit 7747dcc

Please sign in to comment.