Пример #1
0
        public MainPage()
        {
            this.InitializeComponent();

            // 初始化IoT
            objIoT = new Objects.IoTObj(strIoTHubUrl, strDeviceId, strDeviceKey)
            {
                StatusEllipse   = IoTHubLED,
                StatusTextBlock = txtIoTStatus,
                StatusLastTime  = txtIoTTime,
                FromIoTMessage  = txtFromIoTMessage,
            };
            objIoT.Received += ObjIoT_Received;
            objIoT.Open();

            // 啟動偵測功能
            objSensor = new Objects.SensorObj(objGpioController, intSensorPin, 59, txtSensorStatus, SensorLED, txtSensorTime, objIoT);
        }
Пример #2
0
        public SensorObj(GpioController objGpioController, int intSensorPinNo, int intTelemetrySecound, TextBlock objStatusTextBlock, Ellipse objStatusEllipse, TextBlock objLastTime, IoTObj objIoTHub)
        {
            // 放入偵測物件必須的四個屬性
            this.SensorPinNo      = intSensorPinNo;
            this.TelemetrySecound = intTelemetrySecound;
            this.StatusTextBlock  = objStatusTextBlock;
            this.StatusEllipse    = objStatusEllipse;
            this.StatusLastTime   = objLastTime;
            this.objGpio          = objGpioController;

            // 放入IoTObj
            this.IoTHub = objIoTHub;

            // Sensor
            tiSensor          = new DispatcherTimer();
            tiSensor.Interval = TimeSpan.FromMilliseconds(this.TelemetrySecound * 1000);
            tiSensor.Tick    += tiSensor_Tick;

            // 初始化GPIO pin
            InitGPIO();
        }