mirror of https://github.com/sqfmi/Watchy.git
parent
6b958b31b0
commit
ee77c1febc
|
@ -7,6 +7,3 @@ void setup(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){}
|
void loop(){}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,3 @@ void setup(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){}
|
void loop(){}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,150 +1,150 @@
|
||||||
// STARRY HORIZON for Watchy by SQFMI
|
// STARRY HORIZON for Watchy by SQFMI
|
||||||
// Copyright 2021 Dan Delany dan.delany@gmail.com
|
// Copyright 2021 Dan Delany dan.delany@gmail.com
|
||||||
// Released under free MIT License : https://github.com/dandelany/watchy-faces/blob/main/LICENSE
|
// Released under free MIT License : https://github.com/dandelany/watchy-faces/blob/main/LICENSE
|
||||||
|
|
||||||
#include <Watchy.h> //include the Watchy library
|
#include <Watchy.h> //include the Watchy library
|
||||||
#include <Fonts/FreeSansBold9pt7b.h> //include any fonts you want to use
|
#include <Fonts/FreeSansBold9pt7b.h> //include any fonts you want to use
|
||||||
#include "MadeSunflower39pt7b.h"
|
#include "MadeSunflower39pt7b.h"
|
||||||
#include "stars.h"
|
#include "stars.h"
|
||||||
|
|
||||||
#define STAR_COUNT 900
|
#define STAR_COUNT 900
|
||||||
|
|
||||||
const int horizonY = 150;
|
const int horizonY = 150;
|
||||||
const int planetR = 650;
|
const int planetR = 650;
|
||||||
|
|
||||||
struct xyPoint {
|
struct xyPoint {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Star myStars[STAR_COUNT];
|
//Star myStars[STAR_COUNT];
|
||||||
void initStars() {
|
void initStars() {
|
||||||
// The random star field is loaded from PROGMEM - see stars.h
|
// The random star field is loaded from PROGMEM - see stars.h
|
||||||
// this is the function that was used to generate the stars in stars.h
|
// this is the function that was used to generate the stars in stars.h
|
||||||
// it does not run normally but can be used to re-generate stars with different parameters
|
// it does not run normally but can be used to re-generate stars with different parameters
|
||||||
// tweak as needed, call this function in init, open serial monitor, and paste the results into stars.h
|
// tweak as needed, call this function in init, open serial monitor, and paste the results into stars.h
|
||||||
srand(5287); // randomSeed() is not stable on ESP32, use srand
|
srand(5287); // randomSeed() is not stable on ESP32, use srand
|
||||||
printf("const Star STARS[] PROGMEM = {\n");
|
printf("const Star STARS[] PROGMEM = {\n");
|
||||||
for(int i = 0; i < STAR_COUNT; i++) {
|
for(int i = 0; i < STAR_COUNT; i++) {
|
||||||
int starX = (rand() % 260) - 30;
|
int starX = (rand() % 260) - 30;
|
||||||
int starY = (rand() % 260) - 30;
|
int starY = (rand() % 260) - 30;
|
||||||
int radius = 0;
|
int radius = 0;
|
||||||
if (i > STAR_COUNT * 0.99) radius = 2;
|
if (i > STAR_COUNT * 0.99) radius = 2;
|
||||||
else if (i > STAR_COUNT * 0.80) radius = 1;
|
else if (i > STAR_COUNT * 0.80) radius = 1;
|
||||||
printf(" { %d, %d, %d },\n", starX, starY, radius);
|
printf(" { %d, %d, %d },\n", starX, starY, radius);
|
||||||
// myStars[i] = { starX, starY, radius };
|
// myStars[i] = { starX, starY, radius };
|
||||||
}
|
}
|
||||||
printf("};\n");
|
printf("};\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xyPoint rotatePointAround(int x, int y, int ox, int oy, double angle) {
|
struct xyPoint rotatePointAround(int x, int y, int ox, int oy, double angle) {
|
||||||
// rotate X,Y point around given origin point by a given angle
|
// rotate X,Y point around given origin point by a given angle
|
||||||
// based on https://gist.github.com/LyleScott/e36e08bfb23b1f87af68c9051f985302#file-rotate_2d_point-py-L38
|
// based on https://gist.github.com/LyleScott/e36e08bfb23b1f87af68c9051f985302#file-rotate_2d_point-py-L38
|
||||||
double qx = (double)ox + (cos(angle) * (double)(x - ox)) + (sin(angle) * (double)(y - oy));
|
double qx = (double)ox + (cos(angle) * (double)(x - ox)) + (sin(angle) * (double)(y - oy));
|
||||||
double qy = (double)oy + (-sin(angle) * (double)(x - ox)) + (cos(angle) * (double)(y - oy));
|
double qy = (double)oy + (-sin(angle) * (double)(x - ox)) + (cos(angle) * (double)(y - oy));
|
||||||
struct xyPoint newPoint;
|
struct xyPoint newPoint;
|
||||||
newPoint.x = (int)qx;
|
newPoint.x = (int)qx;
|
||||||
newPoint.y = (int)qy;
|
newPoint.y = (int)qy;
|
||||||
return newPoint;
|
return newPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StarryHorizon : public Watchy {
|
class StarryHorizon : public Watchy {
|
||||||
public:
|
public:
|
||||||
StarryHorizon() {
|
StarryHorizon() {
|
||||||
// uncomment to re-generate stars
|
// uncomment to re-generate stars
|
||||||
// initStars();
|
// initStars();
|
||||||
}
|
}
|
||||||
void drawWatchFace(){
|
void drawWatchFace(){
|
||||||
display.fillScreen(GxEPD_BLACK);
|
display.fillScreen(GxEPD_BLACK);
|
||||||
display.fillCircle(100, horizonY + planetR, planetR, GxEPD_WHITE);
|
display.fillCircle(100, horizonY + planetR, planetR, GxEPD_WHITE);
|
||||||
drawGrid();
|
drawGrid();
|
||||||
drawStars(STARS);
|
drawStars(STARS);
|
||||||
drawTime();
|
drawTime();
|
||||||
drawDate();
|
drawDate();
|
||||||
}
|
}
|
||||||
void drawGrid() {
|
void drawGrid() {
|
||||||
int prevY = horizonY;
|
int prevY = horizonY;
|
||||||
for(int i = 0; i < 40; i+= 1) {
|
for(int i = 0; i < 40; i+= 1) {
|
||||||
int y = prevY + int(abs(sin(double(i) / 10) * 10));
|
int y = prevY + int(abs(sin(double(i) / 10) * 10));
|
||||||
if(y <= 200) {
|
if(y <= 200) {
|
||||||
display.drawFastHLine(0, y, 200, GxEPD_BLACK);
|
display.drawFastHLine(0, y, 200, GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
prevY = y;
|
prevY = y;
|
||||||
}
|
}
|
||||||
int vanishY = horizonY - 25;
|
int vanishY = horizonY - 25;
|
||||||
for (int x = -230; x < 430; x += 20) {
|
for (int x = -230; x < 430; x += 20) {
|
||||||
display.drawLine(x, 200, 100, vanishY, GxEPD_BLACK);
|
display.drawLine(x, 200, 100, vanishY, GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void drawStars(const Star stars[]) {
|
void drawStars(const Star stars[]) {
|
||||||
// draw field of stars
|
// draw field of stars
|
||||||
// rotate stars so that they make an entire revolution once per hour
|
// rotate stars so that they make an entire revolution once per hour
|
||||||
int minute = (int)currentTime.Minute;
|
int minute = (int)currentTime.Minute;
|
||||||
double minuteAngle = ((2.0 * M_PI) / 60.0) * (double)minute;
|
double minuteAngle = ((2.0 * M_PI) / 60.0) * (double)minute;
|
||||||
// printf("Minute %d, angle %f\n", (int)currentTime.Minute, minuteAngle);
|
// printf("Minute %d, angle %f\n", (int)currentTime.Minute, minuteAngle);
|
||||||
|
|
||||||
for(int starI = 0; starI < STAR_COUNT; starI++) {
|
for(int starI = 0; starI < STAR_COUNT; starI++) {
|
||||||
int starX = stars[starI].x;
|
int starX = stars[starI].x;
|
||||||
int starY = stars[starI].y;
|
int starY = stars[starI].y;
|
||||||
int starR = stars[starI].r;
|
int starR = stars[starI].r;
|
||||||
|
|
||||||
struct xyPoint rotated = rotatePointAround(starX, starY, 100, 100, minuteAngle);
|
struct xyPoint rotated = rotatePointAround(starX, starY, 100, 100, minuteAngle);
|
||||||
if(rotated.x < 0 || rotated.y < 0 || rotated.x > 200 || rotated.y > horizonY) {
|
if(rotated.x < 0 || rotated.y < 0 || rotated.x > 200 || rotated.y > horizonY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(starR == 0) {
|
if(starR == 0) {
|
||||||
display.drawPixel(rotated.x, rotated.y, GxEPD_WHITE);
|
display.drawPixel(rotated.x, rotated.y, GxEPD_WHITE);
|
||||||
} else {
|
} else {
|
||||||
display.fillCircle(rotated.x, rotated.y, starR, GxEPD_WHITE);
|
display.fillCircle(rotated.x, rotated.y, starR, GxEPD_WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void drawTime() {
|
void drawTime() {
|
||||||
display.setFont(&MADE_Sunflower_PERSONAL_USE39pt7b);
|
display.setFont(&MADE_Sunflower_PERSONAL_USE39pt7b);
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
display.setTextWrap(false);
|
display.setTextWrap(false);
|
||||||
char* timeStr;
|
char* timeStr;
|
||||||
asprintf(&timeStr, "%d:%02d", currentTime.Hour, currentTime.Minute);
|
asprintf(&timeStr, "%d:%02d", currentTime.Hour, currentTime.Minute);
|
||||||
drawCenteredString(timeStr, 100, 115, false);
|
drawCenteredString(timeStr, 100, 115, false);
|
||||||
free(timeStr);
|
free(timeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawDate() {
|
void drawDate() {
|
||||||
String monthStr = monthShortStr(currentTime.Month);
|
String monthStr = monthShortStr(currentTime.Month);
|
||||||
String dayOfWeek = dayShortStr(currentTime.Wday);
|
String dayOfWeek = dayShortStr(currentTime.Wday);
|
||||||
display.setFont(&FreeSansBold9pt7b);
|
display.setFont(&FreeSansBold9pt7b);
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
display.setTextWrap(false);
|
display.setTextWrap(false);
|
||||||
char* dateStr;
|
char* dateStr;
|
||||||
asprintf(&dateStr, "%s %s %d", dayOfWeek, monthStr, currentTime.Day);
|
asprintf(&dateStr, "%s %s %d", dayOfWeek, monthStr, currentTime.Day);
|
||||||
drawCenteredString(dateStr, 100, 140, true);
|
drawCenteredString(dateStr, 100, 140, true);
|
||||||
free(dateStr);
|
free(dateStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawCenteredString(const String &str, int x, int y, bool drawBg) {
|
void drawCenteredString(const String &str, int x, int y, bool drawBg) {
|
||||||
int16_t x1, y1;
|
int16_t x1, y1;
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
|
|
||||||
display.getTextBounds(str, x, y, &x1, &y1, &w, &h);
|
display.getTextBounds(str, x, y, &x1, &y1, &w, &h);
|
||||||
// printf("bounds: %d x %d y, %d x1 %d y1, %d w, %d h\n", 0, 100, x1, y1, w, h);
|
// printf("bounds: %d x %d y, %d x1 %d y1, %d w, %d h\n", 0, 100, x1, y1, w, h);
|
||||||
display.setCursor(x - w / 2, y);
|
display.setCursor(x - w / 2, y);
|
||||||
if(drawBg) {
|
if(drawBg) {
|
||||||
int padY = 3;
|
int padY = 3;
|
||||||
int padX = 10;
|
int padX = 10;
|
||||||
display.fillRect(x - (w / 2 + padX), y - (h + padY), w + padX*2, h + padY*2, GxEPD_BLACK);
|
display.fillRect(x - (w / 2 + padX), y - (h + padY), w + padX*2, h + padY*2, GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
// uncomment to draw bounding box
|
// uncomment to draw bounding box
|
||||||
// display.drawRect(x - w / 2, y - h, w, h, GxEPD_WHITE);
|
// display.drawRect(x - w / 2, y - h, w, h, GxEPD_WHITE);
|
||||||
display.print(str);
|
display.print(str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
StarryHorizon face; //instantiate watchface
|
StarryHorizon face; //instantiate watchface
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
face.init(); //call init in setup
|
face.init(); //call init in setup
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// this should never run, Watchy deep sleeps after init();
|
// this should never run, Watchy deep sleeps after init();
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
|
@ -4,7 +4,7 @@
|
||||||
"id" : "1",
|
"id" : "1",
|
||||||
"name" : "Basic",
|
"name" : "Basic",
|
||||||
"author" : "SQFMI",
|
"author" : "SQFMI",
|
||||||
"screenshot" : "",
|
"screenshot" : "https://raw.githubusercontent.com/sqfmi/Watchy/master/extras/WatchFaces/1_Basic.png",
|
||||||
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/Basic",
|
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/Basic",
|
||||||
"version" : "1.0.0"
|
"version" : "1.0.0"
|
||||||
},
|
},
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
"id" : "2",
|
"id" : "2",
|
||||||
"name" : "7_SEG",
|
"name" : "7_SEG",
|
||||||
"author" : "SQFMI",
|
"author" : "SQFMI",
|
||||||
"screenshot" : "",
|
"screenshot" : "https://raw.githubusercontent.com/sqfmi/Watchy/master/extras/WatchFaces/2_7_SEG.png",
|
||||||
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/7_SEG",
|
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/7_SEG",
|
||||||
"version" : "1.0.0"
|
"version" : "1.0.0"
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
"id" : "3",
|
"id" : "3",
|
||||||
"name" : "DOS",
|
"name" : "DOS",
|
||||||
"author" : "SQFMI",
|
"author" : "SQFMI",
|
||||||
"screenshot" : "",
|
"screenshot" : "https://raw.githubusercontent.com/sqfmi/Watchy/master/extras/WatchFaces/3_DOS.png",
|
||||||
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/DOS",
|
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/DOS",
|
||||||
"version" : "1.0.0"
|
"version" : "1.0.0"
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
"id" : "4",
|
"id" : "4",
|
||||||
"name" : "Pokemon",
|
"name" : "Pokemon",
|
||||||
"author" : "SQFMI",
|
"author" : "SQFMI",
|
||||||
"screenshot" : "",
|
"screenshot" : "https://raw.githubusercontent.com/sqfmi/Watchy/master/extras/WatchFaces/4_Pokemon.png",
|
||||||
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/Pokemon",
|
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/Pokemon",
|
||||||
"version" : "1.0.0"
|
"version" : "1.0.0"
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
"id" : "5",
|
"id" : "5",
|
||||||
"name" : "StarryHorizon",
|
"name" : "StarryHorizon",
|
||||||
"author" : "dandelany",
|
"author" : "dandelany",
|
||||||
"screenshot" : "",
|
"screenshot" : "https://raw.githubusercontent.com/sqfmi/Watchy/master/extras/WatchFaces/5_StarryHorizon.png",
|
||||||
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/StarryHorizon",
|
"source" : "https://github.com/sqfmi/Watchy/tree/master/examples/WatchFaces/StarryHorizon",
|
||||||
"version" : "1.0.0"
|
"version" : "1.0.0"
|
||||||
}
|
}
|
Loading…
Reference in New Issue