Skip to content

Commit

Permalink
Add new watchface and uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
sqfmi committed Jan 12, 2023
1 parent e5556cb commit ce71292
Show file tree
Hide file tree
Showing 9 changed files with 735 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 SQFMI
Copyright (c) 2023 SQFMI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 10 additions & 0 deletions examples/WatchFaces/Mario/Mario.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Watchy_Mario.h"
#include "settings.h"

WatchyMario watchy(settings);

void setup(){
watchy.init();
}

void loop(){}
65 changes: 65 additions & 0 deletions examples/WatchFaces/Mario/Watchy_Mario.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "Watchy_Mario.h"
#define NUM_W 44
#define NUM_H 44
#define COIN_W 24
#define COIN_H 30
#define PIPE_W 42
#define PIPE_H 47
#define MARIO_W 56
#define MARIO_H 54
#define NUM_SPACING 4
#define COIN_SPACING 4
#define FLOOR_H 19
#define PIPE_PADDING DISPLAY_HEIGHT - FLOOR_H - PIPE_H
#define X_PADDING (DISPLAY_WIDTH - (4*NUM_W) - (3*NUM_SPACING))/2
#define Y_PADDING 2*COIN_SPACING+COIN_H


const unsigned char *numbers [10] = {mario0, mario1, mario2, mario3, mario4, mario5, mario6, mario7, mario8, mario9};

void WatchyMario::drawWatchFace(){
display.fillScreen(GxEPD_WHITE);
display.drawBitmap(0, 0, mariobg, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_BLACK);

int hour10 = currentTime.Hour/10;
int hour01 = currentTime.Hour%10;
int minute10 = currentTime.Minute/10;
int minute01 = currentTime.Minute%10;

int pos = 0;

if(hour01 == 0 && minute10 == 0 && minute01 == 0){
pos = 0;
}
else if(minute10 == 0 && minute01 == 0){
pos = 1;
}
else if(minute01 == 0){
pos = 2;
}else{
pos = 3;
}

display.drawBitmap(X_PADDING + pos*(NUM_SPACING + NUM_W) + (NUM_W/2 - MARIO_W/2) + (pos < 2 ? 8 : -8), Y_PADDING+NUM_H + 4, pos < 2 ? mariomariol : mariomarior, MARIO_W, MARIO_H, GxEPD_BLACK); //mario
display.drawBitmap(X_PADDING + pos*(NUM_SPACING + NUM_W) + (NUM_W/2 - COIN_W/2), COIN_SPACING, mariocoin, COIN_W, COIN_H, GxEPD_BLACK); //coin

if(pos == 0){
display.drawBitmap(DISPLAY_WIDTH - 2*PIPE_W, PIPE_PADDING, mariopipe, PIPE_W, PIPE_H, GxEPD_BLACK); //pipe
}
else if(pos == 1 || pos == 2){
display.drawBitmap(X_PADDING, PIPE_PADDING, mariopipe, PIPE_W, PIPE_H, GxEPD_BLACK); //pipe
display.drawBitmap(DISPLAY_WIDTH - PIPE_W - X_PADDING, PIPE_PADDING, mariopipe, PIPE_W, PIPE_H, GxEPD_BLACK); //pipe
}
else{
display.drawBitmap(2*PIPE_W, PIPE_PADDING, mariopipe, PIPE_W, PIPE_H, GxEPD_BLACK); //pipe
}


//Hour
display.drawBitmap(X_PADDING, pos == 0 ? Y_PADDING : Y_PADDING + 20, numbers[hour10], NUM_W, NUM_H, GxEPD_BLACK); //first digit
display.drawBitmap(X_PADDING+NUM_SPACING+NUM_W, pos == 1 ? Y_PADDING : Y_PADDING + 20, numbers[hour01], NUM_W, NUM_H, GxEPD_BLACK); //second digit

//Minute
display.drawBitmap(X_PADDING+2*(NUM_SPACING+NUM_W), pos == 2 ? Y_PADDING : Y_PADDING + 20, numbers[minute10], NUM_W, NUM_H, GxEPD_BLACK); //first digit
display.drawBitmap(X_PADDING+3*(NUM_SPACING+NUM_W), pos == 3 ? Y_PADDING : Y_PADDING + 20, numbers[minute01], NUM_W, NUM_H, GxEPD_BLACK); //second digit
}
13 changes: 13 additions & 0 deletions examples/WatchFaces/Mario/Watchy_Mario.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef WATCHY_MARIO_H
#define WATCHY_MARIO_H

#include <Watchy.h>
#include "mario.h"

class WatchyMario: public Watchy{
using Watchy::Watchy;
public:
void drawWatchFace();
};

#endif
600 changes: 600 additions & 0 deletions examples/WatchFaces/Mario/mario.h

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions examples/WatchFaces/Mario/settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef SETTINGS_H
#define SETTINGS_H

//Weather Settings
#define CITY_ID "5128581" //New York City https://openweathermap.org/current#cityid
#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :)
#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?id=" //open weather api
#define TEMP_UNIT "metric" //metric = Celsius , imperial = Fahrenheit
#define TEMP_LANG "en"
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data

watchySettings settings{
.cityID = CITY_ID,
.weatherAPIKey = OPENWEATHERMAP_APIKEY,
.weatherURL = OPENWEATHERMAP_URL,
.weatherUnit = TEMP_UNIT,
.weatherLang = TEMP_LANG,
.weatherUpdateInterval = WEATHER_UPDATE_INTERVAL,
.ntpServer = NTP_SERVER,
.gmtOffset = GMT_OFFSET_SEC,
.vibrateOClock = true,
};

#endif
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Watchy",
"version": "1.4.5",
"version": "1.4.6",
"description": "Watchy - An Open Source E-Paper Watch by SQFMI",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Watchy
version=1.4.5
version=1.4.6
author=SQFMI
maintainer=SQFMI
sentence=Watchy - An Open Source E-Paper Watch by SQFMI
Expand Down
17 changes: 17 additions & 0 deletions src/Watchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RTC_DATA_ATTR int weatherIntervalCounter = -1;
RTC_DATA_ATTR bool displayFullInit = true;
RTC_DATA_ATTR long gmtOffset = 0;
RTC_DATA_ATTR bool alreadyInMenu = true;
RTC_DATA_ATTR tmElements_t bootTime;

void Watchy::init(String datetime) {
esp_sleep_wakeup_cause_t wakeup_reason;
Expand Down Expand Up @@ -59,6 +60,7 @@ void Watchy::init(String datetime) {
_bmaConfig();
gmtOffset = settings.gmtOffset;
RTC.read(currentTime);
RTC.read(bootTime);
showWatchFace(false); // full update on reset
vibMotor(75, 4);
break;
Expand Down Expand Up @@ -332,6 +334,21 @@ void Watchy::showAbout() {
display.print(voltage);
display.println("V");

display.print("Uptime: ");
RTC.read(currentTime);
time_t b = makeTime(bootTime);
time_t c = makeTime(currentTime);
int totalSeconds = c-b;
//int seconds = (totalSeconds % 60);
int minutes = (totalSeconds % 3600) / 60;
int hours = (totalSeconds % 86400) / 3600;
int days = (totalSeconds % (86400 * 30)) / 86400;
display.print(days);
display.print("d");
display.print(hours);
display.print("h");
display.print(minutes);
display.print("m");
display.display(false); // full refresh

guiState = APP_STATE;
Expand Down

0 comments on commit ce71292

Please sign in to comment.