This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

play beep on specific plan
#2
Hi,

Just add a extra condition:
Code:
if (currentPlanId == 1){
  //your code
}
Here is also a code i use if the sound must be repeated until the object is false
Code:
$(function(){
  var locked;
  var ctx = new(window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.oAudioContext || window.msAudioContext);
  var Beeping;
 
  function beep(duration, freq, vol, cb) {
    var osc = ctx.createOscillator();
    osc.frequency.value = freq;
    var volumeNode = ctx.createGain();
    volumeNode.gain.value = (vol/1000);
    osc.connect(volumeNode);
    volumeNode.connect(ctx.destination);    
    osc.start ? osc.start(0) : osc.noteOn(0);
    setTimeout(function () {
    osc.disconnect();
    if (typeof cb == "function") {
     cb();
    }
   }, duration);
  }
 
  /* beep each time value is true note that 3rd listen parameter must be set to true to execute the callback each time new value arrives otherwise callback is executed only when value changes */
  function startbeep(){
    var ChromeDelay = 0;
    if (document.hidden && !!window.chrome){
      ChromeDelay = 1500;
    }
    setTimeout(function(){
      if (!locked) {
        locked = true;
        // duration , freq
        beep(300, 1500, 50, function() {
          locked = false;
        });
      }
    }, ChromeDelay);
  } 

  // Function to start beep interval
  function StartBeepTimer(){
    // Jump to correct page
    //showPlan(3);
    // Set delay timer to start after x seconds
    setTimeout(function(){
      // Start feedback polling every second
      if (!Beeping) {
        // Run once to bypass the first delay
        startbeep();
        Beeping = setInterval(function(){ startbeep(); }, 2000);
      }
    }, 50); // Set higher value then 50 for extra delay after stop and start beep
  }

  // Function to stop beep interval
  function StopBeepTimer(){
    // Stop feedback polling every second
    if (Beeping) {
      clearInterval(Beeping);
    }
    Beeping = null;
  }
 
  // Creta elistener to start audio beep
  grp.listen('21/0/1', function(object, state) {
    if (state == 'value' && object.value ) {
       StartBeepTimer();
    } else if( state == 'value' && object.value == false){
        StopBeepTimer();
    }
  }, true);
  
});
BR,

Erwin
Reply


Messages In This Thread
play beep on specific plan - by 3r1ck - 25.10.2019, 16:45
RE: play beep on specific plan - by Erwin van der Zwart - 25.10.2019, 18:35
RE: play beep on specific plan - by 3r1ck - 25.10.2019, 19:43

Forum Jump: