<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Gpio;
using Windows.Devices.Spi;
using Windows.Devices.Enumeration;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using Microsoft.Azure.Devices.Client;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace IoTLightSensor
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        /* Important! Change this to either AdcDevice.MCP3002, AdcDevice.MCP3208 or AdcDevice.MCP3008 depending on which ADC you chose     */
        private AdcDevice ADC_DEVICE = AdcDevice.MCP3002;

        enum AdcDevice { NONE, MCP3002, MCP3208, MCP3008 };

        // Use the device specific connection string here
        private const string IOT_HUB_CONN_STRING = "YOUR CONNECTION STRING HERE";
        // Use the name of your Azure IoT device here - this should be the same as the name in the connections string
        private const string IOT_HUB_DEVICE = "YOUR DEVICE NAME HERE";
        // Provide a short description of the location of the device, such as 'Home Office' or 'Garage'
        private const string IOT_HUB_DEVICE_LOCATION = "YOUR LOCATION HERE";

        // Line 0 maps to physical pin 24 on the RPi2
        private const Int32 SPI_CHIP_SELECT_LINE = 0;
        private const string SPI_CONTROLLER_NAME = "SPI0";

        // 01101000 channel configuration data for the MCP3002
        private const byte MCP3002_CONFIG = 0x68;
        // 00000110 channel configuration data for the MCP3208
        private const byte MCP3208_CONFIG = 0x06;
        // 00001000 channel configuration data for the MCP3008
        private const byte MCP3008_CONFIG = 0x08;

        private const int RED_LED_PIN = 12;

        private SolidColorBrush redFill = new SolidColorBrush(Windows.UI.Colors.Red);
        private SolidColorBrush grayFill = new SolidColorBrush(Windows.UI.Colors.LightGray);

        private DeviceClient deviceClient;
        private GpioPin redLedPin;
        private SpiDevice spiAdc;
        private int adcResolution;
        private int adcValue;

        private Timer readSensorTimer;
        private Timer sendMessageTimer;
        public MainPage()
        {
            this.InitializeComponent();

            // Register the Unloaded event to clean up on exit
            Unloaded += MainPage_Unloaded;

            // Initialize GPIO and SPI
            InitAllAsync();
        }

        private async Task InitAllAsync()
        {
            try
            {
                await InitGpioAsync();
                await InitSpiAsync();
            }
            catch (Exception ex)
            {
                StatusText.Text = ex.Message;
                return;
            }

            // Read sensors every 100ms and refresh the UI
            readSensorTimer = new Timer(this.SensorTimer_Tick, null, 0, 100);

            // Instantiate the Azure device client
            deviceClient = DeviceClient.CreateFromConnectionString(IOT_HUB_CONN_STRING);

            // Send messages to Azure IoT Hub every one-second<commit_msg>Running Async tasks in parallel<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Gpio;
using Windows.Devices.Spi;
using Windows.Devices.Enumeration;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using Microsoft.Azure.Devices.Client;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace IoTLightSensor
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        /* Important! Change this to either AdcDevice.MCP3002, AdcDevice.MCP3208 or AdcDevice.MCP3008 depending on which ADC you chose     */
        private AdcDevice ADC_DEVICE = AdcDevice.MCP3002;

        enum AdcDevice { NONE, MCP3002, MCP3208, MCP3008 };

        // Use the device specific connection string here
        private const string IOT_HUB_CONN_STRING = "YOUR CONNECTION STRING HERE";
        // Use the name of your Azure IoT device here - this should be the same as the name in the connections string
        private const string IOT_HUB_DEVICE = "YOUR DEVICE NAME HERE";
        // Provide a short description of the location of the device, such as 'Home Office' or 'Garage'
        private const string IOT_HUB_DEVICE_LOCATION = "YOUR LOCATION HERE";

        // Line 0 maps to physical pin 24 on the RPi2
        private const Int32 SPI_CHIP_SELECT_LINE = 0;
        private const string SPI_CONTROLLER_NAME = "SPI0";

        // 01101000 channel configuration data for the MCP3002
        private const byte MCP3002_CONFIG = 0x68;
        // 00000110 channel configuration data for the MCP3208
        private const byte MCP3208_CONFIG = 0x06;
        // 00001000 channel configuration data for the MCP3008
        private const byte MCP3008_CONFIG = 0x08;

        private const int RED_LED_PIN = 12;

        private SolidColorBrush redFill = new SolidColorBrush(Windows.UI.Colors.Red);
        private SolidColorBrush grayFill = new SolidColorBrush(Windows.UI.Colors.LightGray);

        private DeviceClient deviceClient;
        private GpioPin redLedPin;
        private SpiDevice spiAdc;
        private int adcResolution;
        private int adcValue;

        private Timer readSensorTimer;
        private Timer sendMessageTimer;
        public MainPage()
        {
            this.InitializeComponent();

            // Register the Unloaded event to clean up on exit
            Unloaded += MainPage_Unloaded;

            // Initialize GPIO and SPI
            InitAllAsync();
        }

        private async Task InitAllAsync()
        {
            try
            {
                Task[] initTasks = { InitGpioAsync(), InitSpiAsync() };
                await Task.WhenAll(initTasks);
            }
            catch (Exception ex)
            {
                StatusText.Text = ex.Message;
                return;
            }

            // Read sensors every 100ms and refresh the UI
            readSensorTimer = new Timer(this.SensorTimer_Tick, null, 0, 100);

            // Instantiate the Azure device client
            deviceClient = DeviceClient.CreateFromConnectionString(IOT_HUB_CONN_STRING);

            // Send messages to Azure IoT Hub every one-second
{'fraction_non_alphanumeric': 0.06765992345544013, 'fraction_numerical': 0.0306178239475123, 'mean_word_length': 2.5127220355256843, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3626240', 'n_tokens_mistral': 2199, 'n_tokens_neox': 1969, 'n_words': 653}