mirror of https://github.com/sqfmi/Watchy.git
Whitespace changes
parent
80c4444576
commit
c5c83300da
366
src/Watchy.cpp
366
src/Watchy.cpp
|
@ -1,6 +1,6 @@
|
||||||
#include "Watchy.h"
|
#include "Watchy.h"
|
||||||
|
|
||||||
DS3232RTC Watchy::RTC(false);
|
DS3232RTC Watchy::RTC(false);
|
||||||
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> Watchy::display(GxEPD2_154_D67(CS, DC, RESET, BUSY));
|
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> Watchy::display(GxEPD2_154_D67(CS, DC, RESET, BUSY));
|
||||||
|
|
||||||
RTC_DATA_ATTR int guiState;
|
RTC_DATA_ATTR int guiState;
|
||||||
|
@ -51,10 +51,10 @@ void Watchy::init(String datetime){
|
||||||
tm.Second = 0;
|
tm.Second = 0;
|
||||||
time_t t = makeTime(tm);
|
time_t t = makeTime(tm);
|
||||||
RTC.set(t);
|
RTC.set(t);
|
||||||
RTC.read(currentTime);
|
RTC.read(currentTime);
|
||||||
showWatchFace(true); //partial updates on tick
|
showWatchFace(true); //partial updates on tick
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case ESP_SLEEP_WAKEUP_EXT0: //RTC Alarm
|
case ESP_SLEEP_WAKEUP_EXT0: //RTC Alarm
|
||||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||||
|
@ -80,10 +80,10 @@ void Watchy::init(String datetime){
|
||||||
void Watchy::deepSleep(){
|
void Watchy::deepSleep(){
|
||||||
#ifndef ESP_RTC
|
#ifndef ESP_RTC
|
||||||
esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt
|
esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP_RTC
|
#ifdef ESP_RTC
|
||||||
esp_sleep_enable_timer_wakeup(60000000);
|
esp_sleep_enable_timer_wakeup(60000000);
|
||||||
#endif
|
#endif
|
||||||
esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press
|
esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ void Watchy::_rtcConfig(String datetime){
|
||||||
if(datetime != NULL){
|
if(datetime != NULL){
|
||||||
const time_t FUDGE(30);//fudge factor to allow for upload time, etc. (seconds, YMMV)
|
const time_t FUDGE(30);//fudge factor to allow for upload time, etc. (seconds, YMMV)
|
||||||
tmElements_t tm;
|
tmElements_t tm;
|
||||||
tm.Year = getValue(datetime, ':', 0).toInt() - YEAR_OFFSET;//offset from 1970, since year is stored in uint8_t
|
tm.Year = getValue(datetime, ':', 0).toInt() - YEAR_OFFSET;//offset from 1970, since year is stored in uint8_t
|
||||||
tm.Month = getValue(datetime, ':', 1).toInt();
|
tm.Month = getValue(datetime, ':', 1).toInt();
|
||||||
tm.Day = getValue(datetime, ':', 2).toInt();
|
tm.Day = getValue(datetime, ':', 2).toInt();
|
||||||
tm.Hour = getValue(datetime, ':', 3).toInt();
|
tm.Hour = getValue(datetime, ':', 3).toInt();
|
||||||
|
@ -112,146 +112,144 @@ void Watchy::_rtcConfig(String datetime){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::handleButtonPress(){
|
void Watchy::handleButtonPress(){
|
||||||
uint64_t wakeupBit = esp_sleep_get_ext1_wakeup_status();
|
uint64_t wakeupBit = esp_sleep_get_ext1_wakeup_status();
|
||||||
//Menu Button
|
//Menu Button
|
||||||
if (wakeupBit & MENU_BTN_MASK){
|
if (wakeupBit & MENU_BTN_MASK) {
|
||||||
if(guiState == WATCHFACE_STATE){//enter menu state if coming from watch face
|
if (guiState == WATCHFACE_STATE) {//enter menu state if coming from watch face
|
||||||
showMenu(menuIndex, false);
|
showMenu(menuIndex, false);
|
||||||
}else if(guiState == MAIN_MENU_STATE){//if already in menu, then select menu item
|
} else if (guiState == MAIN_MENU_STATE) {//if already in menu, then select menu item
|
||||||
switch(menuIndex)
|
switch(menuIndex) {
|
||||||
{
|
case 0:
|
||||||
case 0:
|
showBattery();
|
||||||
showBattery();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
showBuzz();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
showAccelerometer();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
setTime();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
setupWifi();
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
showUpdateFW();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else if(guiState == FW_UPDATE_STATE){
|
|
||||||
updateFWBegin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Back Button
|
|
||||||
else if (wakeupBit & BACK_BTN_MASK){
|
|
||||||
if(guiState == MAIN_MENU_STATE){//exit to watch face if already in menu
|
|
||||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
|
||||||
RTC.read(currentTime);
|
|
||||||
showWatchFace(false);
|
|
||||||
}else if(guiState == APP_STATE){
|
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
|
||||||
}else if(guiState == FW_UPDATE_STATE){
|
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Up Button
|
|
||||||
else if (wakeupBit & UP_BTN_MASK){
|
|
||||||
if(guiState == MAIN_MENU_STATE){//increment menu index
|
|
||||||
menuIndex--;
|
|
||||||
if(menuIndex < 0){
|
|
||||||
menuIndex = MENU_LENGTH - 1;
|
|
||||||
}
|
|
||||||
showMenu(menuIndex, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Down Button
|
|
||||||
else if (wakeupBit & DOWN_BTN_MASK){
|
|
||||||
if(guiState == MAIN_MENU_STATE){//decrement menu index
|
|
||||||
menuIndex++;
|
|
||||||
if(menuIndex > MENU_LENGTH - 1){
|
|
||||||
menuIndex = 0;
|
|
||||||
}
|
|
||||||
showMenu(menuIndex, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************** fast menu *****************/
|
|
||||||
bool timeout = false;
|
|
||||||
long lastTimeout = millis();
|
|
||||||
pinMode(MENU_BTN_PIN, INPUT);
|
|
||||||
pinMode(BACK_BTN_PIN, INPUT);
|
|
||||||
pinMode(UP_BTN_PIN, INPUT);
|
|
||||||
pinMode(DOWN_BTN_PIN, INPUT);
|
|
||||||
while(!timeout){
|
|
||||||
if(millis() - lastTimeout > 5000){
|
|
||||||
timeout = true;
|
|
||||||
}else{
|
|
||||||
if(digitalRead(MENU_BTN_PIN) == 1){
|
|
||||||
lastTimeout = millis();
|
|
||||||
if(guiState == MAIN_MENU_STATE){//if already in menu, then select menu item
|
|
||||||
switch(menuIndex)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
showBattery();
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
showBuzz();
|
showBuzz();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
showAccelerometer();
|
showAccelerometer();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
setTime();
|
setTime();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
setupWifi();
|
setupWifi();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
showUpdateFW();
|
showUpdateFW();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}else if(guiState == FW_UPDATE_STATE){
|
|
||||||
updateFWBegin();
|
|
||||||
}
|
}
|
||||||
}else if(digitalRead(BACK_BTN_PIN) == 1){
|
} else if(guiState == FW_UPDATE_STATE) {
|
||||||
lastTimeout = millis();
|
updateFWBegin();
|
||||||
if(guiState == MAIN_MENU_STATE){//exit to watch face if already in menu
|
}
|
||||||
|
}
|
||||||
|
//Back Button
|
||||||
|
else if (wakeupBit & BACK_BTN_MASK) {
|
||||||
|
if (guiState == MAIN_MENU_STATE) {//exit to watch face if already in menu
|
||||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||||
RTC.read(currentTime);
|
RTC.read(currentTime);
|
||||||
showWatchFace(false);
|
showWatchFace(false);
|
||||||
break; //leave loop
|
} else if (guiState == APP_STATE) {
|
||||||
}else if(guiState == APP_STATE){
|
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
showMenu(menuIndex, false);//exit to menu if already in app
|
||||||
}else if(guiState == FW_UPDATE_STATE){
|
} else if (guiState == FW_UPDATE_STATE) {
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
showMenu(menuIndex, false);//exit to menu if already in app
|
||||||
}
|
}
|
||||||
}else if(digitalRead(UP_BTN_PIN) == 1){
|
}
|
||||||
lastTimeout = millis();
|
//Up Button
|
||||||
if(guiState == MAIN_MENU_STATE){//increment menu index
|
else if (wakeupBit & UP_BTN_MASK) {
|
||||||
|
if(guiState == MAIN_MENU_STATE) {//increment menu index
|
||||||
menuIndex--;
|
menuIndex--;
|
||||||
if(menuIndex < 0){
|
if(menuIndex < 0){
|
||||||
menuIndex = MENU_LENGTH - 1;
|
menuIndex = MENU_LENGTH - 1;
|
||||||
}
|
}
|
||||||
showFastMenu(menuIndex);
|
showMenu(menuIndex, true);
|
||||||
}
|
}
|
||||||
}else if(digitalRead(DOWN_BTN_PIN) == 1){
|
}
|
||||||
lastTimeout = millis();
|
//Down Button
|
||||||
if(guiState == MAIN_MENU_STATE){//decrement menu index
|
else if (wakeupBit & DOWN_BTN_MASK) {
|
||||||
|
if(guiState == MAIN_MENU_STATE){//decrement menu index
|
||||||
menuIndex++;
|
menuIndex++;
|
||||||
if(menuIndex > MENU_LENGTH - 1){
|
if(menuIndex > MENU_LENGTH - 1) {
|
||||||
menuIndex = 0;
|
menuIndex = 0;
|
||||||
}
|
}
|
||||||
showFastMenu(menuIndex);
|
showMenu(menuIndex, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
/***************** fast menu *****************/
|
||||||
display.hibernate();
|
bool timeout = false;
|
||||||
|
long lastTimeout = millis();
|
||||||
|
pinMode(MENU_BTN_PIN, INPUT);
|
||||||
|
pinMode(BACK_BTN_PIN, INPUT);
|
||||||
|
pinMode(UP_BTN_PIN, INPUT);
|
||||||
|
pinMode(DOWN_BTN_PIN, INPUT);
|
||||||
|
while(!timeout) {
|
||||||
|
if (millis() - lastTimeout > 5000) {
|
||||||
|
timeout = true;
|
||||||
|
} else {
|
||||||
|
if (digitalRead(MENU_BTN_PIN) == 1) {
|
||||||
|
lastTimeout = millis();
|
||||||
|
if (guiState == MAIN_MENU_STATE) {//if already in menu, then select menu item
|
||||||
|
switch(menuIndex) {
|
||||||
|
case 0:
|
||||||
|
showBattery();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
showBuzz();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
showAccelerometer();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
setTime();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
setupWifi();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
showUpdateFW();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (guiState == FW_UPDATE_STATE) {
|
||||||
|
updateFWBegin();
|
||||||
|
}
|
||||||
|
} else if (digitalRead(BACK_BTN_PIN) == 1) {
|
||||||
|
lastTimeout = millis();
|
||||||
|
if (guiState == MAIN_MENU_STATE) {//exit to watch face if already in menu
|
||||||
|
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||||
|
RTC.read(currentTime);
|
||||||
|
showWatchFace(false);
|
||||||
|
break; //leave loop
|
||||||
|
} else if (guiState == APP_STATE) {
|
||||||
|
showMenu(menuIndex, false);//exit to menu if already in app
|
||||||
|
} else if (guiState == FW_UPDATE_STATE) {
|
||||||
|
showMenu(menuIndex, false);//exit to menu if already in app
|
||||||
|
}
|
||||||
|
} else if (digitalRead(UP_BTN_PIN) == 1) {
|
||||||
|
lastTimeout = millis();
|
||||||
|
if (guiState == MAIN_MENU_STATE) {//increment menu index
|
||||||
|
menuIndex--;
|
||||||
|
if(menuIndex < 0){
|
||||||
|
menuIndex = MENU_LENGTH - 1;
|
||||||
|
}
|
||||||
|
showFastMenu(menuIndex);
|
||||||
|
}
|
||||||
|
} else if (digitalRead(DOWN_BTN_PIN) == 1) {
|
||||||
|
lastTimeout = millis();
|
||||||
|
if (guiState == MAIN_MENU_STATE) {//decrement menu index
|
||||||
|
menuIndex++;
|
||||||
|
if (menuIndex > MENU_LENGTH - 1) {
|
||||||
|
menuIndex = 0;
|
||||||
|
}
|
||||||
|
showFastMenu(menuIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display.hibernate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::showMenu(byte menuIndex, bool partialRefresh){
|
void Watchy::showMenu(byte menuIndex, bool partialRefresh){
|
||||||
|
@ -265,24 +263,24 @@ void Watchy::showMenu(byte menuIndex, bool partialRefresh){
|
||||||
int16_t yPos;
|
int16_t yPos;
|
||||||
|
|
||||||
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware"};
|
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware"};
|
||||||
for(int i=0; i<MENU_LENGTH; i++){
|
for (int i=0; i<MENU_LENGTH; i++) {
|
||||||
yPos = 30+(MENU_HEIGHT*i);
|
yPos = 30+(MENU_HEIGHT*i);
|
||||||
display.setCursor(0, yPos);
|
display.setCursor(0, yPos);
|
||||||
if(i == menuIndex){
|
if (i == menuIndex) {
|
||||||
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
||||||
display.fillRect(x1-1, y1-10, 200, h+15, GxEPD_WHITE);
|
display.fillRect(x1-1, y1-10, 200, h+15, GxEPD_WHITE);
|
||||||
display.setTextColor(GxEPD_BLACK);
|
display.setTextColor(GxEPD_BLACK);
|
||||||
display.println(menuItems[i]);
|
display.println(menuItems[i]);
|
||||||
}else{
|
} else {
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
display.println(menuItems[i]);
|
display.println(menuItems[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display.display(partialRefresh);
|
display.display(partialRefresh);
|
||||||
//display.hibernate();
|
//display.hibernate();
|
||||||
|
|
||||||
guiState = MAIN_MENU_STATE;
|
guiState = MAIN_MENU_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::showFastMenu(byte menuIndex){
|
void Watchy::showFastMenu(byte menuIndex){
|
||||||
|
@ -295,23 +293,23 @@ void Watchy::showFastMenu(byte menuIndex){
|
||||||
int16_t yPos;
|
int16_t yPos;
|
||||||
|
|
||||||
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware"};
|
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware"};
|
||||||
for(int i=0; i<MENU_LENGTH; i++){
|
for (int i=0; i<MENU_LENGTH; i++) {
|
||||||
yPos = 30+(MENU_HEIGHT*i);
|
yPos = 30+(MENU_HEIGHT*i);
|
||||||
display.setCursor(0, yPos);
|
display.setCursor(0, yPos);
|
||||||
if(i == menuIndex){
|
if (i == menuIndex) {
|
||||||
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
||||||
display.fillRect(x1-1, y1-10, 200, h+15, GxEPD_WHITE);
|
display.fillRect(x1-1, y1-10, 200, h+15, GxEPD_WHITE);
|
||||||
display.setTextColor(GxEPD_BLACK);
|
display.setTextColor(GxEPD_BLACK);
|
||||||
display.println(menuItems[i]);
|
display.println(menuItems[i]);
|
||||||
}else{
|
} else {
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
display.println(menuItems[i]);
|
display.println(menuItems[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display.display(true);
|
display.display(true);
|
||||||
|
|
||||||
guiState = MAIN_MENU_STATE;
|
guiState = MAIN_MENU_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::showBattery(){
|
void Watchy::showBattery(){
|
||||||
|
@ -329,7 +327,7 @@ void Watchy::showBattery(){
|
||||||
display.display(false); //full refresh
|
display.display(false); //full refresh
|
||||||
display.hibernate();
|
display.hibernate();
|
||||||
|
|
||||||
guiState = APP_STATE;
|
guiState = APP_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::showBuzz(){
|
void Watchy::showBuzz(){
|
||||||
|
@ -343,7 +341,7 @@ void Watchy::showBuzz(){
|
||||||
display.display(false); //full refresh
|
display.display(false); //full refresh
|
||||||
display.hibernate();
|
display.hibernate();
|
||||||
vibMotor();
|
vibMotor();
|
||||||
showMenu(menuIndex, false);
|
showMenu(menuIndex, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::vibMotor(uint8_t intervalMs, uint8_t length){
|
void Watchy::vibMotor(uint8_t intervalMs, uint8_t length){
|
||||||
|
@ -374,8 +372,8 @@ void Watchy::setTime(){
|
||||||
|
|
||||||
pinMode(DOWN_BTN_PIN, INPUT);
|
pinMode(DOWN_BTN_PIN, INPUT);
|
||||||
pinMode(UP_BTN_PIN, INPUT);
|
pinMode(UP_BTN_PIN, INPUT);
|
||||||
pinMode(MENU_BTN_PIN, INPUT);
|
pinMode(MENU_BTN_PIN, INPUT);
|
||||||
pinMode(BACK_BTN_PIN, INPUT);
|
pinMode(BACK_BTN_PIN, INPUT);
|
||||||
|
|
||||||
display.init(0, true); //_initial_refresh to false to prevent full update on init
|
display.init(0, true); //_initial_refresh to false to prevent full update on init
|
||||||
display.setFullWindow();
|
display.setFullWindow();
|
||||||
|
@ -392,7 +390,7 @@ void Watchy::setTime(){
|
||||||
if(setIndex != SET_HOUR){
|
if(setIndex != SET_HOUR){
|
||||||
setIndex--;
|
setIndex--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blink = 1 - blink;
|
blink = 1 - blink;
|
||||||
|
|
||||||
|
@ -413,10 +411,10 @@ void Watchy::setTime(){
|
||||||
break;
|
break;
|
||||||
case SET_DAY:
|
case SET_DAY:
|
||||||
day == 31 ? (day = 1) : day++;
|
day == 31 ? (day = 1) : day++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(digitalRead(UP_BTN_PIN) == 1){
|
if(digitalRead(UP_BTN_PIN) == 1){
|
||||||
|
@ -436,11 +434,11 @@ void Watchy::setTime(){
|
||||||
break;
|
break;
|
||||||
case SET_DAY:
|
case SET_DAY:
|
||||||
day == 1 ? (day = 31) : day--;
|
day == 1 ? (day = 31) : day--;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display.fillScreen(GxEPD_BLACK);
|
display.fillScreen(GxEPD_BLACK);
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
|
@ -451,7 +449,7 @@ void Watchy::setTime(){
|
||||||
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
if(hour < 10){
|
if(hour < 10){
|
||||||
display.print("0");
|
display.print("0");
|
||||||
}
|
}
|
||||||
display.print(hour);
|
display.print(hour);
|
||||||
|
|
||||||
|
@ -463,7 +461,7 @@ void Watchy::setTime(){
|
||||||
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
if(minute < 10){
|
if(minute < 10){
|
||||||
display.print("0");
|
display.print("0");
|
||||||
}
|
}
|
||||||
display.print(minute);
|
display.print(minute);
|
||||||
|
|
||||||
|
@ -473,7 +471,7 @@ void Watchy::setTime(){
|
||||||
display.setCursor(45, 150);
|
display.setCursor(45, 150);
|
||||||
if(setIndex == SET_YEAR){//blink minute digits
|
if(setIndex == SET_YEAR){//blink minute digits
|
||||||
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
display.print(2000+year);
|
display.print(2000+year);
|
||||||
|
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
|
@ -481,10 +479,10 @@ void Watchy::setTime(){
|
||||||
|
|
||||||
if(setIndex == SET_MONTH){//blink minute digits
|
if(setIndex == SET_MONTH){//blink minute digits
|
||||||
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
if(month < 10){
|
if(month < 10){
|
||||||
display.print("0");
|
display.print("0");
|
||||||
}
|
}
|
||||||
display.print(month);
|
display.print(month);
|
||||||
|
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
|
@ -492,11 +490,11 @@ void Watchy::setTime(){
|
||||||
|
|
||||||
if(setIndex == SET_DAY){//blink minute digits
|
if(setIndex == SET_DAY){//blink minute digits
|
||||||
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
if(day < 10){
|
if(day < 10){
|
||||||
display.print("0");
|
display.print("0");
|
||||||
}
|
}
|
||||||
display.print(day);
|
display.print(day);
|
||||||
display.display(true); //partial refresh
|
display.display(true); //partial refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +526,7 @@ void Watchy::showAccelerometer(){
|
||||||
Accel acc;
|
Accel acc;
|
||||||
|
|
||||||
long previousMillis = 0;
|
long previousMillis = 0;
|
||||||
long interval = 200;
|
long interval = 200;
|
||||||
|
|
||||||
guiState = APP_STATE;
|
guiState = APP_STATE;
|
||||||
|
|
||||||
|
@ -547,7 +545,7 @@ void Watchy::showAccelerometer(){
|
||||||
// Get acceleration data
|
// Get acceleration data
|
||||||
bool res = sensor.getAccel(acc);
|
bool res = sensor.getAccel(acc);
|
||||||
uint8_t direction = sensor.getDirection();
|
uint8_t direction = sensor.getDirection();
|
||||||
display.fillScreen(GxEPD_BLACK);
|
display.fillScreen(GxEPD_BLACK);
|
||||||
display.setCursor(0, 30);
|
display.setCursor(0, 30);
|
||||||
if(res == false) {
|
if(res == false) {
|
||||||
display.println("getAccel FAIL");
|
display.println("getAccel FAIL");
|
||||||
|
@ -608,8 +606,8 @@ void Watchy::drawWatchFace(){
|
||||||
display.print(":");
|
display.print(":");
|
||||||
if(currentTime.Minute < 10){
|
if(currentTime.Minute < 10){
|
||||||
display.print("0");
|
display.print("0");
|
||||||
}
|
}
|
||||||
display.println(currentTime.Minute);
|
display.println(currentTime.Minute);
|
||||||
}
|
}
|
||||||
|
|
||||||
weatherData Watchy::getWeatherData(){
|
weatherData Watchy::getWeatherData(){
|
||||||
|
@ -624,7 +622,7 @@ weatherData Watchy::getWeatherData(){
|
||||||
String payload = http.getString();
|
String payload = http.getString();
|
||||||
JSONVar responseObject = JSON.parse(payload);
|
JSONVar responseObject = JSON.parse(payload);
|
||||||
currentWeather.temperature = int(responseObject["main"]["temp"]);
|
currentWeather.temperature = int(responseObject["main"]["temp"]);
|
||||||
currentWeather.weatherConditionCode = int(responseObject["weather"][0]["id"]);
|
currentWeather.weatherConditionCode = int(responseObject["weather"][0]["id"]);
|
||||||
}else{
|
}else{
|
||||||
//http error
|
//http error
|
||||||
}
|
}
|
||||||
|
@ -673,7 +671,7 @@ uint16_t Watchy::_writeRegister(uint8_t address, uint8_t reg, uint8_t *data, uin
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::_bmaConfig(){
|
void Watchy::_bmaConfig(){
|
||||||
|
|
||||||
if (sensor.begin(_readRegister, _writeRegister, delay) == false) {
|
if (sensor.begin(_readRegister, _writeRegister, delay) == false) {
|
||||||
//fail to init BMA
|
//fail to init BMA
|
||||||
return;
|
return;
|
||||||
|
@ -765,7 +763,7 @@ void Watchy::_bmaConfig(){
|
||||||
sensor.enableStepCountInterrupt();
|
sensor.enableStepCountInterrupt();
|
||||||
sensor.enableTiltInterrupt();
|
sensor.enableTiltInterrupt();
|
||||||
// It corresponds to isDoubleClick interrupt
|
// It corresponds to isDoubleClick interrupt
|
||||||
sensor.enableWakeupInterrupt();
|
sensor.enableWakeupInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::setupWifi(){
|
void Watchy::setupWifi(){
|
||||||
|
@ -799,7 +797,7 @@ void Watchy::setupWifi(){
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
btStop();
|
btStop();
|
||||||
|
|
||||||
guiState = APP_STATE;
|
guiState = APP_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::_configModeCallback (WiFiManager *myWiFiManager) {
|
void Watchy::_configModeCallback (WiFiManager *myWiFiManager) {
|
||||||
|
@ -853,7 +851,7 @@ void Watchy::showUpdateFW(){
|
||||||
display.display(false); //full refresh
|
display.display(false); //full refresh
|
||||||
display.hibernate();
|
display.hibernate();
|
||||||
|
|
||||||
guiState = FW_UPDATE_STATE;
|
guiState = FW_UPDATE_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watchy::updateFWBegin(){
|
void Watchy::updateFWBegin(){
|
||||||
|
@ -902,7 +900,7 @@ void Watchy::updateFWBegin(){
|
||||||
display.println(" ");
|
display.println(" ");
|
||||||
display.print(BT.howManyBytes());
|
display.print(BT.howManyBytes());
|
||||||
display.println(" bytes");
|
display.println(" bytes");
|
||||||
display.display(true); //partial refresh
|
display.display(true); //partial refresh
|
||||||
}
|
}
|
||||||
if(currentStatus == 2){
|
if(currentStatus == 2){
|
||||||
display.setFullWindow();
|
display.setFullWindow();
|
||||||
|
@ -917,7 +915,7 @@ void Watchy::updateFWBegin(){
|
||||||
display.display(false); //full refresh
|
display.display(false); //full refresh
|
||||||
|
|
||||||
delay(2000);
|
delay(2000);
|
||||||
esp_restart();
|
esp_restart();
|
||||||
}
|
}
|
||||||
if(currentStatus == 4){
|
if(currentStatus == 4){
|
||||||
display.setFullWindow();
|
display.setFullWindow();
|
||||||
|
@ -944,7 +942,7 @@ void Watchy::updateFWBegin(){
|
||||||
}
|
}
|
||||||
|
|
||||||
// time_t compileTime()
|
// time_t compileTime()
|
||||||
// {
|
// {
|
||||||
// const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
|
// const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
|
||||||
// const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
// const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||||
// char compMon[3], *m;
|
// char compMon[3], *m;
|
||||||
|
@ -963,4 +961,4 @@ void Watchy::updateFWBegin(){
|
||||||
|
|
||||||
// time_t t = makeTime(tm);
|
// time_t t = makeTime(tm);
|
||||||
// return t + FUDGE; //add fudge factor to allow for compile time
|
// return t + FUDGE; //add fudge factor to allow for compile time
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "DSEG7_Classic_Bold_53.h"
|
#include "DSEG7_Classic_Bold_53.h"
|
||||||
#include "BLE.h"
|
#include "BLE.h"
|
||||||
#include "bma.h"
|
#include "bma.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef struct weatherData{
|
typedef struct weatherData{
|
||||||
int8_t temperature;
|
int8_t temperature;
|
||||||
|
@ -48,7 +48,7 @@ class Watchy {
|
||||||
virtual void drawWatchFace(); //override this method for different watch faces
|
virtual void drawWatchFace(); //override this method for different watch faces
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _rtcConfig(String datetime);
|
void _rtcConfig(String datetime);
|
||||||
void _bmaConfig();
|
void _bmaConfig();
|
||||||
static void _configModeCallback(WiFiManager *myWiFiManager);
|
static void _configModeCallback(WiFiManager *myWiFiManager);
|
||||||
static uint16_t _readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len);
|
static uint16_t _readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len);
|
||||||
|
@ -61,4 +61,4 @@ extern RTC_DATA_ATTR BMA423 sensor;
|
||||||
extern RTC_DATA_ATTR bool WIFI_CONFIGURED;
|
extern RTC_DATA_ATTR bool WIFI_CONFIGURED;
|
||||||
extern RTC_DATA_ATTR bool BLE_CONFIGURED;
|
extern RTC_DATA_ATTR bool BLE_CONFIGURED;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue