-
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
38 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 3479c79
Merge remote-tracking branch 'upstream/master' into spotrem
681ce21
Dial_Display: more robust clearing of previous position
251da4f
Dial_Display: rework method `reset` into `queueRedraw`
6666f7a
Dial_Display: fix docs referencing `Dial` where it should be `dial`
d6a0dae
spotrem: `Dial` becomes `dial`
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 was deleted.
Oops, something went wrong.
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,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,60 @@ | ||
Bangle.js Dial Library | ||
====================== | ||
|
||
> Take a look at README.md for hints on developing with this library. | ||
|
||
Usage | ||
----- | ||
|
||
```JS | ||
var Dial = require("Dial"); | ||
var dial = new Dial(cb, options) | ||
Bangle.on("drag", dial); | ||
|
||
or | ||
|
||
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 library for drawing graphics is provided in the Dial_Display module. |
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,59 @@ | ||
let dialDisplayGenerator = function(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, | ||
}; | ||
|
||
let dialDisplay = function(step, value, isReinit) { | ||
let prevValue = this.value; | ||
if (value!==undefined) this.value = value; | ||
if (!this.value) this.value = 0; | ||
if (this.isFirstDraw===undefined || isReinit) this.isFirstDraw = true; | ||
this.value += step; | ||
//g.setFont("Vector:30"); | ||
//g.drawString(this.value); | ||
|
||
let drawCircle = (value, R, G, B, rad, isFill)=>{ | ||
let x = CENTER.x+27*Math.sin(value*(2*Math.PI/options.stepsPerWholeTurn)); | ||
let y = CENTER.y-27*Math.cos(value*(2*Math.PI/options.stepsPerWholeTurn)); | ||
g.setColor(R,G,B) | ||
if (!isFill) g.drawCircle(x, y, rad); | ||
if (isFill) g.fillCircle(x, y, rad); | ||
bobrippling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (this.isFirstDraw) { | ||
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 25); | ||
bobrippling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
g.setColor(1,1,1).drawCircle(CENTER.x, CENTER.y, 25); | ||
for (let i=0; i<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/options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(prevValue*(2*Math.PI/options.stepsPerWholeTurn))); | ||
g.setColor(1,1,1).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(this.value*(2*Math.PI/options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(this.value*(2*Math.PI/options.stepsPerWholeTurn))); | ||
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 9); | ||
|
||
return this.value; | ||
} | ||
return dialDisplay; | ||
} | ||
|
||
exports = dialDisplayGenerator; |
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,65 @@ | ||
Bangle.js Dial Display Library | ||
====================== | ||
|
||
|
||
> Take a look at README.md for hints on developing with this library. | ||
|
||
Usage | ||
----- | ||
|
||
```JS | ||
var DialDisplay = require("Dial_Display"); | ||
var dialDisplay = new DialDisplay(options); | ||
thyttan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var value = dialDisplay(-1, 0, true) | ||
``` | ||
|
||
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)=>{ | ||
var value = dialDisplay(step, undefined, true); | ||
}; | ||
|
||
var Dial = require("Dial"); | ||
var dial = new 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 generated function takes three arguments: | ||
`step` - +1 or -1 | ||
`value` - the previous value the step acts on. | ||
`isReinit` - true/false, whether to draw all of the dial or just the indicator. | ||
|
||
Notes: | ||
====== | ||
- It would be nice to choose what colors are used. Something for the future. |
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.