コード例 #1
0
 public void Initialize()
 {
     _pinConfiguration = Pin.Input().OnStatusChanged(s => {
         RaiseOnPressedEvent(null);
     });
     _connection = new GpioConnection(_pinConfiguration);
 }
コード例 #2
0
ファイル: WindMonitor.cs プロジェクト: he4d/almue-deprecated
 public WindMonitor(ConfigurationObject.DevicesConfig.WindMonitorConfig config, GpioConnection gpioConnection)
     : base(gpioConnection)
 {
     Description          = config.Description;
     _inputPinConfig      = config.InPin.Input();
     _inputPinConfig.Name = config.Description;
     _inputPinConfig.OnStatusChanged(CountPulses);
     Disabled = config.Disabled;
 }
コード例 #3
0
        public TokenReader(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;

            this.canTransmit = new AutoResetEvent(false);

            this.busyPin = ConnectorPin.P1Pin12.Input();

            this.serialPort = new SerialPort("/dev/ttyAMA0", 9600, Parity.None, 8, StopBits.One);
        }
コード例 #4
0
        public Button(InputPinConfiguration outputPin, IGpioConnectionDriver driver = null)
        {
            PinConfig = outputPin;
            Driver    = driver ?? GpioConnectionSettings.DefaultDriver;
            Driver.Allocate(PinConfig.Pin, PinDirection.Output);
            TokenScource = new System.Threading.CancellationTokenSource();
            Action a = Watch;

            Task.Run(a, TokenScource.Token);
            // Task.Start(Watch);
        }
コード例 #5
0
        public clsDialHookListener(InputPinConfiguration HookInput, InputPinConfiguration PulseDialInput)
        {
            HookIO = HookInput;
            DialIO = PulseDialInput;


            var config = new GpioConnectionSettings()
            {
                PollInterval = 5,
            };


            GPIO = new GpioConnection(config, HookIO, DialIO);



            GPIO.PinStatusChanged += (object sender, PinStatusEventArgs e) => {              //switch change event handler
                if (e.Configuration.Pin == HookIO.Pin)
                {
                    if (GPIO[HookIO])
                    {
                        HookPulseCount++;
                    }
                    HookWaitEvent.Set();
                }
                else if (e.Configuration.Pin == DialIO.Pin)
                {
                    if (GPIO[DialIO])
                    {
                        DialPulseCount++;
                        DialWaitEvent.Set();
                    }
                }
                else
                {
                    Console.WriteLine("Huh?! Wrong IO: " + e.Configuration.Name);
                }
            };

            DialListenerThread = new Thread(ListenDial)
            {
                Name         = "DialListener",
                IsBackground = true,
            };
            DialListenerThread.Start();

            HookListenerThread = new Thread(ListenHookSwitch)
            {
                Name         = "HookListener",
                IsBackground = true,
            };
            HookListenerThread.Start();
        }
コード例 #6
0
        /// <summary>
        /// Add a gpio to the global connection if not already added setting direction
        /// </summary>
        /// <param name="processorPin"></param>
        /// <param name="output"></param>
        public static void Add(ProcessorPin processorPin, bool output)
        {
            //if (!CommonHelper.IsBoard)
            //    return;

            if (output)
            {
                OutputPinConfiguration opc = processorPin.Output();
                ConnectionGlobalPinAdd(opc);
            }
            else
            {
                InputPinConfiguration ipc = processorPin.Input();
                ConnectionGlobalPinAdd(ipc);
            }
        }
コード例 #7
0
        static void Main()
        {
            MMirrorManager mm = MMirrorManager.Instance;

            //incase our downloaded data isnt complete, we just get what we last stored
            try
            {
                dynamic manager = JObject.Parse(File.ReadAllText(@"../../Data/tempArray.json"));

                stocks[] stock;
                stock = manager.stock.ToObject <List <stocks> >().ToArray();

                List <weatherDay> weather;
                weather = manager.weather.ToObject <List <weatherDay> >();

                mm.setStock(stock);
                mm.setWeather(weather);
            }
            catch (Exception)
            {
                stockController si = new stockController();
                si.getStockFile();

                weatherController wc = new weatherController(MMirrorManager.instance);
                wc.getWeatherJSON();
            }



            /* Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             * stockView = new View.stockView();
             * edges = 0;
             * state = 0;
             * stockView.Visible = true;
             * stockView.startFadeinTimer();
             * Application.Run(stockView);
             *
             */

            InputPinConfiguration p = new InputPinConfiguration(ConnectorPin.P1Pin07.ToProcessor());
            GpioConnection        g = new GpioConnection(p);

            g.PinStatusChanged += g_detected;
        }
