Skip to content
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

Fix spirit level when screen rotated #2999

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/slevel/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
0.02: Updated to work with both Bangle.js 1 and 2.
0.03: Now also visible on Bangle.js 2
0.04: Now work with different themes
0.05: Take default rotation/reflection into account
2 changes: 1 addition & 1 deletion apps/slevel/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "slevel",
"name": "Spirit Level",
"version": "0.04",
"version": "0.05",
"description": "Show the current angle of the watch, so you can use it to make sure something is absolutely flat",
"icon": "spiritlevel.png",
"screenshots": [{"url":"screenshot.png"}],
Expand Down
12 changes: 12 additions & 0 deletions apps/slevel/spiritlevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ g.clear();
var old = {x:0,y:0};
var W = g.getWidth();
var H = g.getHeight();
var defaultRotation = 0 | require('Storage').readJSON("setting.json").rotate;

Bangle.on('accel',function(v) {
var max = Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(v.z));
Expand All @@ -20,6 +21,17 @@ Bangle.on('accel',function(v) {
var n = {
x:E.clip(W/2+v.x*256,4,W-4),
y:E.clip(H/2+v.y*256,4,H-4)};

if (defaultRotation === 1) {
n = {x:n.y,y:H-n.x};
} else if (defaultRotation === 2) {
n = {x:W-n.x,y:H-n.y};
} else if (defaultRotation === 3) {
n = {x:W-n.y,y:n.x};
} else if (defaultRotation === 4) {
n = {x:W-n.x,y:n.y};
}

g.clearRect(old.x-3,old.y-3,old.x+6,old.y+6); // clear old marker
g.setColor("#0f0");
g.fillRect(n.x-3,n.y-3,n.x+6,n.y+6); // draw new marker
Expand Down