Esempio n. 1
0
        public HumiditySensor()
        {
            _peripheralManagerService = new PeripheralManagerService();
            _rawDevice = _peripheralManagerService.OpenI2cDevice(_peripheralManagerService.I2cBusList.First(), ADDRESS);

            InitHandler();
        }
        private static string GetBoardVariant()
        {
            if (!string.IsNullOrEmpty(BoardVariant))
            {
                return(BoardVariant);
            }
            BoardVariant = Build.Device;
            // For the edison check the pin prefix
            // to always return Edison Breakout pin name when applicable.
            if (!BoardVariant.Equals(DeviceEdison))
            {
                return(BoardVariant);
            }

            var pioService = new PeripheralManagerService();
            var gpioList   = pioService.GpioList;

            if (gpioList.Count == 0)
            {
                return(BoardVariant);
            }

            var pin = gpioList[0];

            if (pin.StartsWith("IO"))
            {
                BoardVariant = DeviceEdisonArduino;
            }

            return(BoardVariant);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Log.Info(TAG, "Starting BlinkActivity");

            var service = new PeripheralManagerService();

            try
            {
                string pinName = BoardDefaults.GetGpioForLed();
                _ledGpio = service.OpenGpio(pinName);
                _ledGpio.SetDirection(Gpio.DirectionOutInitiallyLow);

                Log.Info(TAG, "Start blinking LED GPIO pin");

                Task.Run(() =>
                {
                    while (true)
                    {
                        _ledGpio.Value = !_ledGpio.Value;

                        Log.Info(TAG, "State set to " + _ledGpio.Value);

                        Thread.Sleep(100);
                    }
                });
            }
            catch (Exception e)
            {
                Log.Error(TAG, "Error on PeripheralIO API", e);
            }
        }
        public Joystick(Keycode[] keyCodes)
        {
            _keyCodes = keyCodes;
            _peripheralManagerService = new PeripheralManagerService();

            InitHandler();
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _peripheralManagerService?.Dispose();
         _peripheralManagerService = null;
     }
 }
        public LedMatrix(string bus)
        {
            var pioService = new PeripheralManagerService();

            _device
                =
                    pioService.OpenI2cDevice
                        (bus, SenseHat.I2CAddress);
        }
 static ComponentsManager()
 {
     try {
         string pinName = GetGpioForLed();
         Current = new PeripheralManagerService();
     } catch (Exception ex) {
         Console.Write(ex);
     }
 }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                _handler?.RemoveCallbacks(_listenerAction);
                _handler?.Dispose();
                _handler        = null;
                _listenerAction = null;

                _peripheralManagerService?.Dispose();
                _peripheralManagerService = null;
            }
        }
Esempio n. 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var peripheralMgr = new PeripheralManagerService();

            foreach (var gpio in peripheralMgr.GpioList)
            {
                Android.Util.Log.Debug(TAG, "Found Peripheral: {0}", gpio);
            }
        }
Esempio n. 10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Log.Info(TAG, "Starting AlarmActivity");

            var service = new PeripheralManagerService();

            _alarm1Gpio = service.OpenGpio("IO8");
            _buzzerGpio = service.OpenGpio("IO4");
            _buzzerGpio.SetDirection(Gpio.DirectionOutInitiallyLow);

            ConfigureAlarmInput();
        }
Esempio n. 11
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.activity_main);

            var gpioPinsView = (LinearLayout)FindViewById(Resource.Id.gpio_pins);
            var inflater     = LayoutInflater;
            var pioService   = new PeripheralManagerService();


            foreach (var gpIoName in pioService.GpioList)
            {
                var child  = inflater.Inflate(Resource.Layout.list_item_gpio, gpioPinsView, false);
                var button = (Switch)child.FindViewById(Resource.Id.gpio_switch);
                button.Text = gpIoName;
                gpioPinsView.AddView(button);

                Log.Info(TAG, "Added button for GPIO: " + gpIoName);

                try
                {
                    var ledPin = pioService.OpenGpio(gpIoName);
                    ledPin.SetEdgeTriggerType(Gpio.EdgeNone);
                    ledPin.SetActiveType(Gpio.ActiveHigh);
                    ledPin.SetDirection(Gpio.DirectionOutInitiallyLow);

                    button.CheckedChange += (sender, args) =>
                    {
                        try
                        {
                            ledPin.Value = args.IsChecked;
                        }
                        catch (IOException e)
                        {
                            Log.Error(TAG, "error toggling gpio:", e);
                        }
                    };

                    _gpioMap[gpIoName] = ledPin;
                }
                catch (IOException e)
                {
                    Log.Error(TAG, "Error initializing GPIO: " + gpIoName, e);
                    button.Enabled = false;
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            _service = new PeripheralManagerService();

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.myButton);

            button.Click += delegate { button.Text = $"{count++} clicks!"; };

            SetupDemo1();
            SetupDemo2();
            SetupDemo3();
        }
Esempio n. 13
0
        protected virtual void Dispose(bool disposing)
        {
            _rawDevice?.Close();
            _rawDevice?.Dispose();
            _rawDevice = null;

            if (disposing)
            {
                _handler?.RemoveCallbacks(_listenerAction);
                _handler?.Dispose();
                _handler        = null;
                _listenerAction = null;

                _temperatureConversion = null;
                _humidityConversion    = null;

                _peripheralManagerService?.Dispose();
                _peripheralManagerService = null;
            }
        }
