-
Notifications
You must be signed in to change notification settings - Fork 1.3k
spotrem: add volume knob gesture #3847
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
thyttan
wants to merge
33
commits into
espruino:master
Choose a base branch
from
thyttan:spotrem
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
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
597a47e
spotrem: refactor copying setui ud logic into app
5f91cf8
spotrem: add volume knob
2966051
spotrem: lint error fix
8a78873
spotrem: tweak knob steps per turn, tweak buzz
09ee996
spotrem: add info re volume knob to readme
0b693cd
spotrem: increase buzz strength for volume dial
3df424b
spotrem: refactor moving buzzes to callback function
915546d
spotrem: add double buzz on deactivating volume knob
732c633
Merge remote-tracking branch 'upstream/master' into spotrem
7be4771
spotrem: tweak defaults of dial, call w/o options
068675e
Dial: new module providing a circular dial
0696b12
spotrem: refactor to use the Dial module
d99f528
Dial: add documentation (skeleton for now)
be7c1de
Dial: tweaks
4d8ff49
Dial: move to correct folder
9af1e6a
Dial: tweak stepsPerWholeTurn
e7b0af4
Dial: small refactor
656294b
Dial: add contents to documentation
0d7fb84
Dial_Display: complementary graphics to Dial module
9445bf4
Dial_Display: WIP generate a function drawing the dial
807add0
Merge remote-tracking branch 'upstream/master' into spotrem
08e23d8
Dial_Display: tweaks to debugging code
b4bcc6f
Dial_Display: drop debugging code
15ceb23
Dial: tweak docs
5ed691b
Dial_Display: improve docs
d5f5b22
Merge remote-tracking branch 'upstream/master' into spotrem
ea1a716
Dial_Display: tweak logic and docs
cb82231
spotrem: integrate dial graphics
9adab33
Dial_Display: add future work comment to docs
902bbf8
Dial: update docs re Dial_Display module
afe41f0
dial: change to lower case initial
e372807
Dial_Display: describe as module, not library
91a6b9d
Make `DialDisplay` a class
bobrippling 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
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
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
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
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,68 @@ | ||
function DialDisplay(options) { | ||
const SCREEN_W = g.getWidth(); | ||
const SCREEN_H = g.getHeight(); | ||
|
||
this.options = Object.assign( | ||
{ | ||
stepsPerWholeTurn : 7, // 7 chosen as it felt the best in use. | ||
dialRect : { | ||
x: 0, | ||
y: 0, | ||
w: SCREEN_W, | ||
h: SCREEN_H, | ||
}, | ||
}, options); | ||
|
||
this.value = 0; | ||
this.reset(); | ||
} | ||
|
||
DialDisplay.prototype.reset = function() { | ||
this.isFirstDraw = true; | ||
}; | ||
|
||
DialDisplay.prototype.set = function(value) { | ||
this.prevValue = this.value; | ||
this.value = value; | ||
}; | ||
|
||
DialDisplay.prototype.step = function(step) { | ||
"ram"; | ||
let prevValue = this.prevValue != null ? this.prevValue : this.value; | ||
this.value += step; | ||
//g.setFont("Vector:30"); | ||
//g.drawString(this.value); | ||
|
||
const DIAL_RECT = this.options.dialRect; | ||
|
||
const CENTER = { | ||
x: DIAL_RECT.x + DIAL_RECT.w / 2, | ||
y: DIAL_RECT.y + DIAL_RECT.h / 2, | ||
}; | ||
|
||
let drawCircle = (value, R, G, B, rad, isFill)=>{ | ||
let x = CENTER.x+27*Math.sin(value*(2*Math.PI/this.options.stepsPerWholeTurn)); | ||
let y = CENTER.y-27*Math.cos(value*(2*Math.PI/this.options.stepsPerWholeTurn)); | ||
g.setColor(R,G,B) | ||
if (!isFill) g.drawCircle(x, y, rad); | ||
if (isFill) g.fillCircle(x, y, rad); | ||
} | ||
if (this.isFirstDraw) { | ||
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 25); | ||
g.setColor(1,1,1).drawCircle(CENTER.x, CENTER.y, 25); | ||
for (let i=0; i<this.options.stepsPerWholeTurn; i++) { | ||
drawCircle(i, 1, 1, 1, 1, true); | ||
} | ||
this.isFirstDraw = false; | ||
} | ||
|
||
//drawCircle(this.value, 1, 1, 1, 2, false); | ||
//drawCircle(prevValue, 0, 0, 0, 2, false); | ||
g.setColor(0,0,0).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(prevValue*(2*Math.PI/this.options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(prevValue*(2*Math.PI/this.options.stepsPerWholeTurn))); | ||
g.setColor(1,1,1).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(this.value*(2*Math.PI/this.options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(this.value*(2*Math.PI/this.options.stepsPerWholeTurn))); | ||
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 9); | ||
|
||
delete this.prevValue; | ||
}; | ||
|
||
exports = DialDisplay; |
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,72 @@ | ||
Bangle.js Dial Display Module | ||
============================= | ||
|
||
|
||
> Take a look at README.md for hints on developing with this module. | ||
|
||
Usage | ||
----- | ||
|
||
```JS | ||
var DialDisplay = require("Dial_Display"); | ||
var dialDisplay = new DialDisplay(options); | ||
|
||
dialDisplay.step(-1); | ||
|
||
var value = dialDisplay.value; | ||
|
||
// ... after some time: | ||
dialDisplay.reset(); | ||
dialDisplay.set(0); | ||
``` | ||
|
||
For example in use with the Dial module: | ||
|
||
```JS | ||
var options = { | ||
stepsPerWholeTurn : 6, | ||
dialRect : { | ||
x: 0, | ||
y: 0, | ||
w: g.getWidth()/2, | ||
h: g.getHeight()/2, | ||
} | ||
} | ||
|
||
var DialDisplay = require("Dial_Display"); | ||
var dialDisplay = new DialDisplay(options); | ||
|
||
var cb = (step) => { | ||
dialDisplay.reset(); | ||
dialDisplay.step(step); | ||
}; | ||
|
||
var dial = require("Dial")(cb, options) | ||
Bangle.on("drag", dial); | ||
``` | ||
|
||
`options` (first argument) (optional) is an object containing: | ||
|
||
`stepsPerWholeTurn` - how many steps there are in one complete turn of the dial. | ||
`dialRect` - decides the area of the screen the dial is set up on. | ||
|
||
Defaults: | ||
```js | ||
{ stepsPerWholeTurn : 7 | ||
dialRect : { | ||
x: 0, | ||
y: 0, | ||
w: g.getWidth(), | ||
h: g.getHeight(), | ||
}, | ||
} | ||
``` | ||
|
||
The Dial Display has three functions: | ||
`step(amount)` - +1 or -1 to step the dial. | ||
`set(value)` - set the value for the next `step()` to act on. | ||
`reset()` - draw all of the dial (instead of just the indicator) on the next `step()`. | ||
|
||
Notes: | ||
====== | ||
- It would be nice to choose what colors are used. Something for the future. |
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,75 @@ | ||
function dial(cb, options) { | ||
"ram"; | ||
const SCREEN_W = g.getWidth(); | ||
const SCREEN_H = g.getHeight(); | ||
|
||
options = Object.assign( | ||
{ stepsPerWholeTurn : 7, // 7 chosen as it felt the best in use. | ||
dialRect : { | ||
x: 0, | ||
y: 0, | ||
w: SCREEN_W, | ||
h: SCREEN_H, | ||
}, | ||
}, options); | ||
|
||
const DIAL_RECT = options.dialRect; | ||
|
||
const CENTER = { | ||
x: DIAL_RECT.x + DIAL_RECT.w / 2, | ||
y: DIAL_RECT.y + DIAL_RECT.h / 2, | ||
}; | ||
|
||
const BASE_SCREEN_W = 176; | ||
const STEPS_PER_TURN = options.stepsPerWholeTurn; | ||
const BASE_THRESHOLD = 50; | ||
const THRESHOLD = | ||
BASE_THRESHOLD * | ||
(10 / STEPS_PER_TURN) * | ||
(DIAL_RECT.w / BASE_SCREEN_W); | ||
|
||
let cumulative = 0; | ||
|
||
function onDrag(e) { | ||
"ram"; | ||
|
||
if ( | ||
e.x < DIAL_RECT.x || | ||
e.x > DIAL_RECT.x+DIAL_RECT.w-1 || | ||
e.y < DIAL_RECT.y || | ||
e.y > DIAL_RECT.y+DIAL_RECT.h-1 | ||
) { | ||
return; | ||
} | ||
|
||
if (e.y < CENTER.y) { | ||
cumulative += e.dx; | ||
} else { | ||
cumulative -= e.dx; | ||
} | ||
|
||
if (e.x < CENTER.x) { | ||
cumulative -= e.dy; | ||
} else { | ||
cumulative += e.dy; | ||
} | ||
|
||
function stepHandler(step) { | ||
cumulative -= THRESHOLD * step; | ||
cb(step); | ||
} | ||
|
||
while (cumulative > THRESHOLD) { | ||
stepHandler(1); | ||
} | ||
while (cumulative < -THRESHOLD) { | ||
stepHandler(-1); | ||
} | ||
|
||
E.stopEventPropagation(); | ||
} | ||
|
||
return onDrag; | ||
} | ||
|
||
exports = dial; |
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,54 @@ | ||
Bangle.js Dial Module | ||
===================== | ||
|
||
> Take a look at README.md for hints on developing with this module. | ||
|
||
Usage | ||
----- | ||
|
||
```JS | ||
var dial = require("dial")(cb, options); | ||
Bangle.on("drag", dial); | ||
``` | ||
|
||
For example: | ||
|
||
```JS | ||
let cb = (plusOrMinusOne)=>{print(plusOrMinusOne)}; | ||
let options = { | ||
stepsPerWholeTurn : 6, | ||
dialRect : { | ||
x: 0, | ||
y: 0, | ||
w: g.getWidth()/2, | ||
h: g.getHeight()/2, | ||
} | ||
} | ||
|
||
let dial = require("dial")(cb, options); | ||
Bangle.on("drag", dial); | ||
``` | ||
|
||
`cb` (first argument) is a callback function that should expect either `+1` or `-1` as argument when called. | ||
|
||
`options` (second argument) (optional) is an object containing: | ||
|
||
`stepsPerWholeTurn` - how many steps there are in one complete turn of the dial. | ||
`dialRect` - decides the area of the screen the dial is set up on. | ||
|
||
Defaults: | ||
```js | ||
{ stepsPerWholeTurn : 7 | ||
dialRect : { | ||
x: 0, | ||
y: 0, | ||
w: g.getWidth(), | ||
h: g.getHeight(), | ||
}, | ||
} | ||
``` | ||
|
||
Notes | ||
----- | ||
|
||
A complementary module for drawing graphics is provided in the Dial_Display module. |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Same again (as the other comment), but here I think we'll want to change to make it more class-like, or alter how
this
is used within thedialDisplay
function. At the moment it'll be writing to the global object.For example, in the IDE:
Happy to go through a few suggestions for it, if you like
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.
Please do! Fun with a learning opportunity :) Feel free to commit to this PR.
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.
Of course, I'll pop something together
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.
Here you go - I've summarised the usage in the updated readme (inline below), let me know what you think. Happy to revert if you'd prefer a different approach :)
BangleApps/modules/Dial_Display.md
Lines 11 to 20 in 91a6b9d
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.
Thanks - looks nice I think! Wont claim to understand it completely yet - I'll try to test it tomorrow or the day after. The only thing I got a little hung up on is if the name
reset
may be ambiguous - it could be interpreted as reset graphics, values or both. I'll think about that.Thanks again :D
Uh oh!
There was an error while loading. Please reload this page.
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.
I really like getting rid of those extra parameters and moving to methods instead. That's something I'll try to take with me going forward :)
I'm curious if using
set
twice before drawing can lead to not clearing the previous visual indicator position. I'll look at that when I get to testing.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.
Yes very true,
reset
is a little ambiguous! (feel free to change it, delete any of the methods or anything of course)But yes - I found exactly what you said,
set()
makes it forget the previous value, so I altered the code slightly to deal with that tooThere 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.
I don't think you pushed this? 🙂
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.
Ah, sorry I should've said - it was all in the same commit, the code keeping
prevValue
in sync is here :)BangleApps/modules/Dial_Display.js
Lines 24 to 32 in 91a6b9d