2021-12-30 23:16:03 -05:00
|
|
|
#ifndef WATCHY_H
|
|
|
|
#define WATCHY_H
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2022-05-06 23:58:07 -04:00
|
|
|
#include <WiFiManager.h>
|
2021-12-30 23:16:03 -05:00
|
|
|
#include <HTTPClient.h>
|
2022-01-03 21:41:36 -05:00
|
|
|
#include <NTPClient.h>
|
|
|
|
#include <WiFiUdp.h>
|
2022-05-06 23:58:07 -04:00
|
|
|
#include <Arduino_JSON.h>
|
|
|
|
#include <GxEPD2_BW.h>
|
2021-12-30 23:16:03 -05:00
|
|
|
#include <Wire.h>
|
2022-05-06 23:58:07 -04:00
|
|
|
#include <Fonts/FreeMonoBold9pt7b.h>
|
|
|
|
#include "DSEG7_Classic_Bold_53.h"
|
2022-08-03 12:08:12 -04:00
|
|
|
#include "Display.h"
|
2022-05-06 23:58:07 -04:00
|
|
|
#include "BLE.h"
|
|
|
|
#include "bma.h"
|
|
|
|
#include "config.h"
|
2024-04-03 15:10:09 -04:00
|
|
|
#include "esp_chip_info.h"
|
2024-07-02 00:50:47 -04:00
|
|
|
#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"
|
2024-07-06 01:38:48 -04:00
|
|
|
#include "hal/rtc_io_types.h"
|
|
|
|
#include "driver/rtc_io.h"
|
2024-07-02 00:50:47 -04:00
|
|
|
#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
|
2021-12-30 23:16:03 -05:00
|
|
|
|
2022-04-28 21:17:00 -04:00
|
|
|
typedef struct weatherData {
|
|
|
|
int8_t temperature;
|
|
|
|
int16_t weatherConditionCode;
|
|
|
|
bool isMetric;
|
|
|
|
String weatherDescription;
|
2022-12-29 08:08:24 -05:00
|
|
|
bool external;
|
2023-06-16 00:17:20 -04:00
|
|
|
tmElements_t sunrise;
|
|
|
|
tmElements_t sunset;
|
2022-04-28 21:17:00 -04:00
|
|
|
} weatherData;
|
2021-12-30 23:16:03 -05:00
|
|
|
|
2022-04-28 21:17:00 -04:00
|
|
|
typedef struct watchySettings {
|
|
|
|
// Weather Settings
|
|
|
|
String cityID;
|
2023-06-16 00:17:20 -04:00
|
|
|
String lat;
|
|
|
|
String lon;
|
2022-04-28 21:17:00 -04:00
|
|
|
String weatherAPIKey;
|
|
|
|
String weatherURL;
|
|
|
|
String weatherUnit;
|
|
|
|
String weatherLang;
|
|
|
|
int8_t weatherUpdateInterval;
|
|
|
|
// NTP Settings
|
|
|
|
String ntpServer;
|
|
|
|
int gmtOffset;
|
2022-10-15 09:34:52 -04:00
|
|
|
//
|
|
|
|
bool vibrateOClock;
|
2022-04-28 21:17:00 -04:00
|
|
|
} watchySettings;
|
2021-12-30 23:16:03 -05:00
|
|
|
|
|
|
|
class Watchy {
|
2022-04-28 21:17:00 -04:00
|
|
|
public:
|
2024-07-02 00:50:47 -04:00
|
|
|
#ifdef ARDUINO_ESP32S3_DEV
|
|
|
|
static Watchy32KRTC RTC;
|
|
|
|
#else
|
|
|
|
static WatchyRTC RTC;
|
|
|
|
#endif
|
2022-08-03 12:08:12 -04:00
|
|
|
static GxEPD2_BW<WatchyDisplay, WatchyDisplay::HEIGHT> display;
|
2022-04-28 21:17:00 -04:00
|
|
|
tmElements_t currentTime;
|
|
|
|
watchySettings settings;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Watchy(const watchySettings &s) : settings(s) {} // constructor
|
|
|
|
void init(String datetime = "");
|
|
|
|
void deepSleep();
|
|
|
|
float getBatteryVoltage();
|
2024-04-03 15:10:09 -04:00
|
|
|
uint8_t getBoardRevision();
|
2022-04-28 21:17:00 -04:00
|
|
|
void vibMotor(uint8_t intervalMs = 100, uint8_t length = 20);
|
2021-12-30 23:16:03 -05:00
|
|
|
|
2022-12-30 11:14:13 -05:00
|
|
|
virtual void handleButtonPress();
|
2022-04-28 21:17:00 -04:00
|
|
|
void showMenu(byte menuIndex, bool partialRefresh);
|
|
|
|
void showFastMenu(byte menuIndex);
|
|
|
|
void showAbout();
|
|
|
|
void showBuzz();
|
|
|
|
void showAccelerometer();
|
|
|
|
void showUpdateFW();
|
|
|
|
void showSyncNTP();
|
|
|
|
bool syncNTP();
|
2022-10-14 22:23:06 -04:00
|
|
|
bool syncNTP(long gmt);
|
|
|
|
bool syncNTP(long gmt, String ntpServer);
|
2022-04-28 21:17:00 -04:00
|
|
|
void setTime();
|
|
|
|
void setupWifi();
|
|
|
|
bool connectWiFi();
|
|
|
|
weatherData getWeatherData();
|
|
|
|
void updateFWBegin();
|
2021-12-30 23:16:03 -05:00
|
|
|
|
2022-04-28 21:17:00 -04:00
|
|
|
void showWatchFace(bool partialRefresh);
|
|
|
|
virtual void drawWatchFace(); // override this method for different watch
|
|
|
|
// faces
|
2021-12-30 23:16:03 -05:00
|
|
|
|
2022-04-28 21:17:00 -04:00
|
|
|
private:
|
|
|
|
void _bmaConfig();
|
|
|
|
static void _configModeCallback(WiFiManager *myWiFiManager);
|
|
|
|
static uint16_t _readRegister(uint8_t address, uint8_t reg, uint8_t *data,
|
|
|
|
uint16_t len);
|
|
|
|
static uint16_t _writeRegister(uint8_t address, uint8_t reg, uint8_t *data,
|
|
|
|
uint16_t len);
|
2024-04-02 14:13:15 -04:00
|
|
|
weatherData _getWeatherData(String cityID, String lat, String lon, String units, String lang,
|
|
|
|
String url, String apiKey, uint8_t updateInterval);
|
2021-12-30 23:16:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
extern RTC_DATA_ATTR int guiState;
|
|
|
|
extern RTC_DATA_ATTR int menuIndex;
|
|
|
|
extern RTC_DATA_ATTR BMA423 sensor;
|
|
|
|
extern RTC_DATA_ATTR bool WIFI_CONFIGURED;
|
|
|
|
extern RTC_DATA_ATTR bool BLE_CONFIGURED;
|
2024-07-06 01:38:48 -04:00
|
|
|
extern RTC_DATA_ATTR bool USB_PLUGGED_IN;
|
2021-12-30 23:16:03 -05:00
|
|
|
|
2022-01-05 03:25:22 -05:00
|
|
|
#endif
|