Watchy/src/Watchy.h

85 lines
2.6 KiB
C
Raw Normal View History

2021-01-05 00:03:49 -05:00
#ifndef WATCHY_H
#define WATCHY_H
#include <Arduino.h>
#include <WiFiManager.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
#include <GxEPD2_BW.h>
#include <Wire.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include "DSEG7_Classic_Bold_53.h"
#include "WatchyRTC.h"
2021-01-05 00:03:49 -05:00
#include "BLE.h"
#include "bma.h"
#include "config.h"
2021-01-05 00:03:49 -05:00
typedef struct weatherData{
int8_t temperature;
int16_t weatherConditionCode;
2021-12-30 22:47:38 -05:00
bool isMetric;
String weatherDescription;
2021-01-05 00:03:49 -05:00
}weatherData;
2021-12-30 22:47:38 -05:00
typedef struct watchySettings{
//Weather Settings
String cityID;
String weatherAPIKey;
String weatherURL;
String weatherUnit;
String weatherLang;
int8_t weatherUpdateInterval;
//NTP Settings
String ntpServer;
int gmtOffset;
int dstOffset;
}watchySettings;
2021-01-05 00:03:49 -05:00
class Watchy {
public:
static WatchyRTC RTC;
2021-01-05 00:03:49 -05:00
static GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display;
tmElements_t currentTime;
2021-12-30 22:47:38 -05:00
watchySettings settings;
2021-01-05 00:03:49 -05:00
public:
2021-12-30 22:47:38 -05:00
explicit Watchy(const watchySettings& s) : settings(s){} //constructor
2021-01-30 17:09:24 -05:00
void init(String datetime = "");
2021-01-05 00:03:49 -05:00
void deepSleep();
static void displayBusyCallback(const void*);
2021-01-05 00:03:49 -05:00
float getBatteryVoltage();
void vibMotor(uint8_t intervalMs = 100, uint8_t length = 20);
void handleButtonPress();
void showMenu(byte menuIndex, bool partialRefresh);
2021-04-01 15:24:32 -04:00
void showFastMenu(byte menuIndex);
2021-01-05 00:03:49 -05:00
void showBattery();
void showBuzz();
void showAccelerometer();
void showUpdateFW();
2021-12-30 13:02:40 -05:00
void showSyncNTP();
bool syncNTP();
2021-12-30 22:47:38 -05:00
bool syncNTP(long gmt, int dst, String ntpServer);
2021-01-05 00:03:49 -05:00
void setTime();
void setupWifi();
bool connectWiFi();
weatherData getWeatherData();
2021-12-30 22:47:38 -05:00
weatherData getWeatherData(String cityID, String units, String lang, String url, String apiKey, uint8_t updateInterval);
2021-01-05 00:03:49 -05:00
void updateFWBegin();
void showWatchFace(bool partialRefresh);
virtual void drawWatchFace(); //override this method for different watch faces
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);
};
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;
#endif