コード例 #8
0
        public Form1()
        {
            InitializeComponent();

            // 自分のIPアドレスを探す
            string      ipaddress = string.Empty;
            IPHostEntry ipentry   = Dns.GetHostEntry(Dns.GetHostName());

            foreach (IPAddress ip in ipentry.AddressList)
            {
                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    ipaddress = ip.ToString();
                    break;
                }
            }
            // TCサーバの起動
            _ = server.Open(ipaddress, 5000, 1024);

            // 起動時に一度入力チェック
            getIO();

            // ここで示すピン番号は定義されている名称
            GPIO2      = ProcessorPin.Pin2.Input().PullUp();
            GPIO3      = ProcessorPin.Pin3.Input().PullUp();
            GPIO4      = ProcessorPin.Pin4.Input().PullUp();
            connection = new GpioConnection(GPIO2, GPIO3, GPIO4);
            // 入力変化時のイベント
            connection.PinStatusChanged += (sender, eventArgs) =>
            {
                if (eventArgs.Configuration.Pin == ProcessorPin.Pin2)
                {
                    checkBox1.Checked = eventArgs.Enabled;
                }
                if (eventArgs.Configuration.Pin == ProcessorPin.Pin3)
                {
                    checkBox2.Checked = eventArgs.Enabled;
                }
                if (eventArgs.Configuration.Pin == ProcessorPin.Pin4)
                {
                    checkBox3.Checked = eventArgs.Enabled;
                }
            };
        }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ky040Device" /> class.
 /// </summary>
 /// <param name="clockConnectorPin">The clock connector pin.</param>
 /// <param name="dataConnectorPin">The data connector pin.</param>
 /// <param name="buttonConnectorPin">The button connector pin.</param>
 /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param>
 /// <param name="rotaryEncoderReporter">The ky040 reporter.</param>
 public Ky040Device(
     ConnectorPin clockConnectorPin,
     ConnectorPin dataConnectorPin,
     ConnectorPin buttonConnectorPin,
     IGpioConnectionDriverFactory?gpioConnectionDriverFactory = null,
     IRotaryEncoderReporter?rotaryEncoderReporter             = null)
 {
     this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory);
     this.gpioConnectionDriver        = this.gpioConnectionDriverFactory.Get();
     this.rotaryEncoderReporter       = rotaryEncoderReporter;
     this.rotaryEncoderReporter?.SetSource(typeof(IRotaryEncoderReporter), this);
     this.clkPinConfiguration = clockConnectorPin.Input().PullUp();
     this.clkPinConfiguration.OnStatusChanged(this.OnEncoderChanged);
     this.dtPinConfiguration = dataConnectorPin.Input().PullUp();
     this.dtPinConfiguration.OnStatusChanged(this.OnEncoderChanged);
     this.buttonPinConfiguration = buttonConnectorPin.Input().PullUp();
     this.buttonPinConfiguration.OnStatusChanged(this.OnButtonPressed);
     this.clockProcessorPin = clockConnectorPin.ToProcessor();
     this.dataProcessorPin  = dataConnectorPin.ToProcessor();
 }
コード例 #10
0
ファイル: DateAndTime.cs プロジェクト: kholysa/MMirror
        public DateAndTime()
        {
            InitializeComponent();
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;
            //let the labels update every minute
            //this is done by an event being raised every minute
            //the event modifies the labels

            tn          = new System.Windows.Forms.Timer();
            tn.Interval = 1;
            tn.Tick    += t_Tick_fade;

            InputPinConfiguration p = new InputPinConfiguration(ConnectorPin.P1Pin07.ToProcessor());
            GpioConnection        g = new GpioConnection(p);

            g.PinStatusChanged += g_Detected;
            startFadeinTimer();
            StartTimer();
            this.Opacity = 0;
        }
コード例 #11
0
 internal SwitchInputPinConfiguration(InputPinConfiguration pin) : base(pin.Pin)
 {
     Reversed = pin.Reversed;
     Name     = pin.Name;
 }
