<commit_before>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO.Ports;

public class Rangefinder : MonoBehaviour
{
    public static Rangefinder Instance;

    [System.NonSerialized]
    public float distance_cm;

    [System.NonSerialized]
    public float raw_cm;
    [System.NonSerialized]
    public float last_raw_cm;

    [System.NonSerialized]
    public float idleTime;

    [System.NonSerialized]
    public bool IsActive;

    private SerialPort sp = new SerialPort("COM4", 9600);
    private List<float> buffer;
    private List<float> rawBuffer;

    private GameManager gameManager;

    public void Reset() {
      idleTime = 0f;
      // Game starts in attract mode where sensor sweep should be empty and
      // sensor value should be maxed out.
      distance_cm = gameManager.SensorMaxDistance;
      buffer = new List<float>() {distance_cm};
      rawBuffer = new List<float>() {0};
    }

    void Awake() {
      Instance = this;
    }

    void Start() {
      gameManager = GameManager.Instance;
      Reset();
      StartCoroutine("Connect");
    }

    void Update() {
      IsActive = sp.IsOpen;

      if (IsActive) {
        ReadSerialData();
      } else {
        if (Input.GetKey(KeyCode.DownArrow)) {
          distance_cm += 40 * Time.deltaTime;
        } else if (Input.GetKey(KeyCode.UpArrow)) {
          distance_cm -= 40 * Time.deltaTime;
        }
      }

      distance_cm = Mathf.Max(distance_cm, gameManager.SensorMinDistance);

      // Accrue idle time when sensor gets no readings (zeroes) or average
      // distance is beyond the max.
      var min_cm = gameManager.SensorMinDistance;
      var max_cm = gameManager.SensorMaxDistance;
      if (raw_cm < min_cm * 0.25 || distance_cm >= max_cm) {
        idleTime += Time.deltaTime;
      } else {
        idleTime = 0f;
      }
    }<commit_msg>Resets idle timer when moving with keyboard.<commit_after>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO.Ports;

public class Rangefinder : MonoBehaviour
{
    public static Rangefinder Instance;

    [System.NonSerialized]
    public float distance_cm;

    [System.NonSerialized]
    public float raw_cm;
    [System.NonSerialized]
    public float last_raw_cm;

    [System.NonSerialized]
    public float idleTime;

    [System.NonSerialized]
    public bool IsActive;

    private SerialPort sp = new SerialPort("COM4", 9600);
    private List<float> buffer;
    private List<float> rawBuffer;

    private GameManager gameManager;

    public void Reset() {
      idleTime = 0f;
      // Game starts in attract mode where sensor sweep should be empty and
      // sensor value should be maxed out.
      distance_cm = gameManager.SensorMaxDistance;
      buffer = new List<float>() {distance_cm};
      rawBuffer = new List<float>() {0};
    }

    void Awake() {
      Instance = this;
    }

    void Start() {
      gameManager = GameManager.Instance;
      Reset();
      StartCoroutine("Connect");
    }

    void Update() {
      IsActive = sp.IsOpen;

      if (IsActive) {
        ReadSerialData();
      } else {
        if (Input.GetKey(KeyCode.DownArrow)) {
          distance_cm += 40 * Time.deltaTime;
          idleTime = 0f;
        } else if (Input.GetKey(KeyCode.UpArrow)) {
          distance_cm -= 40 * Time.deltaTime;
          idleTime = 0f;
        }
      }

      distance_cm = Mathf.Max(distance_cm, gameManager.SensorMinDistance);

      // Accrue idle time when sensor gets no readings (zeroes) or average
      // distance is beyond the max.
      var min_cm = gameManager.SensorMinDistance;
      var max_cm = gameManager.SensorMaxDistance;
      if (raw_cm < min_cm * 0.25 || distance_cm >= max_cm) {
        idleTime += Time.deltaTime;
      } else {
        idleTime = 0f;
      }
    }
{'fraction_non_alphanumeric': 0.09556751217012555, 'fraction_numerical': 0.008198821419420958, 'mean_word_length': 2.504488330341113, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2462406', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1156, 'n_words': 312}