Skip to content
Merged
Show file tree
Hide file tree
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
May 9, 2025
5f91cf8
spotrem: add volume knob
May 9, 2025
2966051
spotrem: lint error fix
May 9, 2025
8a78873
spotrem: tweak knob steps per turn, tweak buzz
May 14, 2025
09ee996
spotrem: add info re volume knob to readme
May 16, 2025
0b693cd
spotrem: increase buzz strength for volume dial
May 16, 2025
3df424b
spotrem: refactor moving buzzes to callback function
May 16, 2025
915546d
spotrem: add double buzz on deactivating volume knob
May 16, 2025
732c633
Merge remote-tracking branch 'upstream/master' into spotrem
May 25, 2025
7be4771
spotrem: tweak defaults of dial, call w/o options
May 25, 2025
068675e
Dial: new module providing a circular dial
May 25, 2025
0696b12
spotrem: refactor to use the Dial module
May 25, 2025
d99f528
Dial: add documentation (skeleton for now)
May 25, 2025
be7c1de
Dial: tweaks
May 25, 2025
4d8ff49
Dial: move to correct folder
May 25, 2025
9af1e6a
Dial: tweak stepsPerWholeTurn
May 31, 2025
e7b0af4
Dial: small refactor
May 31, 2025
656294b
Dial: add contents to documentation
May 31, 2025
0d7fb84
Dial_Display: complementary graphics to Dial module
May 31, 2025
9445bf4
Dial_Display: WIP generate a function drawing the dial
Jun 1, 2025
807add0
Merge remote-tracking branch 'upstream/master' into spotrem
Aug 1, 2025
08e23d8
Dial_Display: tweaks to debugging code
Aug 1, 2025
b4bcc6f
Dial_Display: drop debugging code
Aug 12, 2025
15ceb23
Dial: tweak docs
Aug 12, 2025
5ed691b
Dial_Display: improve docs
Aug 12, 2025
d5f5b22
Merge remote-tracking branch 'upstream/master' into spotrem
Aug 12, 2025
ea1a716
Dial_Display: tweak logic and docs
Aug 12, 2025
cb82231
spotrem: integrate dial graphics
Aug 12, 2025
9adab33
Dial_Display: add future work comment to docs
Aug 12, 2025
902bbf8
Dial: update docs re Dial_Display module
Aug 13, 2025
afe41f0
dial: change to lower case initial
Aug 29, 2025
e372807
Dial_Display: describe as module, not library
Aug 29, 2025
91a6b9d
Make `DialDisplay` a class
bobrippling Aug 29, 2025
3479c79
Merge remote-tracking branch 'upstream/master' into spotrem
Sep 17, 2025
681ce21
Dial_Display: more robust clearing of previous position
Sep 18, 2025
251da4f
Dial_Display: rework method `reset` into `queueRedraw`
Sep 18, 2025
6666f7a
Dial_Display: fix docs referencing `Dial` where it should be `dial`
Sep 18, 2025
d6a0dae
spotrem: `Dial` becomes `dial`
Sep 18, 2025
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
89 changes: 0 additions & 89 deletions apps/modules/Dial.js

This file was deleted.

9 changes: 7 additions & 2 deletions apps/spotrem/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ let volumeChangedThisGoAround = false;
let knobTimeout;
let dragHandler = function(e) {

let DialDisplay = require("Dial_Display");
let volumeKnobVisual = new DialDisplay();

let cb = ud => {
Bangle.musicControl(ud<0 ? "volumedown" : "volumeup");
Bangle.buzz(20);
Expand All @@ -126,9 +129,10 @@ let dragHandler = function(e) {

if (volumeChangedThisGoAround && Math.abs(dx)>32) {
// setup volume knob here.
cb(Math.sign(dx))
let cbVisual = (step, value, reinit)=>{cb(step); volumeKnobVisual(step, value, reinit)};
cbVisual(Math.sign(dx)*Math.sign(g.getHeight()/2-e.y), 0, true)
resetOuterScopeVariables();
let volumeKnob = require("Dial")(cb);
let volumeKnob = require("Dial")(cbVisual);
let timingOutVolumeKnob = (e)=>{
if (!e.b) {
setKnobTimeout();
Expand All @@ -147,6 +151,7 @@ let dragHandler = function(e) {
Bangle.removeListener("swipe", swipeMask);
Bangle.buzz(40);
setTimeout(Bangle.buzz, 150, 40, 0.8)
gfx();
knobTimeout = undefined;
print("removed volume knob")
}, 350);
Expand Down
75 changes: 75 additions & 0 deletions modules/Dial.js
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;
60 changes: 60 additions & 0 deletions modules/Dial.md
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.
59 changes: 59 additions & 0 deletions modules/Dial_Display.js
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);
}
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<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;
65 changes: 65 additions & 0 deletions modules/Dial_Display.md
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);
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.