<commit_before>package nme.sensors;
#if (!flash)

import nme.errors.ArgumentError;
import nme.events.AccelerometerEvent;
import nme.events.EventDispatcher;
import haxe.Timer;

private class Data
{
   public var x:Float;
   public var y:Float;
   public var z:Float;

   public function new()
   {
      x = y = z = 0.0;
   }
}

@:nativeProperty
class Accelerometer extends EventDispatcher 
{
   public static var isSupported(get, null):Bool;

   public var muted(default, null):Bool;

   private static var defaultInterval:Int = 34;

   var data:Data;

   /** @private */ private var timer:Timer;
   public function new() 
   {
      super();

      data = new Data();

      setRequestedUpdateInterval(defaultInterval);
   }

   override public function addEventListener(type:String, listener:Function, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void 
   {
      super.addEventListener(type, listener, useCapture, priority, useWeakReference);
      update();
   }

   public static function get_isSupported() return nme.ui.Accelerometer.isSupported();

   public function setRequestedUpdateInterval(interval:Float):Void 
   {
      if (interval < 0) 
      {
         throw new ArgumentError();

      } else if (interval == 0) 
      {
         interval = defaultInterval;
      }

      if (timer != null) 
      {
         timer.stop();
      }

      if (isSupported) 
      {
         timer = new Timer(interval);
         timer.run = update;
      }
   }

    public function removeInterval():Void {
        timer.stop();
    }
<commit_msg>Avoid crash for unsupported accelerometer (#667)<commit_after>package nme.sensors;
#if (!flash)

import haxe.ds.Option;
import nme.errors.ArgumentError;
import nme.events.AccelerometerEvent;
import nme.events.EventDispatcher;
import haxe.Timer;

private class Data
{
   public var x:Float;
   public var y:Float;
   public var z:Float;

   public function new()
   {
      x = y = z = 0.0;
   }
}

@:nativeProperty
class Accelerometer extends EventDispatcher 
{
   public static var isSupported(get, null):Bool;

   public var muted(default, null):Bool;

   private static var defaultInterval:Int = 34;

   var data:Data;

   /** @private */ private var timer:Option<Timer> = None;
   public function new() 
   {
      super();

      data = new Data();

      setRequestedUpdateInterval(defaultInterval);
   }

   override public function addEventListener(type:String, listener:Function, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void 
   {
      super.addEventListener(type, listener, useCapture, priority, useWeakReference);
      update();
   }

   public static function get_isSupported() return nme.ui.Accelerometer.isSupported();

   public function setRequestedUpdateInterval(interval:Float):Void 
   {
      if (interval < 0) 
      {
         throw new ArgumentError();

      } else if (interval == 0) 
      {
         interval = defaultInterval;
      }

      switch (timer) {
         case None:
         case Some(t):
            t.stop();
      }

      if (isSupported) 
      {
         var t:Timer = new Timer(interval);
         t.run = update;
         timer = Some(t);
      }
   }

    public function removeInterval():Void {
       switch (timer) {
          case None:
          case Some(t):
             t.stop();
       }
    }

{'fraction_non_alphanumeric': 0.10513810513810513, 'fraction_numerical': 0.005049005049005049, 'mean_word_length': 2.605995717344754, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6416952', 'n_tokens_mistral': 1031, 'n_tokens_neox': 963, 'n_words': 254}