-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Sun and Moon Clock #4179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eholstine
wants to merge
31
commits into
espruino:master
Choose a base branch
from
eholstine:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sun and Moon Clock #4179
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
4aa62b4
Add files via upload
eholstine 2afebfa
Delete apps/Sun_Moon_Watch.js
eholstine d39eea8
Delete apps/sunmoonclk.img
eholstine eb9bbea
Delete apps/sunmoonclk.info
eholstine 2b9bcdf
Delete apps/sunmoonclk.png
eholstine dd618e6
Create sunmoonclk
eholstine fbf5e70
Delete apps/sunmoonclk
eholstine c278cc2
Create sunmoonclk.js
eholstine 1d2a02a
Delete apps/sunmoonclk/sunmoonclk.js
eholstine 7cff19f
Create test.js
eholstine 8d4d2ae
Add files via upload
eholstine e522ac9
Delete apps/sunmoonclk/test.js
eholstine bc42c9f
Add files via upload
eholstine fd49c16
Delete apps/sunmoonclk/screenshot (1).png
eholstine 2a48ee9
Delete apps/sunmoonclk/screenshot (2).png
eholstine 87f9e94
Add files via upload
eholstine 41da040
Add files via upload
eholstine 59d6cce
Update metadata.json
eholstine ee968e4
Merge branch 'espruino:master' into master
eholstine 31514f4
Delete apps/sunmoonclk/Sun_Moon_Watch.js
eholstine b37ad5c
Delete apps/sunmoonclk/sunmoonclk.info
eholstine 2c072c6
Add files via upload
eholstine bf883ea
Update metadata.json
eholstine 4c4291e
Delete apps/sunmoonclk directory
eholstine e4aebe4
Revert "Delete apps/sunmoonclk directory"
bobrippling c36684d
sunmoon: add changelog and fix metadata/filenames
bobrippling c5fec1e
Update app-icon.js
eholstine bd55b8d
Update metadata.json
eholstine 2761890
Update metadata.json
eholstine 6cb4c8a
Update app-icon.js
eholstine 3c4e172
Merge branch 'espruino:master' into master
eholstine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Load fonts | ||
| require("Font7x11Numeric7Seg").add(Graphics); | ||
| // X/Y are the position of the bottom right of the HH:MM text - make it central! | ||
| const X = g.getWidth()/2 + 45, | ||
| Y = g.getHeight()/2 + 40; | ||
|
|
||
| function draw() { | ||
| // work out how to display the current time | ||
| var d = new Date(); | ||
| var clock = require("locale").time(d, 1 /*omit seconds*/); | ||
| var seconds = d.getSeconds().toString().padStart(2,0); | ||
| var meridian = require("locale").meridian(d); | ||
| // Reset the state of the graphics library | ||
| g.reset(); | ||
| // draw the current time (4x size 7 segment) | ||
| g.setFontAlign(1,1); // align bottom right | ||
| g.setFont("7x11Numeric7Seg:4"); | ||
| g.drawString(clock, X, Y, true /*clear background*/); | ||
| // draw the meridian(am/pm) and seconds (2x size 7 segment) | ||
| g.setFontAlign(-1,1); // align bottom left | ||
| g.setFont("6x8:2"); | ||
| g.drawString(meridian, X+4, Y-26, true /*clear background*/); | ||
| g.setFont("7x11Numeric7Seg:2"); | ||
| g.drawString(seconds, X+2, Y, true /*clear background*/); | ||
| // draw the date, in a normal font | ||
| g.setFont("6x8", 2); | ||
| g.setFontAlign(0,-40); // align center bottom | ||
| // pad the date - this clears the background if the date were to change length | ||
| var dateStr = " "+require("locale").date(d)+" "; | ||
| g.drawString(dateStr, g.getWidth()/2, Y+15, true /*clear background*/); | ||
|
|
||
| // Get current time | ||
| let now = new Date(); | ||
| let h = now.getHours(); | ||
| let m = now.getMinutes(); | ||
| let timeStr = ("0" + h).slice(-2) + ":" + ("0" + m).slice(-2); | ||
|
|
||
| // Draw sun or moon icon | ||
| if (h >= 6 && h < 18) { | ||
| drawSun(g.getWidth()/2, g.getHeight()/2 - 40); | ||
| } else { | ||
| drawMoon(g.getWidth()/2, g.getHeight()/2 - 40); | ||
| } | ||
| } | ||
|
|
||
| function drawSun(x, y) { | ||
| g.setColor("#FF8C00"); // orange | ||
| g.fillCircle(x, y, 12); | ||
| for (let i = 0; i < 8; i++) { | ||
| let angle = i * Math.PI / 4; | ||
| g.drawLine( | ||
| x + Math.cos(angle) * 16, | ||
| y + Math.sin(angle) * 16, | ||
| x + Math.cos(angle) * 22, | ||
| y + Math.sin(angle) * 22 | ||
| ); | ||
| } | ||
| } | ||
| function drawMoon(x, y) { | ||
| g.setColor("#F5F5F5"); // white smoke | ||
| g.fillCircle(x, y, 12); | ||
| g.setColor(0, 0, 0); // mask for crescent | ||
| g.fillCircle(x + 5, y - 2, 12); | ||
|
|
||
| } | ||
|
|
||
| // Clear the screen once, at startup | ||
| g.clear(); | ||
| // draw immediately at first | ||
| draw(); | ||
| // now draw every second | ||
| var secondInterval = setInterval(draw, 1000); | ||
| // Stop updates when LCD is off, restart when on | ||
| Bangle.on('lcdPower',on=>{ | ||
| if (secondInterval) clearInterval(secondInterval); | ||
| secondInterval = undefined; | ||
| if (on) { | ||
| secondInterval = setInterval(draw, 1000); | ||
| draw(); // draw immediately | ||
| } | ||
| }); | ||
| /* Show launcher when middle button pressed | ||
| This should be done *before* Bangle.loadWidgets so that | ||
| widgets know if they're being loaded into a clock app or not */ | ||
| Bangle.setUI("clock"); | ||
| // Load widgets | ||
| Bangle.loadWidgets(); | ||
| Bangle.drawWidgets(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| require("heatshrink").decompress(atob("MDCDAf/////////////////////////////////////////////////////////////////////////////////wAAAP/////////////////wAMP/+AAP//////////////wNtth////wP////////////+Nttth/////x///////////+BttttsP////+B//////////xtttttth/////+P////////+Ntttttth//////x////////xtttttttsP/////+P//////+NtttttttsP//////x//////+NttttsBtth//+B//x//////xttttth+Nth//x+P/+P////+NttttsOB9th/+OBx//x////+NttttsOB9tsP+OBx//x////xtttttsP/9tsP+P/x//+P///xtttttth+NtsP/x+P//+P///xttttttsBttsP/+B///+P///xtttttttttth///////+P//+Ntttttttttth////////x//+NtttttttttsP////////x//+Nttttttttth/////////x//+Nttttttttth/////////x//+NtttttttttsAP///////x//+Nttttttttttth///////x//+Nttttttttttth///////x//+Nttttttttttth///////x///xttttttttttth//////+P///xttttttttttth//////+P///xtttttthtttsP//x///+P///xttttttsNttsP/+P///+P///+NtttttsNttsP/+P///x////+NttttthhttsP/xx///x/////xttttttsAAAAAP///+P/////xttttttttth//////x//////+Ntttttttth//////x///////xtttttttsP/////+P///////+NttttttsP/////x/////////xtttttth/////+P/////////+BttttsP////+B///////////+Nttth/////x/////////////wNtth////wP//////////////wAMP//wAP/////////////////wAAAP/////////////////////////////////////////////////////////////////////////////////w==") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| require("Storage").write("sunmoonclk.info",{ | ||
| "id":"sunmoonclk", | ||
| "name":"Sun Moon", | ||
| "type":"clock", | ||
| "src":"sunmoonclk.app.js" | ||
| }); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want a metadata file (example linked), rather than the info file here