Beep on change of field value?

Former Member
Former Member
I'm trying to have a beep when a field changes with code like the below:
class DataField extends Ui.SimpleDataField {

var result ="";
var last_result ="";

// Constructor
function initialize() {
label = "Field";


}

// Handle the update event
function compute(info) {
//some stuff to calculate result

answer = position;
if (result != last_result) { Attention.playTone(2);
}
last_result = result;
return result;
}
}

But in the simulator it plays the beep whether or not the field changes value. Even if I output the result and last result and can see that they are the same. What am I missing?
Also is that the best way of getting a beep. It appears to make the 520 crash.
  • Do you need to use a .equals() instead of != since you are comparing strings??
  • Former Member
    Former Member over 8 years ago
    Do you need to use a .equals() instead of != since you are comparing strings??

    Ah, Thanks. It is working now in the simulator, but on the device (edge 520) the field crashes when it gets to the playtone, anyone know why? Or what the best way to beep is?
  • What FW are you running on the 520? I'm on 9.10 and playTone() works fine in a DF. Is there anything in \garmin\apps\logs\ciq_log.txt?

    Here's the code for compute I use. (it's just a simple DF that beeps ever X seconds, and watches timerTime to see if it's recording)
    function compute(info) {
    if(info.timerTime==null || info.timerTime==0) {
    beeps=0;
    running=false;
    lastTimerTime=0;
    }
    if(info.timerTime!=null && info.timerTime!=0) {
    if(info.timerTime!=lastTimerTime) {
    running=true;
    lastTimerTime=info.timerTime;
    }
    else {running=false;}

    if(running && (info.timerTime/1000)%seconds==0) {
    beeps++;
    Attention.playTone(Attention.TONE_LOUD_BEEP);
    }
    }
    }