Example #1
0
 public void Run(IBackgroundTaskInstance taskInstance)
 {
     sw         = new Stopwatch();
     repoClient = new RaspiWebService.RepositoryClient();
     _deferral  = taskInstance.GetDeferral();
     InitGPIO();
     if (pinEcho != null & pinTrigger != null)
     {
         var result = repoClient.AddValueAsync("INFO", "RUN METODU İÇİNDEYİZ").Result;
         this.timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(1000));
     }
 }
Example #2
0
        /// <summary>
        /// Ana İşleri Yaptığım Kısım
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //    private void Timer_Tick(ThreadPoolTimer timer)
        //    {
        //        string sensorValue = readSensor.GetSensorValue();
        //        switch (sensorValue)
        //        {
        //            case "000": //Hiç Çizgi Yoksa Çift Motor ileri
        //                movement.SagMotorOnYon();
        //                movement.SolMotorOnYon();
        //                Task.Delay(-1).Wait(ileribeklemesuresisec);
        //                movement.SagMotorDur();
        //                movement.SolMotorDur();
        //                break;
        //            case "010":  //Ortada çizgi var ise Çift Motor ileri
        //                movement.SolMotorOnYon();
        //                movement.SagMotorOnYon();
        //                Task.Delay(-1).Wait(ileribeklemesuresisec);
        //                movement.SolMotorDur();
        //                movement.SagMotorDur();
        //                break;
        //            case "001": //Sola dönüş çizgileri takip et
        //                movement.SolMotorDur();
        //                movement.SagMotorDur();
        //                Task.Delay(-1).Wait(softdonusbeklemesuresisec);
        //                movement.SolMotorOnYon();
        //                movement.SagMotorArkaYon();
        //                break;
        //            case "100": //Sağa dönüş
        //                movement.SolMotorDur();
        //                movement.SagMotorDur();
        //                Task.Delay(-1).Wait(softdonusbeklemesuresisec);
        //                movement.SagMotorOnYon();
        //                movement.SolMotorArkaYon();
        //                break;
        //            case "011": //Sağa keskin dönüş
        //                movement.SolMotorOnYon();
        //                movement.SagMotorArkaYon();
        //                break;
        //            case "110": //Sola keskin dönüş
        //                movement.SolMotorArkaYon();
        //                movement.SagMotorOnYon();
        //                break;
        //            case "111":
        //                movement.SolMotorDur();
        //                movement.SagMotorDur();
        //                break;
        //            default:
        //                movement.SolMotorDur();
        //                movement.SagMotorDur();
        //                break;
        //        }
        //    //}

        private async void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                pinEcho    = null;
                pinTrigger = null;
                await repoClient.AddValueAsync("INFO", "There is no GPIO controller on this device");

                return;
            }

            pinEcho    = gpio.OpenPin(ECHO_PIN);
            pinTrigger = gpio.OpenPin(TRIGGER_PIN);

            pinTrigger.SetDriveMode(GpioPinDriveMode.Output);
            pinEcho.SetDriveMode(GpioPinDriveMode.Input);
            await repoClient.AddValueAsync("INFO", "GPIO controller and pins initialized successfully.");

            pinTrigger.Write(GpioPinValue.Low);

            await Task.Delay(100);
        }