コード例 #1
0
        //LIFE CYCLE CONTROL
        protected override void OnPause()
        {
            PubSubHandler.GetInstance().Unsubscribe <TagMessage>(_tagEventToken);
            PubSubHandler.GetInstance().Unsubscribe <RfidTriggeredMessage>(_rfIdTriggeredEventToken);
            HoneywellDeviceHub.GetInstance().Detach();

            base.OnPause();
        }
コード例 #2
0
        //LIFE CYCLE CONTROL

        protected override void OnResume()
        {
            base.OnResume();

            HoneywellDeviceHub.GetInstance().Attach();

            _rfIdTriggeredEventToken = PubSubHandler.GetInstance().Subscribe <RfidTriggeredMessage>(OnRfidTriggerMessage);
            _tagEventToken           = PubSubHandler.GetInstance().Subscribe <TagMessage>(OnTagMessage);
        }
コード例 #3
0
        public void OnSensorChanged(SensorEvent e)
        {
            if (e.Values.Count <= 0)
            {
                return;
            }

            var value = e.Values[0];

            var diff = Math.Abs(_lastPressure - value);

            if (!(diff > _updateThreshold))
            {
                return;
            }
            Log.Debug(Tag, "sensor changed: " + value);
            _lastPressure = value;
            PubSubHandler.GetInstance().Publish(new PressureMessage(this, value));
        }
コード例 #4
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);
        }
コード例 #5
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;
            }
        }
コード例 #6
0
 public void OnTagRead(TagReadData[] tagReadData)
 {
     PubSubHandler.GetInstance().Publish(new TagMessage(this, tagReadData));
 }
コード例 #7
0
        public void Initialize()
        {
            if (_useHubs)
            {
                InitializeHubs();
            }


            SensorManager          = (SensorManager)GetSystemService(SensorService);
            _dynamicSensorCallback = new WeatherDynamicSensorCallback(this);


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

            try
            {
                _ledRainbowStrip            = new Apa102(BoardDefaults.GetSpiBus(), Apa102.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 = PeripheralManager.Instance;
                _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(),
                                                           Button.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 = RainbowHat.CreateSensorDriver();
                // Register the drivers with the framework

                SensorManager.RegisterDynamicSensorCallback(_dynamicSensorCallback);

                _bmx280SensorDriver.RegisterTemperatureSensor();
                _bmx280SensorDriver.RegisterPressureSensor();
                _bmx280SensorDriver.RegisterHumiditySensor();
                Log.Debug(Tag, "Initialized I2C BMP280");
            }
            catch (IOException e)
            {
                throw new RuntimeException("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;
            }
        }
コード例 #8
0
 public void OnTriggerModeSwitched(TriggerMode mode)
 {
     PubSubHandler.GetInstance().Publish(new RfidTriggerModeMessage(this, mode));
 }
コード例 #9
0
 public void OnRfidTriggered(bool triggered)
 {
     PubSubHandler.GetInstance().Publish(new RfidTriggeredMessage(this, triggered));
 }
コード例 #10
0
 public void OnDeviceDisconnected(Object data)
 {
     PubSubHandler.GetInstance().Publish(new RfidDisconnectedMessage(this, data));
 }