Exemple #1
0
 private void set_led_current(LED_CURRENT led_current_red = LED_CURRENT.L11_0, LED_CURRENT led_current_ir = LED_CURRENT.L11_0)
 {
     Set(LED_CONFIG, (byte)(((int)led_current_red << 4) | (int)led_current_ir));
     Console.WriteLine("LED config : " + Get(LED_CONFIG));
 }
Exemple #2
0
        public Max30100(byte mode = MODE_HR,
                        SAMPLE_RATE sample_rate     = SAMPLE_RATE.R100,
                        LED_CURRENT led_current_red = LED_CURRENT.L11_0,
                        LED_CURRENT led_current_ir  = LED_CURRENT.L11_0,
                        PULSE_WIDTH pulse_width     = PULSE_WIDTH.P1600,
                        int max_buffer_len          = 10000
                        )
        {
            new Thread(new ThreadStart(delegate
            {
                var list  = new List <int[]>();
                int count = 0;
                while (Program.appRun)
                {
                    if (Program.pause)
                    {
                        Thread.Sleep(2000);
                        if (isStart)
                        {
                            shutdown();
                        }
                    }
                    else
                    {
                        if (!isStart)
                        {
                            start();
                        }
                        var data = read_sensor();
                        if (data == null)
                        {
                            continue;
                        }
                        list.Insert(0, data);
                        list          = list.Take(10).ToList();
                        var hasfinger = list.Count(i => i[0] == 0) < 2;
                        HasFinger     = hasfinger;

                        if (count == 10)
                        {
                            if (HasFinger)
                            {
                                var moyenIR = (int)list.Average(i => i[0]);
                                var ir      = moyenIR / 100 - 40;
                                IR          = ir > 90 ? 90 : ir < 40 ? 0 : ir;


                                var red = (int)(((double)(data[1] / 10000.0) - 0.05) * 100.0);
                                RED     = IR == 0 ? 0 : (red > 100 ? 100 : red < 0 ? 0 : red) - 1;
                            }
                            else
                            {
                                IR = RED = 0;
                            }
                        }
                        count++;
                        if (count >= 11)
                        {
                            count = 0;
                        }
                    }
                }
            })).Start();
        }