Finaly can build.

pull/156/head
Michael-Paul Moore 2022-04-11 13:31:21 -07:00
parent 8e6c4a5693
commit 4e8f5fc1fb
7 changed files with 51 additions and 1121 deletions

View File

@ -20,6 +20,8 @@
{ "name": "Arduino_JSON" },
{ "name": "DS3232RTC" },
{ "name": "NTPClient" },
{ "name": "ESP32 BLE Arduino" },
{ "name": "Adafruit BusIO" },
{
"name": "Rtc_Pcf8563",
"version": "https://github.com/orbitalair/Rtc_Pcf8563.git#master"

View File

@ -1,5 +1,8 @@
#include "BLE.h"
// Expanded
#include "watchy_config.h"
#define SERVICE_UUID_ESPOTA "cd77498e-1ac8-48b6-aba8-4161c7342fce"
#define CHARACTERISTIC_UUID_ID "cd77498f-1ac8-48b6-aba8-4161c7342fce"

File diff suppressed because it is too large Load Diff

View File

@ -1,90 +0,0 @@
#pragma once
#include <Arduino.h>
#include <WiFiManager.h>
#include <HTTPClient.h>
#include <NTPClient.h>
#include <WiFiUdp.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"
#include "BLE.h"
#include "bma.h"
#include "config.h"
typedef struct weatherData{
int8_t temperature;
int16_t weatherConditionCode;
bool isMetric;
String weatherDescription;
}weatherData;
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;
class Watchy
{
public:
static WatchyRTC RTC;
static GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display;
tmElements_t currentTime;
watchySettings settings;
public:
explicit Watchy(const watchySettings& s) : settings(s){} //constructor
void init(String datetime = "");
void deepSleep();
static void displayBusyCallback(const void*);
float getBatteryVoltage();
void vibMotor(uint8_t intervalMs = 100, uint8_t length = 20);
void handleButtonPress();
void showMenu(byte menuIndex, bool partialRefresh);
void showFastMenu(byte menuIndex);
void showAbout();
void showBuzz();
void showAccelerometer();
void showUpdateFW();
void showSyncNTP();
bool syncNTP();
bool syncNTP(long gmt, int dst, String ntpServer);
void setTime();
void setupWifi();
bool connectWiFi();
weatherData getWeatherData();
weatherData getWeatherData(String cityID, String units, String lang, String url, String apiKey, uint8_t updateInterval);
void updateFWBegin();
void showWatchFace(bool partialRefresh);
virtual void drawWatchFace(); //override this method for different watch faces
// Expanded
JSONVar& getWeatherJSON();
JSONVar& getWeatherJSON(String cityID, String units, String lang, String url, String apiKey,
uint8_t updateInterval);
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;

View File

@ -9,10 +9,7 @@
// Fonts
#include <Fonts/FreeMonoBold9pt7b.h>
// Watchy
#include "WatchyRTC.h"
CWatchyExpanded::CWatchyExpanded() : m_display(GxEPD2_154_D67(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY))
CWatchyExpanded::CWatchyExpanded() : m_display(GxEPD2_154_D67(wcd::cs, wcd::dc, wcd::reset, wcd::busy))
{
}
@ -25,7 +22,7 @@ void CWatchyExpanded::Init()
{
const esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); //get wake up reason
Wire.begin(SDA, SCL); //init i2c
RTC.init();
m_rtc.init();
// Init the display here for all cases, if unused, it will do nothing
m_display.init(0, true, 10, true); // 10ms by spec, and fast pulldown reset
@ -34,9 +31,9 @@ void CWatchyExpanded::Init()
switch (wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0: //RTC Alarm
if(m_guiState == kWatchFace_State)
if(m_guiState == wc::kWatchFace_State)
{
RTC.read(m_currentTime);
m_rtc.read(m_currentTime);
UpdateScreen(); //partial updates on tick
}
break;
@ -55,7 +52,7 @@ void CWatchyExpanded::Init()
void CWatchyExpanded::DisplayBusyCallback(const void*)
{
gpio_wakeup_enable((gpio_num_t)BUSY, GPIO_INTR_LOW_LEVEL);
gpio_wakeup_enable(static_cast<gpio_num_t>(wcd::busy), GPIO_INTR_LOW_LEVEL);
esp_sleep_enable_gpio_wakeup();
esp_light_sleep_start();
}
@ -67,7 +64,7 @@ void CWatchyExpanded::UpdateScreen()
DrawBasicClock(); // Temp
m_display.display(true); //partial refresh
m_guiState = kWatchFace_State;
m_guiState = wc::kWatchFace_State;
}
void CWatchyExpanded::DrawBasicClock()
@ -98,12 +95,12 @@ void CWatchyExpanded::DrawBasicClock()
void CWatchyExpanded::DeepSleep()
{
m_display.hibernate();
RTC.clearAlarm(); //resets the alarm flag in the RTC
m_rtc.clearAlarm(); //resets the alarm flag in the RTC
for(int i=0; i<40; i++) // Set pins 0-39 to input to avoid power leaking out
pinMode(i, INPUT);
esp_sleep_enable_ext0_wakeup((gpio_num_t)RTC_INT_PIN, 0); //enable deep sleep wake on RTC interrupt
esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press
esp_sleep_enable_ext0_wakeup(wc::rtc_pin, 0); //enable deep sleep wake on RTC interrupt
esp_sleep_enable_ext1_wakeup(wc::btn_pin_mask, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press
esp_deep_sleep_start();
}

View File

@ -10,10 +10,11 @@
#include <TimeLib.h>
// Watchy
#include "config.h"
#include "WatchyRTC.h"
// Expanded
#include "WatchFace.h"
#include "watchy_config.h"
// Defs
class CWatchFace;
@ -40,5 +41,6 @@ class CWatchyExpanded
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> m_display;
tmElements_t m_currentTime;
std::int8_t m_guiState = kWatchFace_State;
std::int8_t m_guiState = wc::kWatchFace_State;
WatchyRTC m_rtc;
};

View File

@ -1,14 +1,9 @@
#pragma once
//display
#define DISPLAY_WIDTH 200
#define DISPLAY_HEIGHT 200
#define BTN_PIN_MASK MENU_BTN_MASK|BACK_BTN_MASK|UP_BTN_MASK|DOWN_BTN_MASK
//wifi
#define WIFI_AP_TIMEOUT 60
#define WIFI_AP_SSID "Watchy AP"
//menu
constexpr std::int8_t kWatchFace_State{-1};
#define MAIN_MENU_STATE 0
#define APP_STATE 1
#define FW_UPDATE_STATE 2
@ -31,3 +26,36 @@ constexpr std::int8_t kWatchFace_State{-1};
#define HARDWARE_VERSION_MINOR 0
//Versioning
#define WATCHY_LIB_VER "1.4.0"
namespace watchy_config
{
// Menu
constexpr std::int8_t kWatchFace_State{-1};
namespace display
{
// Display
#define DISPLAY_WIDTH 200
#define DISPLAY_HEIGHT 200
// display pins
constexpr std::uint8_t cs{5}; // Unsure what this means.
constexpr std::uint8_t dc{10}; // Unsure what this means.
constexpr std::uint8_t reset{9};
constexpr std::uint8_t busy{19};
};
// RTC pins
constexpr gpio_num_t rtc_pin{GPIO_NUM_27};
// btn pins & masks
constexpr std::uint64_t menu_btn_mask{GPIO_SEL_26};
constexpr std::uint64_t back_btn_mask{GPIO_SEL_25};
constexpr std::uint64_t up_btn_mask{GPIO_SEL_32};
constexpr std::uint64_t down_btn_mask{GPIO_SEL_4};
constexpr std::uint64_t btn_pin_mask{menu_btn_mask|back_btn_mask|up_btn_mask|down_btn_mask};
};
namespace wc = watchy_config;
namespace wcd = watchy_config::display;