Esempio n. 14
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            listView = FindViewById <ListView>(Resource.Id.listView1);

            var peripheralMgr = new PeripheralManagerService();

            var gpios = peripheralMgr.GpioList;

            foreach (var gpio in gpios)
            {
                Android.Util.Log.Debug(TAG, "Found Peripheral: {0}", gpio);
            }

            adapter = new ArrayAdapter <string>(this, global::Android.Resource.Layout.SimpleListItem1, gpios);

            listView.Adapter = adapter;
        }
Esempio n. 15
0
        private static string GetBoardVariant()
        {
            if (!string.IsNullOrEmpty(BoardVariant))
            {
                return(BoardVariant);
            }
            BoardVariant = Build.Device;

            if (BoardVariant.Equals(DEVICE_EDISON))
            {
                var pioService = new PeripheralManagerService();
                var gpioList   = pioService.GpioList;
                if (gpioList.Count != 0)
                {
                    string pin = gpioList[0];
                    if (pin.StartsWith("IO"))
                    {
                        BoardVariant = DEVICE_EDISON_ARDUINO;
                    }
                }
            }
            return(BoardVariant);
        }
Esempio n. 16
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            // SetContentView(Resource.Layout.Main);

            var peripheralMgr = new PeripheralManagerService();

            var gpios = peripheralMgr.GpioList;

            foreach (var gpio in gpios)
            {
                Android.Util.Log.Debug(TAG, "Found Peripheral: {0}", gpio);
            }

            ledGpio = peripheralMgr.OpenGpio(GPIO_PIN);
            ledGpio.SetDirection(Gpio.DirectionOutInitiallyHigh);

            var timer = new Timer(1000);

            timer.Elapsed += ToggleLED;
            timer.Start();
        }
Esempio n. 17
0
 public IoTPin(Connectors connector)
 {
     service = ComponentsManager.Current;
     pin     = service.OpenGpio(connector.Pin());
 }
Esempio n. 18
0
 public PressureSensor()
 {
     _peripheralManagerService = new PeripheralManagerService();
     _rawDevice = _peripheralManagerService.OpenI2cDevice(_peripheralManagerService.I2cBusList.First(), ADDRESS0);
 }
Esempio n. 19
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            if (_useHubs)
            {
                InitializeHubs();
            }


            SetContentView(Resource.Layout.Main);

            SensorManager          = (SensorManager)GetSystemService(SensorService);
            _dynamicSensorCallback = new WeatherDynamicSensorCallback(this);
            _imageView             = FindViewById <ImageView>(Resource.Id.imageView);

            PubSubHandler.GetInstance().Subscribe <TemperatureMessage>(OnTemperatureMessage);
            PubSubHandler.GetInstance().Subscribe <PressureMessage>(OnPressureMessage);
            PubSubHandler.GetInstance().Subscribe <HumidityMessage>(OnHumidityMessage);

            try
            {
                _ledRainbowStrip            = new Apa102Contrib(BoardDefaults.GetSpiBus(), Apa102Contrib.Mode.Bgr);
                _ledRainbowStrip.Brightness = LedstripBrightness;
                for (var i = 0; i < _rainbow.Length; i++)
                {
                    float[] hsv = { i * 360f / _rainbow.Length, 1.0f, 1.0f };

                    _rainbow[i] = Color.HSVToColor(255, hsv);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
                _ledRainbowStrip = null;
            }

            try
            {
                var pioService = new PeripheralManagerService();
                _led = pioService.OpenGpio(BoardDefaults.GetLedGpioPin());
                _led.SetEdgeTriggerType(Gpio.EdgeNone);
                _led.SetDirection(Gpio.DirectionOutInitiallyLow);
                _led.SetActiveType(Gpio.ActiveHigh);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }

            try
            {
                _buttonInputDriver = new ButtonInputDriver(BoardDefaults.GetButtonGpioPin(),
                                                           ButtonContrib.LogicState.PressedWhenLow,
                                                           (int)KeyEvent.KeyCodeFromString("KEYCODE_A"));
                _buttonInputDriver.Register();
                Log.Debug(Tag, "Initialized GPIO Button that generates a keypress with KEYCODE_A");
            }
            catch (Exception e)
            {
                throw new Exception("Error initializing GPIO button", e);
            }

            try
            {
                _bmx280SensorDriver = new Bmx280SensorDriver(BoardDefaults.GetI2cBus());
                SensorManager.RegisterDynamicSensorCallback(_dynamicSensorCallback);
                _bmx280SensorDriver.RegisterTemperatureSensor();
                _bmx280SensorDriver.RegisterPressureSensor();
                _bmx280SensorDriver.RegisterHumiditySensor();
                Log.Debug(Tag, "Initialized I2C BMP280");
            }
            catch (Exception e)
            {
                throw new Exception("Error initializing BMP280", e);
            }

            try
            {
                _display = new AlphanumericDisplay(BoardDefaults.GetI2cBus());
                _display.SetEnabled(true);
                _display.Clear();
                Log.Debug(Tag, "Initialized I2C Display");
            }
            catch (Exception e)
            {
                Log.Error(Tag, "Error initializing display", e);
                Log.Debug(Tag, "Display disabled");
                _display = null;
            }


            try
            {
                Speaker = new Speaker(BoardDefaults.GetSpeakerPwmPin());
                var slide = ValueAnimator.OfFloat(440, 440 * 4);
                slide.SetDuration(50);
                slide.RepeatCount = 5;
                slide.SetInterpolator(new LinearInterpolator());
                slide.AddUpdateListener(new SlideUpdateListener(this));

                //  slide.Start();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
                throw;
            }
        }
 public LedMatrix()
 {
     _peripheralManagerService = new PeripheralManagerService();
 }