private void enforceOrder <T>(List <T> someList) where T : Thalmic.Myo.MyoEventArgs { bool ordered = true; var i = someList.GetEnumerator(); if (i.MoveNext()) { DateTime lastTime = i.Current.Timestamp; while (i.MoveNext()) { DateTime currentTime = i.Current.Timestamp; if (DateTime.Compare(currentTime, lastTime) < 0) { ordered = false; break; } lastTime = currentTime; } } if (!ordered) { Debug.LogError("Events are not ordered. TODO order them!"); throw new System.NotImplementedException(); } }
private DateTime GetCooldownTime() { if (object.Equals(_rewardCooldownTime, default(DateTime))) { if (PlayerPrefs.HasKey(_keyCooldownTime)) { _rewardCooldownTime = DateTime.Parse(PlayerPrefs.GetString(_keyCooldownTime)); if (Debug.isDebugBuild) { DateTime appStartTime = DateTime.UtcNow.AddSeconds(-1 * Time.time); DateTime lastRewardTime = _rewardCooldownTime.AddSeconds(-1 * cooldownTime); if (DateTime.Compare(appStartTime, lastRewardTime) > 0) { ResetCooldownTime(); } } } else { _rewardCooldownTime = DateTime.UtcNow; } } return(_rewardCooldownTime); }
private void timer_Tick(object sender, EventArgs e) { this.clockLabel.Text = DateTime.Now.ToString("HH:mm:ss"); this.dateLabel.Text = DateTime.Now.ToString("dddd, dd MMMM yyyy"); if (DateTime.Compare(DateTime.Now, alarm) > 0 && isAlarmActive) { isAlarmActive = false; this.alarmLabel.Text = String.Empty; MessageBox.Show("Alarm!!!"); } }
public static IEnumerable <DateRange> Collapse(IEnumerable <DateRange> ranges) { var r = ranges.ToList(); while (InnerCollapse(r)) { } r.Sort((a, b) => DateObject.Compare(a.Start, b.Start)); return(r); }
private bool IsReady() { if (DateTime.Compare(DateTime.UtcNow, _rewardCooldownTime) > 0) { return(UnityAdsHelper.IsReady(placementId)); } else { return(false); } }
public void Update() { lock (_lock) { // we sure can't do it online since we need to know the next gyroscope reading // doing it precisely can be a bit inefficient (have to slice the gyroscope values with accel times) // so, we'll have two modes: // 1. precise mode // 2. imprecise mode // precise mode is confusing. may not even exist... // make sure the values are ordered in time, so that we can merge them. enforceOrder(gyroscopeEvents); enforceOrder(accelerometerEvents); var gyroEnum = gyroscopeEvents.GetEnumerator(); var accelEnum = accelerometerEvents.GetEnumerator(); bool gyroHasNext = gyroEnum.MoveNext(); bool accelHasNext = accelEnum.MoveNext(); while (gyroHasNext || accelHasNext) { bool useGyro = false; bool useAccel = false; if (gyroHasNext && accelHasNext) { int gyroIsLater = DateTime.Compare(gyroEnum.Current.Timestamp, accelEnum.Current.Timestamp); if (gyroIsLater == 0) { // both are at the same time useGyro = true; useAccel = true; } else if (gyroIsLater > 0) { // accel is before useAccel = true; } else { // gyro is before useGyro = true; } } else { useGyro = gyroHasNext; useAccel = accelHasNext; } bool moveWithGyro = false; bool moveWithAccel = false; // by now, I should // have the effective value for both // have the necessary one(s) advance if (useGyro) { prevGyro = effectiveGyro; effectiveGyro = gyroEnum.Current; gyroHasNext = gyroEnum.MoveNext(); //Debug.Log("1"); if (prevGyro != null) { //Debug.Log("2"); moveWithGyro = true; } } if (useAccel) { prevAccel = effectiveAccel; effectiveAccel = accelEnum.Current; accelHasNext = accelEnum.MoveNext(); //Debug.Log("3"); if (prevAccel != null) { //Debug.Log("4"); moveWithAccel = true; } } if (moveWithGyro && moveWithAccel) { // TODO think about averaging these two if (accelerometerLowpass != null) { Quaternion accelCorrectionForAccelOnly = calculateCorrectionForAccel(prevAccel, effectiveAccel, accelerometerLowpass); applyAccelCorrection(accelerometerLowpass, accelCorrectionForAccelOnly); } if (complementaryFilter != null) { Quaternion accelCorrectionForComplOnly = calculateCorrectionForAccel(prevAccel, effectiveAccel, complementaryFilter); applyAccelCorrection(complementaryFilter, accelCorrectionForComplOnly); Quaternion gyroChange = calculateChangeForGyro(prevGyro, effectiveGyro); applyGyroChange(complementaryFilter, gyroChange); } if (gyroscopeIntegrated != null) { Quaternion gyroChange = calculateChangeForGyro(prevGyro, effectiveGyro); applyGyroChange(gyroscopeIntegrated, gyroChange); } } else { if (moveWithAccel) { // TODO calculate and apply (time will go in here, will scale the contrib.) Debug.Log("move with accel"); // currentup should always be Vector3.up // localaccelup should be the vector in local coords. this is what we read. // accelup should be that vector in global space // this does not require matrix inversion. good. if (accelerometerLowpass != null) { Quaternion accelCorrectionForAccelOnly = calculateCorrectionForAccel(prevAccel, effectiveAccel, accelerometerLowpass); //this is the actual one applyAccelCorrection(accelerometerLowpass, accelCorrectionForAccelOnly); // TODO test this accelerometer thing first. then, merge it with gyro. } if (complementaryFilter != null) { Quaternion accelCorrectionForComplOnly = calculateCorrectionForAccel(prevAccel, effectiveAccel, complementaryFilter); applyAccelCorrection(complementaryFilter, accelCorrectionForComplOnly); } } else if (moveWithGyro) { // TODO calculate and apply Debug.Log("move with gyro"); if (gyroscopeIntegrated != null) { Quaternion gyroChange = calculateChangeForGyro(prevGyro, effectiveGyro); applyGyroChange(gyroscopeIntegrated, gyroChange); } if (complementaryFilter != null) { //this is the actual one // TODO test this accelerometer thing first. then, merge it with gyro. Quaternion gyroChange = calculateChangeForGyro(prevGyro, effectiveGyro); applyGyroChange(complementaryFilter, gyroChange); } } } } //this leaves effective gyro and accel set. what I should do is to initialize them in the very first use. gyroscopeEvents.Clear(); accelerometerEvents.Clear(); // eat up the data. // I have a couple of gyro and accel readings // now order them // for each time duration, // integrate gyro (avg with last value for area) // use //Debug.Log(gyroscopeDataCount + " " + accelerometerDataCount); //gyroscopeDataCount = accelerometerDataCount = 0; //if (gyroscopeIntegrated != null) { // if (cumulativeHasQ) { // gyroscopeIntegrated.localRotation = gyroscopeIntegrated.localRotation * cumulativeDq; // cumulativeDq = Quaternion.identity; // cumulativeHasQ = false; // } //} } }