コード例 #12
0
ファイル: stockView.cs プロジェクト: kholysa/MMirror
        public stockView()
        {
            //when implementing this, just call whatever the onCLick calls, hopefully we wont crash and fail :))))



            InitializeComponent();
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;
            t          = new Timer();
            t.Interval = 10;
            t.Tick    += t_Tick;

            InputPinConfiguration p = new InputPinConfiguration(ConnectorPin.P1Pin07.ToProcessor());
            GpioConnection        g = new GpioConnection(p);

            g.PinStatusChanged += g_Detected;

            this.Opacity = 0;

            MMirrorManager mmc = MMirrorManager.instance;

            label42.Hide();
            List <Label> stockData = new List <Label>(40);
            var          c         = GetAll(this, typeof(Label));

            for (int i = 0; i < c.Count(); i++)
            {
                c.ElementAt(i).Text = "";
            }
            label42.Text = "No Internet Connection. Try again Later";

            label1.Text = mmc.getStock(0).stockName;
            label2.Text = mmc.getStock(1).stockName;
            label3.Text = mmc.getStock(2).stockName;
            label4.Text = mmc.getStock(3).stockName;
            //the ugly forward slashes below are because we were converting the settings from an html file and apparently couldnt remove all the tags

            if (mmc.getStock(4).stockName == "\"^FTSE\"")
            {
                label5.Text = "FTSE 100";
            }
            else if (mmc.getStock(4).stockName == "\"^FTMC\"")
            {
                label5.Text = "FTSE 250";
            }
            else if (mmc.getStock(4).stockName == "\"^N225\"")
            {
                label5.Text = "NIKKEI";
            }

            if (mmc.getStock(5).stockName == "\"BZZ15.NYM\"")
            {
                label6.Text = "Brent Crude Oil";
            }
            else if (mmc.getStock(5).stockName == "\"^GSPC\"")
            {
                label6.Text = "S" + '&' + "P 500";
            }
            else if (mmc.getStock(5).stockName == "\"WTI\"")
            {
                label6.Text = "WTI";
            }


            label9.Text  = mmc.getStock(0).closePrice + "";
            label10.Text = mmc.getStock(1).closePrice + "";
            label11.Text = mmc.getStock(2).closePrice + "";
            label12.Text = mmc.getStock(3).closePrice + "";
            label13.Text = mmc.getStock(4).closePrice + "";
            label14.Text = mmc.getStock(4).closePrice + "";


            label33.Text = mmc.getStock(0).volatility;
            label34.Text = mmc.getStock(1).volatility;
            label35.Text = mmc.getStock(2).volatility;
            label36.Text = mmc.getStock(3).volatility;
            label21.Text = mmc.getStock(4).volatility;
            label22.Text = mmc.getStock(5).volatility;

            startFadeinTimer();
            try
            {
                sc.getStockFile();
            }
            catch (Exception)
            {
            }
        }
