public ringBuffer() { data = new vector3d[SIZE]; for (int i = 0; i < SIZE; i++) { data[i] = new vector3d(); } }
static void dataRecived(object sender,SerialDataReceivedEventArgs e) { lock (srp) { while (srp.ReadByte() != 0xff) { ; } while (srp.BytesToRead < 12) { ; } // while (srp.BytesToRead > 11) lock (stk) { vector3d V = new vector3d(); byte[] data = new byte[12]; srp.Read(data,0,12); V.x = BitConverter.ToSingle(data,0); V.y = BitConverter.ToSingle(data,4); V.z = BitConverter.ToSingle(data,8); V.x /= 400; V.y /= 400; V.z /= 400; stk.add(V); if (!SIGNAL && !READY_READ && (abs(V.x) > 10.0 || abs(V.y) > 10.0 || abs(V.z) > 10.0)) { SO_POWERFUL = false; SIGNAL = true; Co = 0; sw.Restart(); // sw.Restart(); } if (SIGNAL) { if (abs(V.x) > 60.0 || abs(V.y) > 60.0 || abs(V.z) > 60.0) { SO_POWERFUL = true; } Co += 1; if (Co >= 60) { READY_READ = true && !SO_POWERFUL; SIGNAL = false; // sw.Stop(); } } } } }
public vector3d[] getCopy() { vector3d[] copy = new vector3d[SIZE]; int h = head; for (int i = 0; i < SIZE; i++) { copy[i] = data[h++]; h %= SIZE; } return(copy); }
static double hypot(vector3d V) { return(Math.Sqrt(V.x * V.x + V.y * V.y + V.z * V.z)); }
public void add(vector3d vec) { data[head++] = vec; head %= SIZE; }