mirror of https://github.com/sqfmi/Watchy.git
Compare commits
19 Commits
a07903f7b2
...
58e909afed
Author | SHA1 | Date |
---|---|---|
SQFMI | 58e909afed | |
SQFMI | 9c0b7e6b45 | |
SQFMI | 819b3319aa | |
SQFMI | b21516f9ee | |
SQFMI | d7bb52d34c | |
Oleg Girko | 1e07dc53d4 | |
SQFMI | 2705fca5ba | |
Oleg Girko | 74b38547fe | |
SQFMI | 41d8917c76 | |
SQFMI | 7747dcc645 | |
SQFMI | 667d86737d | |
SQFMI | d65738fbaa | |
SQFMI | 2dd98737fb | |
SQFMI | 5a5b343737 | |
sqfmi | 2da3fd9ede | |
SQFMI | acbb6eeece | |
sqfmi | c1c95f9587 | |
sqfmi | bd1657e9c7 | |
sqfmi | fbbcaabbd1 |
|
@ -16,6 +16,7 @@ jobs:
|
|||
with:
|
||||
arduino-board-fqbn: esp32:esp32:watchy:Revision=v20,PartitionScheme=min_spiffs,UploadSpeed=921600,DebugLevel=none,EraseFlash=none
|
||||
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
|
||||
arduino-platform: esp32:esp32@2.0.17
|
||||
required-libraries: Adafruit GFX Library,Arduino_JSON,DS3232RTC,NTPClient,Rtc_Pcf8563,GxEPD2,WiFiManager
|
||||
set-build-path: true
|
||||
- uses: actions/upload-artifact@v3
|
||||
|
|
|
@ -7,14 +7,32 @@ jobs:
|
|||
release:
|
||||
name: Build and Release
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
board-revisions: [v10, v15, v20]
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: ArminJo/arduino-test-compile@v3
|
||||
with:
|
||||
arduino-board-fqbn: esp32:esp32:watchy:Revision=v20,PartitionScheme=min_spiffs,UploadSpeed=921600,DebugLevel=none,EraseFlash=none
|
||||
arduino-board-fqbn: esp32:esp32:watchy:Revision=${{ matrix.board-revisions }},PartitionScheme=min_spiffs,UploadSpeed=921600,DebugLevel=none,EraseFlash=none
|
||||
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
|
||||
arduino-platform: esp32:esp32@2.0.17
|
||||
required-libraries: Adafruit GFX Library,Arduino_JSON,DS3232RTC,NTPClient,Rtc_Pcf8563,GxEPD2,WiFiManager
|
||||
set-build-path: true
|
||||
- name: Rename binaries with board revision
|
||||
run: |
|
||||
parent_dir="${{ github.workspace }}/examples/WatchFaces"
|
||||
for dir in "$parent_dir"/*; do
|
||||
if [ -d "$dir" ]; then
|
||||
cd "$dir/build"
|
||||
for file in *; do
|
||||
name="${file%%.*}"
|
||||
ext="${file#$name.}"
|
||||
mv "$file" "$name-${{ matrix.board-revisions }}.$ext"
|
||||
done
|
||||
cd -
|
||||
fi
|
||||
done
|
||||
- uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
name: "Watchy Arduino Library ${{ github.ref_name }}"
|
||||
|
|
|
@ -146,7 +146,7 @@ void Watchy7SEG::drawWeather(){
|
|||
}else
|
||||
return;
|
||||
}else{
|
||||
weatherIcon = cputemp;
|
||||
weatherIcon = chip;
|
||||
}
|
||||
|
||||
display.drawBitmap(145, 158, weatherIcon, WEATHER_ICON_WIDTH, WEATHER_ICON_HEIGHT, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
|
||||
|
|
|
@ -189,7 +189,7 @@ const unsigned char wifioff [] PROGMEM = {
|
|||
0x01, 0xff, 0xc0, 0x00, 0x07, 0xe1, 0xc0, 0x00, 0x0f, 0xc0, 0x80, 0x00, 0x1f, 0x0c, 0x00, 0x00,
|
||||
0x3c, 0x1e, 0x00, 0x00, 0xf8, 0x0c, 0x00, 0x00
|
||||
};
|
||||
// 'chip', 32x32px
|
||||
// 'chip', 48x32px
|
||||
const unsigned char chip [] PROGMEM = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x48, 0x00, 0x00, 0x00, 0x00,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Watchy",
|
||||
"version": "1.4.9",
|
||||
"version": "1.4.13",
|
||||
"description": "Watchy - An Open Source E-Paper Watch by SQFMI",
|
||||
"authors": [
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name=Watchy
|
||||
version=1.4.9
|
||||
version=1.4.13
|
||||
author=SQFMI
|
||||
maintainer=SQFMI
|
||||
sentence=Watchy - An Open Source E-Paper Watch by SQFMI
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
};
|
||||
|
||||
void otaCallback::onWrite(BLECharacteristic *pCharacteristic) {
|
||||
std::string rxData = pCharacteristic->getValue();
|
||||
auto 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,
|
||||
|
@ -127,4 +127,4 @@ bool BLE::begin(const char *localName = "Watchy BLE OTA") {
|
|||
|
||||
int BLE::updateStatus() { return status; }
|
||||
|
||||
int BLE::howManyBytes() { return bytesReceived; }
|
||||
int BLE::howManyBytes() { return bytesReceived; }
|
||||
|
|
|
@ -15,20 +15,24 @@
|
|||
// Link: https://github.com/sqfmi/Watchy
|
||||
|
||||
#include "Display.h"
|
||||
#include "config.h"
|
||||
|
||||
RTC_DATA_ATTR bool displayFullInit = true;
|
||||
|
||||
void WatchyDisplay::busyCallback(const void *) {
|
||||
#ifndef ARDUINO_ESP32S3_DEV
|
||||
gpio_wakeup_enable((gpio_num_t)DISPLAY_BUSY, GPIO_INTR_LOW_LEVEL);
|
||||
esp_sleep_enable_gpio_wakeup();
|
||||
esp_light_sleep_start();
|
||||
#endif
|
||||
}
|
||||
|
||||
WatchyDisplay::WatchyDisplay() :
|
||||
GxEPD2_EPD(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY, HIGH, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
|
||||
{
|
||||
// Setup callback and SPI by default
|
||||
#ifdef ARDUINO_ESP32S3_DEV
|
||||
SPI.begin(WATCHY_V3_SCK,WATCHY_V3_MISO,WATCHY_V3_MOSI,WATCHY_V3_SS);
|
||||
#endif
|
||||
selectSPI(SPI, SPISettings(20000000, MSBFIRST, SPI_MODE0));
|
||||
setBusyCallback(busyCallback);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <GxEPD2_EPD.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "config.h"
|
||||
|
||||
class WatchyDisplay : public GxEPD2_EPD
|
||||
{
|
||||
|
|
118
src/Watchy.cpp
118
src/Watchy.cpp
|
@ -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{});
|
||||
|
||||
|
@ -14,18 +20,28 @@ RTC_DATA_ATTR int weatherIntervalCounter = -1;
|
|||
RTC_DATA_ATTR long gmtOffset = 0;
|
||||
RTC_DATA_ATTR bool alreadyInMenu = true;
|
||||
RTC_DATA_ATTR tmElements_t bootTime;
|
||||
RTC_DATA_ATTR uint32_t lastIPAddress;
|
||||
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:
|
||||
|
@ -68,7 +84,17 @@ 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++) {
|
||||
|
@ -81,6 +107,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
|
||||
gpio_deep_sleep_hold_dis();
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
|
@ -171,7 +199,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
|
||||
|
@ -203,7 +231,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
|
||||
|
@ -215,7 +243,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--;
|
||||
|
@ -224,7 +252,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++;
|
||||
|
@ -313,15 +341,15 @@ void Watchy::showAbout() {
|
|||
display.print("LibVer: ");
|
||||
display.println(WATCHY_LIB_VER);
|
||||
|
||||
const char *RTC_HW[3] = {"<UNKNOWN>", "DS3231", "PCF8563"};
|
||||
display.print("RTC: ");
|
||||
display.println(RTC_HW[RTC.rtcType]); // 0 = UNKNOWN, 1 = DS3231, 2 = PCF8563
|
||||
display.print("Rev: v");
|
||||
display.println(getBoardRevision());
|
||||
|
||||
display.print("Batt: ");
|
||||
float voltage = getBatteryVoltage();
|
||||
display.print(voltage);
|
||||
display.println("V");
|
||||
|
||||
#ifndef ARDUINO_ESP32S3_DEV
|
||||
display.print("Uptime: ");
|
||||
RTC.read(currentTime);
|
||||
time_t b = makeTime(bootTime);
|
||||
|
@ -336,15 +364,16 @@ 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(WiFi.SSID());
|
||||
display.println("IP: ");
|
||||
display.println(WiFi.localIP());
|
||||
WiFi.mode(WIFI_OFF);
|
||||
display.println(lastSSID);
|
||||
display.print("IP: ");
|
||||
display.println(IPAddress(lastIPAddress).toString());
|
||||
}else{
|
||||
display.println("WiFi Not Setup");
|
||||
display.println("WiFi Not Connected");
|
||||
}
|
||||
display.display(false); // full refresh
|
||||
|
||||
|
@ -379,11 +408,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;
|
||||
|
||||
|
@ -398,13 +435,13 @@ 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--;
|
||||
}
|
||||
|
@ -412,7 +449,7 @@ void Watchy::setTime() {
|
|||
|
||||
blink = 1 - blink;
|
||||
|
||||
if (digitalRead(DOWN_BTN_PIN) == 1) {
|
||||
if (digitalRead(DOWN_BTN_PIN) == ACTIVE_LOW) {
|
||||
blink = 1;
|
||||
switch (setIndex) {
|
||||
case SET_HOUR:
|
||||
|
@ -435,7 +472,7 @@ void Watchy::setTime() {
|
|||
}
|
||||
}
|
||||
|
||||
if (digitalRead(UP_BTN_PIN) == 1) {
|
||||
if (digitalRead(UP_BTN_PIN) == ACTIVE_LOW) {
|
||||
blink = 1;
|
||||
switch (setIndex) {
|
||||
case SET_HOUR:
|
||||
|
@ -519,7 +556,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;
|
||||
|
@ -548,7 +589,7 @@ void Watchy::showAccelerometer() {
|
|||
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
if (digitalRead(BACK_BTN_PIN) == 1) {
|
||||
if (digitalRead(BACK_BTN_PIN) == ACTIVE_LOW) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -693,12 +734,41 @@ 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() {
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
if(chip_info.model == CHIP_ESP32){ //Revision 1.0 - 2.0
|
||||
Wire.beginTransmission(0x68); //v1.0 has DS3231
|
||||
if (Wire.endTransmission() == 0){
|
||||
return 10;
|
||||
}
|
||||
delay(1);
|
||||
Wire.beginTransmission(0x51); //v1.5 and v2.0 have PCF8563
|
||||
if (Wire.endTransmission() == 0){
|
||||
pinMode(35, INPUT);
|
||||
if(digitalRead(35) == 0){
|
||||
return 20; //in rev 2.0, pin 35 is BTN 3 and has a pulldown
|
||||
}else{
|
||||
return 15; //in rev 1.5, pin 35 is the battery ADC
|
||||
}
|
||||
}
|
||||
}
|
||||
if(chip_info.model == CHIP_ESP32S3){ //Revision 3.0
|
||||
return 30;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint16_t Watchy::_readRegister(uint8_t address, uint8_t reg, uint8_t *data,
|
||||
|
@ -832,11 +902,13 @@ void Watchy::setupWifi() {
|
|||
display.println("Setup failed &");
|
||||
display.println("timed out!");
|
||||
} else {
|
||||
display.println("Connected to");
|
||||
display.println("Connected to:");
|
||||
display.println(WiFi.SSID());
|
||||
display.println("Local IP:");
|
||||
display.println(WiFi.localIP());
|
||||
weatherIntervalCounter = -1; // Reset to force weather to be read again
|
||||
lastIPAddress = WiFi.localIP();
|
||||
WiFi.SSID().toCharArray(lastSSID, 30);
|
||||
}
|
||||
display.display(false); // full refresh
|
||||
// turn off radios
|
||||
|
@ -871,6 +943,8 @@ bool Watchy::connectWiFi() {
|
|||
} else {
|
||||
if (WL_CONNECTED ==
|
||||
WiFi.waitForConnectResult()) { // attempt to connect for 10s
|
||||
lastIPAddress = WiFi.localIP();
|
||||
WiFi.SSID().toCharArray(lastSSID, 30);
|
||||
WIFI_CONFIGURED = true;
|
||||
} else { // connection failed, time out
|
||||
WIFI_CONFIGURED = false;
|
||||
|
|
25
src/Watchy.h
25
src/Watchy.h
|
@ -12,10 +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;
|
||||
|
@ -46,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;
|
||||
|
@ -56,6 +76,7 @@ public:
|
|||
void init(String datetime = "");
|
||||
void deepSleep();
|
||||
float getBatteryVoltage();
|
||||
uint8_t getBoardRevision();
|
||||
void vibMotor(uint8_t intervalMs = 100, uint8_t length = 20);
|
||||
|
||||
virtual void handleButtonPress();
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
#include "Watchy32KRTC.h"
|
||||
|
||||
Watchy32KRTC::Watchy32KRTC(){}
|
||||
|
||||
void Watchy32KRTC::init() {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
setenv("TZ", "", 1);
|
||||
tzset();
|
||||
|
||||
*/
|
||||
|
||||
void Watchy32KRTC::config(String datetime) { // String datetime format is YYYY:MM:DD:HH:MM:SS
|
||||
struct tm timeInfo;
|
||||
memset(&timeInfo, 0, sizeof(timeInfo));
|
||||
|
||||
// Parse the time string
|
||||
if (strptime(datetime.c_str(), "%Y:%m:%d:%H:%M:%S", &timeInfo) == NULL) {
|
||||
// Failed to parse the time string
|
||||
}
|
||||
|
||||
// Convert tm to timeval
|
||||
struct timeval tv;
|
||||
tv.tv_sec = mktime(&timeInfo);
|
||||
tv.tv_usec = 0;
|
||||
|
||||
// Set the time using settimeofday
|
||||
if (settimeofday(&tv, NULL) != 0) {
|
||||
// Error setting the time
|
||||
}
|
||||
}
|
||||
|
||||
void Watchy32KRTC::clearAlarm() {
|
||||
|
||||
}
|
||||
|
||||
void Watchy32KRTC::read(tmElements_t &tm) {
|
||||
time_t now;
|
||||
struct tm timeInfo;
|
||||
time(&now);
|
||||
// Set timezone to China Standard Time
|
||||
//setenv("TZ", "CST-8", 1);
|
||||
//tzset();
|
||||
localtime_r(&now, &timeInfo);
|
||||
tm.Year = timeInfo.tm_year - 70;
|
||||
tm.Month = timeInfo.tm_mon + 1;
|
||||
tm.Day = timeInfo.tm_mday;
|
||||
tm.Wday = timeInfo.tm_wday + 1;
|
||||
tm.Hour = timeInfo.tm_hour;
|
||||
tm.Minute = timeInfo.tm_min;
|
||||
tm.Second = timeInfo.tm_sec;
|
||||
}
|
||||
|
||||
void Watchy32KRTC::set(tmElements_t tm) {
|
||||
struct tm timeInfo;
|
||||
timeInfo.tm_year = tm.Year + 70;
|
||||
timeInfo.tm_mon = tm.Month - 1;
|
||||
timeInfo.tm_mday = tm.Day;
|
||||
timeInfo.tm_hour = tm.Hour;
|
||||
timeInfo.tm_min = tm.Minute;
|
||||
timeInfo.tm_sec = tm.Second;
|
||||
|
||||
// Convert tm to timeval
|
||||
struct timeval tv;
|
||||
tv.tv_sec = mktime(&timeInfo);
|
||||
tv.tv_usec = 0;
|
||||
|
||||
// Set the time using settimeofday
|
||||
if (settimeofday(&tv, NULL) != 0) {
|
||||
// Error setting the time
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Watchy32KRTC::temperature() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String Watchy32KRTC::_getValue(String data, char separator, int index) {
|
||||
int found = 0;
|
||||
int strIndex[] = {0, -1};
|
||||
int maxIndex = data.length() - 1;
|
||||
|
||||
for (int i = 0; i <= maxIndex && found <= index; i++) {
|
||||
if (data.charAt(i) == separator || i == maxIndex) {
|
||||
found++;
|
||||
strIndex[0] = strIndex[1] + 1;
|
||||
strIndex[1] = (i == maxIndex) ? i + 1 : i;
|
||||
}
|
||||
}
|
||||
|
||||
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
|
||||
}
|
||||
|
||||
void Watchy32KRTC::_timeval_to_tm(struct timeval *tv, struct tm *tm) {
|
||||
// Get the seconds and microseconds from the timeval struct
|
||||
time_t seconds = tv->tv_sec;
|
||||
int microseconds = tv->tv_usec;
|
||||
// Convert the seconds to a tm struct
|
||||
*tm = *localtime(&seconds);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef WATCHY_32K_RTC_H
|
||||
#define WATCHY_32K_RTC_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <TimeLib.h>
|
||||
#include "config.h"
|
||||
|
||||
class Watchy32KRTC {
|
||||
public:
|
||||
Watchy32KRTC();
|
||||
void init();
|
||||
void config(String datetime); //datetime format is YYYY:MM:DD:HH:MM:SS
|
||||
void clearAlarm();
|
||||
void read(tmElements_t &tm);
|
||||
void set(tmElements_t tm);
|
||||
uint8_t temperature();
|
||||
|
||||
private:
|
||||
String _getValue(String data, char separator, int index);
|
||||
void _timeval_to_tm(struct timeval *tv, struct tm *tm);
|
||||
};
|
||||
|
||||
#endif
|
59
src/config.h
59
src/config.h
|
@ -2,15 +2,51 @@
|
|||
#define CONFIG_H
|
||||
|
||||
// Versioning
|
||||
#define WATCHY_LIB_VER "1.4.9"
|
||||
#define WATCHY_LIB_VER "1.4.13"
|
||||
|
||||
//pins
|
||||
|
||||
#ifdef ARDUINO_ESP32S3_DEV //V3
|
||||
|
||||
#define WATCHY_V3_SDA 12
|
||||
#define WATCHY_V3_SCL 11
|
||||
|
||||
#define WATCHY_V3_SS 33
|
||||
#define WATCHY_V3_MOSI 48
|
||||
#define WATCHY_V3_MISO 46
|
||||
#define WATCHY_V3_SCK 47
|
||||
|
||||
#define MENU_BTN_PIN 7
|
||||
#define BACK_BTN_PIN 6
|
||||
#define UP_BTN_PIN 0
|
||||
#define DOWN_BTN_PIN 8
|
||||
|
||||
#define DISPLAY_CS 33
|
||||
#define DISPLAY_DC 34
|
||||
#define DISPLAY_RES 35
|
||||
#define DISPLAY_BUSY 36
|
||||
#define ACC_INT_1_PIN 14
|
||||
#define ACC_INT_2_PIN 13
|
||||
#define VIB_MOTOR_PIN 17
|
||||
#define BATT_ADC_PIN 9
|
||||
#define CHRG_STATUS_PIN 10
|
||||
#define USB_DET_PIN 21
|
||||
#define RTC_INT_PIN -1 //not used
|
||||
|
||||
#define MENU_BTN_MASK (BIT64(7))
|
||||
#define BACK_BTN_MASK (BIT64(6))
|
||||
#define UP_BTN_MASK (BIT64(0))
|
||||
#define DOWN_BTN_MASK (BIT64(8))
|
||||
#define ACC_INT_MASK (BIT64(14))
|
||||
#define BTN_PIN_MASK MENU_BTN_MASK|BACK_BTN_MASK|UP_BTN_MASK|DOWN_BTN_MASK
|
||||
|
||||
#else //V1,V1.5,V2
|
||||
|
||||
#if !defined(ARDUINO_WATCHY_V10) && !defined(ARDUINO_WATCHY_V15) && !defined(ARDUINO_WATCHY_V20)
|
||||
|
||||
#pragma message "Please install the latest ESP32 Arduino Core (2.0.5+) and choose Watchy as the target board"
|
||||
#pragma message "Hardware revision is not defined at the project level, please define in config.h. Defaulting to ARDUINO_WATCHY_V20"
|
||||
|
||||
//Change to your board version
|
||||
#define ARDUINO_WATCHY_V20
|
||||
|
||||
#define MENU_BTN_PIN 26
|
||||
|
@ -28,28 +64,30 @@
|
|||
#if defined (ARDUINO_WATCHY_V10)
|
||||
#define UP_BTN_PIN 32
|
||||
#define BATT_ADC_PIN 33
|
||||
#define UP_BTN_MASK GPIO_SEL_32
|
||||
#define UP_BTN_MASK (BIT64(32))
|
||||
#define RTC_TYPE 1 //DS3231
|
||||
#elif defined (ARDUINO_WATCHY_V15)
|
||||
#define UP_BTN_PIN 32
|
||||
#define BATT_ADC_PIN 35
|
||||
#define UP_BTN_MASK GPIO_SEL_32
|
||||
#define UP_BTN_MASK (BIT64(32))
|
||||
#define RTC_TYPE 2 //PCF8563
|
||||
#elif defined (ARDUINO_WATCHY_V20)
|
||||
#define UP_BTN_PIN 35
|
||||
#define BATT_ADC_PIN 34
|
||||
#define UP_BTN_MASK GPIO_SEL_35
|
||||
#define UP_BTN_MASK (BIT64(35))
|
||||
#define RTC_TYPE 2 //PCF8563
|
||||
#endif
|
||||
|
||||
#define MENU_BTN_MASK GPIO_SEL_26
|
||||
#define BACK_BTN_MASK GPIO_SEL_25
|
||||
#define DOWN_BTN_MASK GPIO_SEL_4
|
||||
#define ACC_INT_MASK GPIO_SEL_14
|
||||
#define MENU_BTN_MASK (BIT64(26))
|
||||
#define BACK_BTN_MASK (BIT64(25))
|
||||
#define DOWN_BTN_MASK (BIT64(4))
|
||||
#define ACC_INT_MASK (BIT64(14))
|
||||
#define BTN_PIN_MASK MENU_BTN_MASK|BACK_BTN_MASK|UP_BTN_MASK|DOWN_BTN_MASK
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//display
|
||||
#define DISPLAY_WIDTH 200
|
||||
#define DISPLAY_HEIGHT 200
|
||||
|
@ -78,4 +116,5 @@
|
|||
#define SOFTWARE_VERSION_PATCH 0
|
||||
#define HARDWARE_VERSION_MAJOR 1
|
||||
#define HARDWARE_VERSION_MINOR 0
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue