Whitespace changes

pull/86/head
Clayton Rogers 2021-08-08 16:53:17 -04:00
parent 80c4444576
commit c5c83300da
2 changed files with 185 additions and 187 deletions

View File

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

View File

@ -12,7 +12,7 @@
#include "DSEG7_Classic_Bold_53.h"
#include "BLE.h"
#include "bma.h"
#include "config.h"
#include "config.h"
typedef struct weatherData{
int8_t temperature;
@ -48,7 +48,7 @@ class Watchy {
virtual void drawWatchFace(); //override this method for different watch faces
private:
void _rtcConfig(String datetime);
void _rtcConfig(String datetime);
void _bmaConfig();
static void _configModeCallback(WiFiManager *myWiFiManager);
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 BLE_CONFIGURED;
#endif
#endif