コード例 #13
0
ファイル: WeatherView.cs プロジェクト: kholysa/MMirror
        public WeatherView()
        {
            InitializeComponent();
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;

            tn          = new Timer();
            tn.Interval = 1;
            tn.Tick    += t_Tick;

            InputPinConfiguration p = new InputPinConfiguration(ConnectorPin.P1Pin07.ToProcessor());
            GpioConnection        g = new GpioConnection(p);

            g.PinStatusChanged += g_Detected;

            this.Opacity = 0.5;
            MMirrorManager mmc = MMirrorManager.Instance;

            label2.Hide();
            //lotta code, but im just populating the labels with the relevant data

            //current temp
            currentWeather.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[0].hi - 273.15) + "°C");

            //next tweleve hours
            currentForecast1.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[0].twelveHourForcast[0] - 273.15) + "°C");
            currentForecast2.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[0].twelveHourForcast[1] - 273.15) + "°C");
            currentForecast3.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[0].twelveHourForcast[2] - 273.15) + "°C");
            currentForecast4.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[0].twelveHourForcast[3] - 273.15) + "°C");

            //time of the forecast calculations
            string[] times    = new string[4];
            int[]    timesInt = new int[4];
            for (int i = 0; i < times.Length; i++)
            {
                if (mmc.getWeather()[0].twelveHourTimes[i] > 12)
                {
                    timesInt[i] = mmc.getWeather()[0].twelveHourTimes[i] - 12;
                    times[i]    = Convert.ToString(timesInt[i]) + "p";
                }
                else if (mmc.getWeather()[0].twelveHourTimes[i] == 12)
                {
                    timesInt[i] = mmc.getWeather()[0].twelveHourTimes[i];
                    times[i]    = Convert.ToString(timesInt[i]) + "p";
                }
                else if (mmc.getWeather()[0].twelveHourTimes[i] == 0)
                {
                    timesInt[i] = mmc.getWeather()[0].twelveHourTimes[i] + 12;
                    times[i]    = Convert.ToString(timesInt[i]) + "a";
                }
                else
                {
                    timesInt[i] = mmc.getWeather()[0].twelveHourTimes[i];
                    times[i]    = Convert.ToString(timesInt[i]) + "a";
                }
            }
            currentTime1.Text = Convert.ToString(times[0]);
            currentTime2.Text = Convert.ToString(times[1]);
            currentTime3.Text = Convert.ToString(times[2]);
            currentTime4.Text = Convert.ToString(times[3]);

            //the image of the humidity
            Image humidity = Image.FromFile(@"../../Data/50d.png");

            currentHumidityIMG.Size  = new System.Drawing.Size(humidity.Width, humidity.Height);
            currentHumidityIMG.Image = humidity;

            //humidity
            currentHumidity.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[0].humidity) + "%");
            currentLocation.Text = "Current weather";
            location.Text        = mmc.getWeather()[0].location;
            forecastWeather.Text = "Weather Forecast";

            //image of current weather
            Image img = Image.FromFile(@"../../Data/" + mmc.getWeather()[0].weatherConditions + ".png");

            currentImage.Size  = new System.Drawing.Size(img.Width, img.Height);
            currentImage.Image = img;

            //only display this data if we recieve it
            if (mmc.getWeather()[0].rain == -50)
            {
                currentRain.Text = "";
            }
            else
            {
                Image rain = Image.FromFile(@"../../Data/rain.png");
                rainIMG.Size     = new System.Drawing.Size(50, 50);
                rainIMG.Image    = rain;
                currentRain.Text = Convert.ToString(Convert.ToDouble(mmc.getWeather()[0].rain) + "mm");
            }
            if (mmc.getWeather()[0].snow == -50)
            {
                currentSnow.Text = "";
            }
            else
            {
                Image snow = Image.FromFile(@"../../Data/snow.png");
                snowIMG.Size  = new System.Drawing.Size(50, 50);
                snowIMG.Image = snow;

                currentSnow.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[0].snow) + "cm");
            }

            //the highs of the next few days
            forecastTemp1.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[1].hi - 273.15) + "°");
            forecastTemp2.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[2].hi - 273.15) + "°");
            forecastTemp3.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[3].hi - 273.15) + "°");
            forecastTemp4.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[4].hi - 273.15) + "°");
            //the los of the next 4 days
            forecastLo1.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[1].lo - 273.15) + "°");
            forecastLo2.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[2].lo - 273.15) + "°");
            forecastLo3.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[3].lo - 273.15) + "°");
            forecastLo4.Text = Convert.ToString(Convert.ToInt32(mmc.getWeather()[4].lo - 273.15) + "°");
            //the image of the next few days
            forecastIMG1.Size = new System.Drawing.Size(50, 50);
            forecastIMG2.Size = new System.Drawing.Size(50, 50);
            forecastIMG3.Size = new System.Drawing.Size(50, 50);
            forecastIMG4.Size = new System.Drawing.Size(50, 50);

            forecastIMG1.Image = Image.FromFile(@"../../Data/" + mmc.getWeather()[1].weatherConditions + ".png");
            forecastIMG2.Image = Image.FromFile(@"../../Data/" + mmc.getWeather()[2].weatherConditions + ".png");
            forecastIMG3.Image = Image.FromFile(@"../../Data/" + mmc.getWeather()[3].weatherConditions + ".png");
            forecastIMG4.Image = Image.FromFile(@"../../Data/" + mmc.getWeather()[4].weatherConditions + ".png");
            //the days of the weather forecast
            DateTime dt = DateTime.Now;

            Tomorrow.Text  = Convert.ToString(dt.AddDays(1).DayOfWeek);
            tomorrow2.Text = Convert.ToString(dt.AddDays(2).DayOfWeek);
            tomorrow3.Text = Convert.ToString(dt.AddDays(3).DayOfWeek);
            tomorrow4.Text = Convert.ToString(dt.AddDays(4).DayOfWeek);

            startFadeinTimer();
            try
            {
                wc.getWeatherJSON();
            }
            catch (Exception)
            {
            }
        }
コード例 #14
0
 internal SwitchInputPinConfiguration(InputPinConfiguration pin) : base(pin.Pin)
 {
     Reversed = pin.Reversed;
     Name = pin.Name;
 }
