コード例 #1
0
 /// <summary>
 /// Initial application - Done once
 /// </summary>
 /// <returns></returns>
 private bool InitApplication(LoggingChannel logging, AzureIoTHubService azureIoTService, GPIOService gpioService)
 {
     //Config
     //var localSettings = ApplicationData.Current.LocalSettings;
     _logging            = logging;
     _azureIoTHubService = azureIoTService;
     _gpioService        = gpioService;
     return(true);
 }
コード例 #2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //Deferral task to allow for async
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            //Config
            _localSettings = ApplicationData.Current.LocalSettings;

            //Get TPM Device ConnectionString
            _tpmDevice = new TpmDevice(0);

            //Create services
            _logging            = new LoggingChannel("LunchBagCamera", null, new Guid("8e2fb18a-e7ae-45f9-bf05-d42455ba6ce0"));
            _azureIoTHubService = new AzureIoTHubService(_logging, ReceiveConfiguration, ReceiveSubscription);
            _cognitiveService   = new CognitiveVisionService(_logging);
            _cameraService      = new CameraService(_logging);

            await RunApplication();

            deferral.Complete();
        }
コード例 #3
0
 private void InitAzureIoTHub()
 {
     _azureIoTHubService = new AzureIoTHubService();
 }
コード例 #4
0
        public MainPage()
        {
            this.InitializeComponent();
            this.InitializeComponent();
            _azureIoTHubService = new AzureIoTHubService();
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(3000);
            timer.Tick    += async(s, e) =>
            {
                SpiDisplay.TransferFullDuplex(writeBuffer, readBuffer);
                res = convertToInt(readBuffer);
                var forceSensorValue = res.ToString();

                textPlaceHolder.Text = forceSensorValue;
                System.Diagnostics.Debug.WriteLine("FORCE SENSOR VALUE: " + forceSensorValue);

                if (res > 0)
                {
                    await _azureIoTHubService.SendDataToAzure(forceSensorValue);
                }
            };
            timer.Start();

            whichADCChip = ADCChip.mcp3008;
            switch (whichADCChip)
            {
            case ADCChip.mcp3002:
            {
                // To line everything up for ease of reading back (on byte boundary) we
                // will pad the command start bit with 1 leading "0" bit

                // Write 0SGO MNxx xxxx xxxx
                // Read  ???? ?N98 7654 3210
                // S = start bit
                // G = Single / Differential
                // O = Chanel data
                // M = Most significant bit mode
                // ? = undefined, ignore
                // N = 0 "Null bit"
                // 9-0 = 10 data bits

                // 0110 1000 = 1 0 pad bit, start bit, Single ended, odd (channel 0), MSFB only, 2 clocking bits
                // 0000 0000 = 8 clocking bits
                readBuffer = new byte[2] {
                    0x00, 0x00
                };
                writeBuffer = new byte[2] {
                    0x68, 0x00
                };
            }
            break;

            case ADCChip.mcp3008:
            {
                // To line everything up for ease of reading back (on byte boundary) we
                // will pad the command start bit with 7 leading "0" bits

                // Write 0000 000S GDDD xxxx xxxx xxxx
                // Read  ???? ???? ???? ?N98 7654 3210
                // S = start bit
                // G = Single / Differential
                // D = Chanel data
                // ? = undefined, ignore
                // N = 0 "Null bit"
                // 9-0 = 10 data bits

                // 0000 01 = 7 pad bits, start bit
                // 1000 0000 = single ended, channel bit 2, channel bit 1, channel bit 0, 4 clocking bits
                // 0000 0000 = 8 clocking bits
                readBuffer = new byte[3] {
                    0x00, 0x00, 0x00
                };
                writeBuffer = new byte[3] {
                    0x01, 0x80, 0x00
                };
            }
            break;

            case ADCChip.mcp3208:
            {
                /* mcp3208 is 12 bits output */
                // To line everything up for ease of reading back (on byte boundary) we
                // will pad the command start bit with 5 leading "0" bits

                // Write 0000 0SGD DDxx xxxx xxxx xxxx
                // Read  ???? ???? ???N BA98 7654 3210
                // S = start bit
                // G = Single / Differential
                // D = Chanel data
                // ? = undefined, ignore
                // N = 0 "Null bit"
                // B-0 = 12 data bits


                // 0000 0110 = 5 pad bits, start bit, single ended, channel bit 2
                // 0000 0000 = channel bit 1, channel bit 0, 6 clocking bits
                // 0000 0000 = 8 clocking bits
                readBuffer = new byte[3] {
                    0x00, 0x00, 0x00
                };
                writeBuffer = new byte[3] {
                    0x06, 0x00, 0x00
                };
            }
            break;
            }

            InitSPI();
        }