Esempio n. 1
0
        static void GestureMode(Nusbio nusbio, GY_9960LLC gy_9960LLC)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Gesture Mode", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 5, "Q)uit");
            while (true)
            {
                Thread.Sleep(100);
                var isGestureAvailable = gy_9960LLC.isGestureAvailable();
                //ConsoleEx.WriteMenu(-1, 2, string.Format("InterruptOn:{0}, isGestureAvailable:{1}",
                Console.WriteLine(string.Format("InterruptOn:{0}, isGestureAvailable:{1}",
                                                gy_9960LLC.InterruptOn(), isGestureAvailable
                                                ));

                if (isGestureAvailable)
                {
                    var g = gy_9960LLC.readGesture();
                    if (g != GY_9960LLC.Direction.DIR_NONE)
                    {
                        Console.WriteLine(string.Format("Gest:{0}", g));
                    }
                }

                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey();
                    if (k.Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("nusbio not detected");
                return;
            }

            var sclPin       = NusbioGpio.Gpio0;
            var sdaPin       = NusbioGpio.Gpio1;
            var interruptPin = NusbioGpio.Gpio2;

            using (var nusbio = new Nusbio(serialNumber)) // ,
            {
                gy_9960LLC = new GY_9960LLC(nusbio, sdaPin, sclPin, interruptPin, GY_9960LLC.APDS9960_I2C_ADDR);

                Cls(nusbio);

                while (nusbio.Loop())
                {
                    TimePeriod.Sleep(100);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.A)
                        {
                            Cls(nusbio);
                        }
                        //if (k == ConsoleKey.G)
                        //    LightSensor(nusbio, gy_9960LLC);
                        if (k == ConsoleKey.G)
                        {
                            GestureMode(nusbio, gy_9960LLC);
                        }
                        if (k == ConsoleKey.Q)
                        {
                            break;
                        }
                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }
Esempio n. 3
0
        static bool LightSensorMode(Nusbio nusbio, GY_9960LLC apds)
        {
            //Console.Clear();
            //ConsoleEx.TitleBar(0, "Light Sensor Mode", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            //ConsoleEx.WriteMenu(-1, 5, "Q)uit");

            //// Set high and low interrupt thresholds
            //if (!apds.setLightIntLowThreshold(LIGHT_INT_LOW))
            //    return Error("Error writing low threshold");

            //if (!apds.setLightIntHighThreshold(LIGHT_INT_HIGH))
            //    return Error("Error writing high threshold");

            //// Start running the APDS-9960 light sensor (no interrupts)
            //if (apds.enableLightSensor(false))
            //{
            //    return Error("Light sensor is now running");
            //}
            //else
            //{
            //    Serial.println(F("Something went wrong during light sensor init!"));
            //}

            //// Read high and low interrupt thresholds
            //if (!apds.getLightIntLowThreshold(threshold))
            //{
            //    Serial.println(F("Error reading low threshold"));
            //}
            //else
            //{
            //    Serial.print(F("Low Threshold: "));
            //    Serial.println(threshold);
            //}
            //if (!apds.getLightIntHighThreshold(threshold))
            //{
            //    Serial.println(F("Error reading high threshold"));
            //}
            //else
            //{
            //    Serial.print(F("High Threshold: "));
            //    Serial.println(threshold);
            //}

            //// Enable interrupts
            //if (!apds.setAmbientLightIntEnable(1))
            //{
            //    Serial.println(F("Error enabling interrupts"));
            //}

            //// Wait for initialization and calibration to finish
            //delay(500);

            //while (true)
            //{
            //    Thread.Sleep(100);

            //    if (Console.KeyAvailable)
            //    {
            //        var k = Console.ReadKey();
            //        if (k.Key == ConsoleKey.Q)
            //            break;
            //    }

            //}
            return(true);
        }