Exemplo n.º 1
0
        private static void RunEKG()
        {
            SPO2Reader    reader    = new SPO2Reader("/dev/tty.SLAB_USBtoUART", 500);
            SPO2Processor processor = new SPO2Processor(reader);

            processor.Start();

            int previousBPM = 0;

            while (true)
            {
                processor.Update();
                int bpm = processor.GetBPM();
                if (previousBPM != bpm)
                {
                    previousBPM = bpm;
                    Console.WriteLine(bpm);
                }
            }
        }
Exemplo n.º 2
0
        private void WriteLoop()
        {
            SPO2Reader    reader    = new SPO2Reader(port, 100000);
            SPO2Processor processor = new SPO2Processor(reader);

            processor.Start();

            List <SPO2Packet> allPackets = new List <SPO2Packet>();
            List <BPMEvent>   bpmEvents  = new List <BPMEvent>();

            bool startWriting = false;

            while (!done)
            {
                processor.Update();

                List <SPO2Packet> packets = processor.ProcessedPackets;
                BPMEvent          bpmEvent;
                bpmEvent.bpm       = processor.GetBPM();
                bpmEvent.timestamp = DateTime.Now.Ticks;
                if (bpmEvent.bpm != 0)
                {
                    startWriting = true;
                }

                if (startWriting)
                {
                    allPackets.AddRange(packets);
                    bpmEvents.Add(bpmEvent);
                }

                Thread.Sleep(10);
            }

            processor.StopAndJoin();

            Console.WriteLine("Done. Packets read: " + allPackets.Count);
            Console.WriteLine("Filename base: " + filenameBase);
            Console.WriteLine("Writing files...");

            StringBuilder rawBpms  = new StringBuilder();
            StringBuilder procBpms = new StringBuilder();
            StringBuilder peaks    = new StringBuilder();

            foreach (SPO2Packet packet in allPackets)
            {
                int    rawHr = packet.HeartRate;
                string line  = rawHr.ToString() + "," + packet.timeStamp;
                rawBpms.AppendLine(line);

                line = (packet.Peak ? "1" : "0") + "," + packet.timeStamp;
                peaks.AppendLine(line);
            }

            foreach (BPMEvent ev in bpmEvents)
            {
                string line = ev.bpm.ToString() + "," + ev.timestamp;
                procBpms.AppendLine(line);
            }

            File.WriteAllText(filenameBase + "-RawBpm.csv", rawBpms.ToString());
            File.WriteAllText(filenameBase + "-ProcBpm.csv", procBpms.ToString());
            File.WriteAllText(filenameBase + "-Peaks.csv", peaks.ToString());
        }