コード例 #15
0
ファイル: PLCupdater.cs プロジェクト: robertlarue/PLCupdater
        static void Main(string[] args)
        {
            //create instance of settings object to get settings from config file
            Properties.Settings settings = new Properties.Settings();

            //set idleTimout to value from PLCupdater.exe.config file
            idleTimeout = settings.idleTimeout;

            //Initialize timer to shutdown device when idle
            timer = new Timer(new TimerCallback(idleShutdown), null, idleTimeout, Timeout.Infinite);

            //flag to prevent triggering update while one is already in progress
            bool updating = false;

            //pin definitions

            //blue LED on pin 12, provision as a low-level pin
            ProcessorPin blueLED = ConnectorPin.P1Pin12.ToProcessor();

            //red LED on pin 18, provision as a low-level pin
            ProcessorPin redLED = ConnectorPin.P1Pin18.ToProcessor();

            //green LED on pin 16, provision as a managed output
            OutputPinConfiguration greenLED = ConnectorPin.P1Pin16.Output();

            //create a low-level connection driver for red LED and blue LED
            IGpioConnectionDriver driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(redLED, PinDirection.Output);
            driver.Allocate(blueLED, PinDirection.Output);

            //turn blue LED on to indicate program is ready
            driver.Write(blueLED, true);

            //create instance of DF1 protocol serial connection class
            DF1Comm.DF1Comm df1 = new DF1Comm.DF1Comm();

            //create high-level connection for green LED and buttons
            //allows for blinking LEDs and OnStatusChanged events for buttons
            GpioConnection gpioConnection = new GpioConnection(greenLED);

            //Program A download on pin 15, reverse input so that it's normally open instead of normally closed
            //Download program A to PLC when pressed
            InputPinConfiguration A_Down = ConnectorPin.P1Pin15.Input()
                                           .Revert()
                                           .OnStatusChanged(a =>
            {
                //if the button is pressed and update is not currently running, start update
                if (a && !updating)
                {
                    //set updating flag to true
                    updating = true;

                    //start update to transfer program A to the PLC using serial port from the config
                    DownloadProgram(df1, driver, gpioConnection, redLED, greenLED, settings.FileA, settings.SerialPort);

                    //set updating flag back to false
                    updating = false;
                }
            });

            //Program B download on pin 7, reverse input so that it's normally open instead of normally closed
            //Download program B to PLC when pressed
            InputPinConfiguration B_Down = ConnectorPin.P1Pin7.Input()
                                           .Revert()
                                           .OnStatusChanged(a =>
            {
                //if the button is pressed and update is not currently running, start update
                if (a && !updating)
                {
                    //set updating flag to true
                    updating = true;

                    //start update to transfer program A to the PLC using serial port from the config
                    DownloadProgram(df1, driver, gpioConnection, redLED, greenLED, settings.FileB, settings.SerialPort);

                    //set updating flag back to false
                    updating = false;
                }
            });

            //Progam A upload on pin 13, reverse input so that it's normally open instead of normally closed
            //Upload program A from PLC when pressed
            var A_Up = ConnectorPin.P1Pin13.Input()
                       .Revert()
                       .OnStatusChanged(b =>
            {
                //if the button is pressed and update is not currently running, start update
                if (b && !updating)
                {
                    //set updating flag to true
                    updating = true;

                    //start update to transfer program B to the PLC using serial port from the config
                    //DownloadProgram(df1, driver, gpioConnection, redLED, greenLED, settings.FileB, settings.SerialPort);
                    UploadProgram(df1, driver, gpioConnection, redLED, greenLED, settings.FileA, settings.SerialPort);

                    //set updating flag back to false
                    updating = false;
                }
            });

            //Progam B upload on pin 11, reverse input so that it's normally open instead of normally closed
            //Upload program B from PLC when pressed
            var B_Up = ConnectorPin.P1Pin11.Input()
                       .Revert()
                       .OnStatusChanged(b =>
            {
                //if the button is pressed and update is not currently running, start update
                if (b && !updating)
                {
                    //set updating flag to true
                    updating = true;

                    //start update to transfer program B to the PLC using serial port from the config
                    //DownloadProgram(df1, driver, gpioConnection, redLED, greenLED, settings.FileB, settings.SerialPort);
                    UploadProgram(df1, driver, gpioConnection, redLED, greenLED, settings.FileB, settings.SerialPort);

                    //set updating flag back to false
                    updating = false;
                }
            });

            //add the button configurations to the high-level connection
            gpioConnection.Add(A_Up);
            gpioConnection.Add(B_Up);
            gpioConnection.Add(A_Down);
            gpioConnection.Add(B_Down);

            //prevent program from exiting
            Console.ReadKey();
        }