Skip to content
Open
Show file tree
Hide file tree
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
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
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
2 changes: 2 additions & 0 deletions apps/spotrem/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ when fastloading.
0.11: Further refactoring to shorten the code. Fixed search and play that was broken in v0.10.
0.12: Fix some warnings from the linter.
0.13: Move ui-handlers inside setUI-call.
0.14: Add volume knob.

2 changes: 2 additions & 0 deletions apps/spotrem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Swipe input:

Swipe left/right to go to previous/next track. Swipe up/down to change the volume.

If you have changed the volume by swipe up/down, you can use a "volume knob" to continuously change the volume. Clock wise circle gesture on the screen increases volume and vice versa. The knob will deactivate shortly after you release the finger from the watch screen, indicated by a double buzz.

It's possible to start tracks by searching with the remote. Search term without tags will override search with tags.

To start playing 'from cold' the command for previous/next track via touch or swipe can be used. Pressing just play/pause is not guaranteed to initiate spotify in all circumstances (this will probably change with subsequent releases).
Expand Down
75 changes: 70 additions & 5 deletions apps/spotrem/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,83 @@ let swipeHandler = function(LR, _) {
}
};

let dx = 0;
let dy = 0;
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);
}

let resetOuterScopeVariables = ()=>{
dy=0;
dx=0;
volumeChangedThisGoAround=false;
}

dx += e.dx;
dy += e.dy;
if (!e.b) {resetOuterScopeVariables();}

while (Math.abs(dy)>32) {
if (dy>0) { dy-=32; cb(-1) }
else { dy+=32; cb(1) }
volumeChangedThisGoAround = true;
}

if (volumeChangedThisGoAround && Math.abs(dx)>32) {
// setup volume knob here.
let cbVisual = (step)=>{
cb(step);
volumeKnobVisual.step(step);
};
cbVisual(Math.sign(dx)*Math.sign(g.getHeight()/2-e.y));
resetOuterScopeVariables();
let volumeKnob = require("Dial")(cbVisual);
let timingOutVolumeKnob = (e)=>{
if (!e.b) {
setKnobTimeout();
} else if (knobTimeout) {
clearTimeout(knobTimeout);
knobTimeout = undefined;
}
volumeKnob(e);
}
let swipeMask = ()=>{
E.stopEventPropagation();
}
let setKnobTimeout = ()=>{
knobTimeout = setTimeout(()=>{
Bangle.removeListener("drag", timingOutVolumeKnob)
Bangle.removeListener("swipe", swipeMask);
Bangle.buzz(40);
setTimeout(Bangle.buzz, 150, 40, 0.8)
gfx();
knobTimeout = undefined;
print("removed volume knob")
}, 350);
}
Bangle.prependListener("drag", timingOutVolumeKnob);
Bangle.prependListener("swipe", swipeMask);
}
};

// Navigation input on the main layout
let setUI = function() {
Bangle.setUI(
{mode : "updown",
{mode : "custom",
touch: touchHandler,
swipe: swipeHandler,
drag: dragHandler,
btn: ()=>load(),
remove : ()=>widgetUtils.show(),
},
ud => {
if (ud) Bangle.musicControl(ud>0 ? "volumedown" : "volumeup");
}
}
);
};

Expand Down
2 changes: 1 addition & 1 deletion apps/spotrem/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "spotrem",
"name": "Remote for Spotify",
"version": "0.13",
"version": "0.14",
"description": "Control spotify on your android device.",
"readme": "README.md",
"type": "app",
Expand Down
68 changes: 68 additions & 0 deletions modules/Dial_Display.js
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;
72 changes: 72 additions & 0 deletions modules/Dial_Display.md
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);
Copy link
Collaborator

@bobrippling bobrippling Aug 17, 2025

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 the dialDisplay function. At the moment it'll be writing to the global object.

For example, in the IDE:

> cb
=function (step) { ... }
>cb(1)
=undefined
>cb(1)
=undefined

// the dial renders successfully
// `this` variables are written to the global:

>isFirstDraw
=false
>value
=14

Happy to go through a few suggestions for it, if you like

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to go through a few suggestions for it, if you like

Please do! Fun with a learning opportunity :) Feel free to commit to this PR.

Copy link
Collaborator

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

Copy link
Collaborator

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 :)

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);

Copy link
Collaborator Author

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

Copy link
Collaborator Author

@thyttan thyttan Aug 29, 2025

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.

Copy link
Collaborator

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 too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I altered the code slightly to deal with that too

I don't think you pushed this? 🙂

Copy link
Collaborator

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 :)

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;


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.
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;
54 changes: 54 additions & 0 deletions modules/dial.md
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.