Most recent activity
-
-
Thanks for your kind words, @Robin.
'I realize my newbie question is quite senseless'
I wanted to express, that I feel a bit guilty asking questions which could've been answered by myself by a revision of my code and re-reading some tutorial-parts. But maybe you're right, sometimes you need a kind of other "input" to get to a solution.
Are you sure you are a beginner??
Before starting this project I copypasted tutorial-codesnippets into the IDE or tried changing code-parts of e.g. a clock app to change its look. So I guess so.
You indiated in post #3 two references, (the API Reference helped a ton and mozillas MDN JavaScript reference was very helpful too) are there by chance any others that you are using that helped here?
I tried several Youtube-tutorials, but never found one which focuses on javascript without combining it with html and css. So the great tutorials on espruino.com and those mentioned references were the only "sources of knowledge" for me.
Carefully review L36 in post #7 and review examples at MDN:
Ah, it's obviously unnecessary, as there are only two conditions for tstate :D . Should've rechecked before posting.
Thanks again for spending your time on my gain of knowledge! Really appreciate that!
-
Thanks a lot for pointing me in the right direction. I lacked the knowledge to realize that I don't need a second Bangle.on('twist'). And now I realize my newbie question is quite senseless, because a bit more of "if...else-understanding" gets the job done easily.
So here is the less function-cluttered "app":
///////////////////////////////////////////////////////////// // control music by twist/buttons let counter = 0; //stores your counted your twists var tstate = false; //are you ready to count the twists? function playx() { Bluetooth.println(JSON.stringify({t:"music", n:"play"})); } function volu() { Bluetooth.println(JSON.stringify({t:"music", n:"volumeup"})); } function vold() { Bluetooth.println(JSON.stringify({t:"music", n:"volumedown"})); } function sendCmd() { print (counter); Bangle.beep(200,3000); if (tstate==false && counter>0){ do {playx(); counter--;} while (counter >= 1); } } function twistctrl() { if (tstate==false){ tstate=true; setTimeout('tstate=false',4000); setTimeout(sendCmd,4100); Bangle.beep(200,3000); } else{ if (tstate==true){ if (counter < 5){ counter++; Bangle.buzz(100,2); } else { counter = 0; Bangle.buzz(400); } } } } setWatch(volu,BTN1,{repeat:true}); setWatch(vold,BTN3,{repeat:true}); Bangle.on('twist',twistctrl); setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
-
Hey Robin, thanks a lot for your detailed answer!
The counter call within a timeout in L24 is caused by the different timeouts on lines 56 & 57. If it would be reset before sendCmd is executed, sendCmd would always have counter=0 and therefore never send any commands to my phone, was my line of thought.The only thing I consider to be the possible problem is in L39 "Bangle.removeListener('twist',countup);". Maybe I don't get this function right. I wanted to remove the listener that looks for twists and executes "countup" then. Is line39 removing the listener and also executing countup once?
EDIT: just tested to change the L39 into "Bangle.removeListener('twist');", which causes errors and breaks the functionality. So I guess, it was right in first place?(regarding the "nit-picky" off topic stuff: "tackling sth in a roundabout way" may be what I wanted to say. I guess one could write this "functionality" with less functions, so it preserves RAM and battery. So I was also looking for hints to do so ;-) )
-
Well, I went through the Bangle.JS First App and Clock Faces tutorials and spent some time reading code on github. But this was the first time I've done something without a tutorial and tried to get my ideas into codelines (the API Reference helped a ton and mozillas MDN JavaScript reference was very helpful too). It took me quite a while in the last two days to figure things out, but it's so satisfying if problems get solved :D
It is working for me but... there are some things happening, I don't really understand.
After loading the code into RAM, I twist to start counting -> Bangle beeps and starts counting my following twists confirming them with short vibrations and sends a BL command to my phone and beeps after 4s - that's what it should do. But on the second twist to start counting, it also vibrates and counts up one. Thats why I had to add a "reset counter" (line 20) function to be executed in line 24. If I hadn't done that, every counting would start with the counter set to 1 instead of 0.
But what causes the +1 before the "real" countup starts?At first attempt I ran the code without Bangle.removeListener(). That caused added countup-functions everytime I started a new "start counting my twists"-twist. At this point I almost gave up until I discovered that you can "stop" Bangle.on('twist')-functions with those "removeListeners". Then I added Bangle.removeAllListeners(). which stopped those multiple countups at once, but also stopped the inital twist-listener for the "start counting my twists"-function after sending the commands first time. Then I tried "Bangle.removeListener('twist',countup)", which seems to have solved it.
So it was a lot of try and error and looking up things. There's still a lot of syntax I don't understand.So the reasons why I'm asking are on the one hand the "problems" I mentioned above and on the other hand I want to improve it so one day it's fine enough to find it's way into the App Loader so others can use it too, if they want. :)
I hope my text is kind of understandable
-
Hey there,
first of all, thanks to everyone who created Bangle.js. Without this piece of hard- and software I would've never started to try writing code.
In the last two days I tried to write an app (never wrote any code before, I hope it's not too "ugly") to control a music player on Android, which can be controlled by multiple play-commands (1x play / 2x next song / 3x previous song / 4x next folder / 5x previous folder), by a twist of your arm. The idea behind this was: there may be situations when you second hand isn't free, but you wanna change the song you're listening to.I had some problems, which I solved very intricately (is this the right word? I'm no native english speaker :sweat_smile: ) I guess.
Maybe somebody wants to take a look and tell me how to handle things better or less intricate?
///////////////////////////////////////////////////////////// // control music by twist/buttons let counter = 0; var tstate = false; // defining commands function playx() { Bluetooth.println(JSON.stringify({t:"music", n:"play"})); } function volu() { Bluetooth.println(JSON.stringify({t:"music", n:"volumeup"})); } function vold() { Bluetooth.println(JSON.stringify({t:"music", n:"volumedown"})); } function resetc() {counter=0;} function cstate() { tstate=!tstate; setTimeout(resetc,100); Bangle.beep(200,3000);} function countup() { if (counter < 5){ counter++; Bangle.buzz(100,2); } else {counter = 0; Bangle.buzz(400); } } function sendCmd() { print (counter); Bangle.removeListener('twist',countup); if (tstate==false && counter>0){ do {playx(); counter--;} while (counter >= 1); } } function twistcount() { if (tstate==true){ Bangle.on('twist',countup); } } function twistctrl() { if (tstate==false) {cstate(); twistcount(); setTimeout(cstate,4000); setTimeout(sendCmd,4100); } } setWatch(volu,BTN1,{repeat:true}); setWatch(vold,BTN3,{repeat:true}); Bangle.on('twist',twistctrl); setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
Is this the right place for this thread, or is "Projects" the better place?
Hey there, the signal strength of the bluetooth connection between Bangle and phone is measurable, right? What came to my mind yesterday was, when I'm walking, there is a certain "distance pattern" between watch and phone most of the time. If a parameter like "only count steps if bluetooth signal strength shows pattern x" is added, could this prevent the step counting when not walking?
Of course it would only work when the watch is connected to your phone and that phone is kind of in a fixed position, so it wouldn't cover the problem in standalone mode.