Esempio n. 1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();  // get the deferral handle

            int count = 0;

            MAX7219             driver = new MAX7219(2);
            SevenSegmentDisplay ssd    = new SevenSegmentDisplay(driver);
            BMP180 bmp = new BMP180(BMP180.Mode.HIGHRES);

            ssd.FrameClear();
            ssd.FrameDraw();
            ssd.SetBrightness(4);

            while (true)
            {
                temperature = bmp.Temperature.DegreesCelsius;

                data.Clear();

                // is temperature less than 3 digits and there is a decimal part too then right pad to 5 places as decimal point does not take up a digit space on the display
                if (temperature < 100 && temperature != (int)temperature)
                {
                    data.Append($"{Math.Round(temperature, 1)}C".PadRight(5));
                }
                else
                {
                    data.Append($"{Math.Round(temperature, 0)}C".PadRight(4));
                }

                data.Append(Math.Round(bmp.Pressure.Hectopascals, 0));

                if (blink = !blink)
                {
                    data.Append(".");
                }                                          // add a blinking dot on bottom right as an I'm alive indicator

                ssd.DrawString(data.ToString());

                ssd.DrawString(count++, 1);

                ssd.FrameDraw();

                Task.Delay(2000).Wait();
            }
        }
Esempio n. 2
0
        private async Task InitDisplay()
        {
            /* Initialize the display */
            try
            {
                var driver = new MAX7219(2);
                ssd = new SevenSegmentDisplay(driver);
                ssd.FrameClear();
                ssd.FrameDraw();
                ssd.SetBrightness(10);

                await SerialWriteAsync("Starting...");
            }
            catch (Exception ex)
            {
                throw new Exception("Display Initialization Failed", ex);
            }
        }
Esempio n. 3
0
        public static void Main()
        {
            daq.Initialize(GoSockets.Socket4);

            var state = daq.GetClockState();

            if (state == NwazetDAQ.ClockState.Invalid)
            {
                daq.SetDateTime(new DateTime(2012, 10, 05, 20, 39, 00));
            }

            var usartConfig = new UsartConfig();

            usartConfig.BaudRate = UsartBaudRate.Baud57600;
            daq.UsartPort.SetConfig(usartConfig);

            daq.UsartPort.Write("\r\n\r\nNwazet DAQ Pro Kit - demo\r\n");

            canvas.Initialize(GoSockets.Socket5);
            canvas.SetOrientation(Orientation.Landscape);

            InitDisplay();

            seg.SetBrightness(.1f);
            seg.SetColon(true);

            while (true)
            {
                var hih    = new HIH613x(daq.I2cPort);
                var bmp085 = new BoschBmp085(daq.I2cPort);
                var taos   = new TaosTSL256x(daq.I2cPort);

                var       pressure = 0;
                AdcSample sample   = null;
                try {
                    while (true)
                    {
                        try {
                            seg.SetBrightness(pot.GetValue());
                            sample = daq.ReadAnalogInputs();
                            ShowTime(sample.Time);
                            hih.Read();
                            pressure = bmp085.ReadPressurePascals();
                            taos.Read();
                        } catch (I2cException e) {
                            Debug.Print("I2C transaction failed: " + e.Message);
                            daq.I2cPort.BusReset();
                        }
                        UpdateDisplay(hih.TemperatureCelsius, hih.RelativeHumidityPercent, pressure, taos.Lux, taos.InfraredSpectrum, sample);

                        daq.UsartPort.Write(
                            sample.Time.ToString() + "," +
                            hih.TemperatureCelsius + "," +
                            hih.RelativeHumidityPercent + "," +
                            pressure + "," +
                            taos.Lux + "," +
                            taos.InfraredSpectrum + "," +
                            sample.Values[(int)ADC.A0].ToString()
                            + "\r\n");
                    }
                } catch (Exception e) {
                    Debug.Print("Other exception: " + e.Message);
                    hih.Dispose();
                    bmp085.Dispose();
                    taos.Dispose();
                }
            }
        }