Ejemplo n.º 1
0
        private string GetPiFaceStatus()
        {
            try
            {
                UInt16 inputs = MCP23S17.ReadRegister16();

                JObject status = new JObject(
                    new JProperty("LED",
                                  new JObject(
                                      new JProperty("LED0", ((inputs & 1 << PiFaceDigital2.LED0) != 0) ? "on" : "off"),
                                      new JProperty("LED1", ((inputs & 1 << PiFaceDigital2.LED1) != 0) ? "on" : "off"),
                                      new JProperty("LED2", ((inputs & 1 << PiFaceDigital2.LED2) != 0) ? "on" : "off"),
                                      new JProperty("LED3", ((inputs & 1 << PiFaceDigital2.LED3) != 0) ? "on" : "off"),
                                      new JProperty("LED4", ((inputs & 1 << PiFaceDigital2.LED4) != 0) ? "on" : "off"),
                                      new JProperty("LED5", ((inputs & 1 << PiFaceDigital2.LED5) != 0) ? "on" : "off"),
                                      new JProperty("LED6", ((inputs & 1 << PiFaceDigital2.LED6) != 0) ? "on" : "off"),
                                      new JProperty("LED7", ((inputs & 1 << PiFaceDigital2.LED7) != 0) ? "on" : "off")
                                      )),
                    new JProperty("Switch",
                                  new JObject(
                                      new JProperty("SW0", ((inputs & 1 << PiFaceDigital2.SW0) == 0) ? "on" : "off"),
                                      new JProperty("SW1", ((inputs & 1 << PiFaceDigital2.SW1) == 0) ? "on" : "off"),
                                      new JProperty("SW2", ((inputs & 1 << PiFaceDigital2.SW2) == 0) ? "on" : "off"),
                                      new JProperty("SW3", ((inputs & 1 << PiFaceDigital2.SW3) == 0) ? "on" : "off")
                                      )));

                return(status.ToString());
            }
            catch (Exception ex)
            {
                return("에러발생" + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>Updates the values from the Pi.</summary>
        internal void UpdateValuesFromPi()
        {
            var result = MCP23S17.ReadRegister16(); // do something with the values

            for (int i = 0; i < 8; i++)
            {
                var bitIsOn = (result & (1 << i)) != 0;
                this.Inputs.First(input => input.Id == i).IsOn = !bitIsOn;
                bitIsOn = (result & (1 << (i + 8))) != 0;
                this.Outputs.First(input => input.Id == i).IsOn = bitIsOn;
            }
        }
Ejemplo n.º 3
0
        private async void InitSPIchip()
        {
            try
            {
                await MCP23S17.InitSPI();

                MCP23S17.InitMCP23S17();
                MCP23S17.setPinMode(0x00FF);
                MCP23S17.pullupMode(0x00FF);
                MCP23S17.WriteWord(0x0000);
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 4
0
        private async void InitSPI()
        {
            try
            {
                await MCP23S17.InitSPI();

                MCP23S17.InitMCP23S17();
                MCP23S17.setPinMode(0x00FF); // 0x0000 = all outputs, 0xffff=all inputs, 0x00FF is PIFace Default
                MCP23S17.pullupMode(0x00FF); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default
                MCP23S17.WriteWord(0x0000);  // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 5
0
        /// <summary>Initializes the pi face.</summary>
        public async Task InitializePiFace()
        {
            await MCP23S17.InitializeSpiDevice();

            MCP23S17.Initialize();
            MCP23S17.SetPinMode(0x00FF);    // 0x0000 = all outputs, 0xffff=all inputs, 0x00FF is PIFace Default
            MCP23S17.SetPullUpMode(0x00FF); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default
            MCP23S17.WriteWord(0x0000);     // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default

            // ReSharper disable once ExceptionNotDocumented
            this.timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(200)
            };
            this.timer.Tick += this.TimerOnTick;
            this.timer.Start();
            this.SendStatus();
        }
Ejemplo n.º 6
0
        private string ControlPiFaceLed(string[] query)
        {
            int    targetLedNo;
            string resultString = "XXXXXXX";

            if (int.TryParse(query[1], out targetLedNo) == true && targetLedNo < 8)
            {
                MCP23S17.WritePin(LedAdress[targetLedNo],
                                  this.CheckLedStatus(LedAdress[targetLedNo]) == MCP23S17.On
                        ? MCP23S17.Off
                        : MCP23S17.On);
                //MCP23S17.WritePin(LedAdress[targetLedNo], Convert.ToByte(query[1]));

                resultString = "ok";
            }
            return(resultString);
        }
Ejemplo n.º 7
0
        private void TimerOutputs_Tick(object sender, object e)
        {
            if (OnFlag == 0)
            {
                MCP23S17.pullupMode(PFDII.LED2, Off);

                MCP23S17.WritePin(PFDII.LED2, On);
                MCP23S17.WritePin(PFDII.LED3, On);
                MCP23S17.WritePin(PFDII.LED4, On);
                OnFlag = 1;
            }
            else
            {
                MCP23S17.WritePin(PFDII.LED2, Off);
                MCP23S17.WritePin(PFDII.LED3, Off);
                MCP23S17.WritePin(PFDII.LED4, Off);
                OnFlag = 0;
            }
        }
Ejemplo n.º 8
0
        /* Initialize GPIO, SPI, and the display */
        private async void InitAll()
        {
            try
            {
                await MCP23S17.InitSPI();

                MCP23S17.InitMCP23S17();
                MCP23S17.setPinMode(0x00FF); // 0x0000 = all outputs, 0xffff=all inputs, 0x00FF is PIFace Default
                MCP23S17.pullupMode(0x00FF); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default
                MCP23S17.WriteWord(0x0000);  // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default



                Switch0.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch0_PointerPressed), true);
                Switch0.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch0_PointerReleased), true);
                Switch1.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch1_PointerPressed), true);
                Switch1.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch1_PointerReleased), true);
                Switch2.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch2_PointerPressed), true);
                Switch2.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch2_PointerReleased), true);
                Switch3.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch3_PointerPressed), true);
                Switch3.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch3_PointerReleased), true);



                initTimer();
            }
            catch (Exception ex)
            {
                //Text_Status.Text = "Exception: " + ex.Message;
                //if (ex.InnerException != null)
                //{
                //    Text_Status.Text += "\nInner Exception: " + ex.InnerException.Message;
                //}
                //return;
            }
        }
Ejemplo n.º 9
0
 // read GPIO and display it
 private void Timer_Tick(object sender, object e)
 {
     LightLEDs(MCP23S17.ReadRegister16());    // do something with the values
 }
Ejemplo n.º 10
0
 private void LED7_Unchecked(object sender, RoutedEventArgs e)
 {
     MCP23S17.WritePin(PFDII.LED7, Off);
 }
Ejemplo n.º 11
0
 private void LED1_Unchecked(object sender, RoutedEventArgs e)
 {
     MCP23S17.WritePin(PFDII.LED1, Off);
     RelayA.IsChecked = false; // LED1 and RelayB are the same output pin
 }
Ejemplo n.º 12
0
 private void LED0_Checked(object sender, RoutedEventArgs e)
 {
     MCP23S17.WritePin(PFDII.LED0, On);
     RelayB.IsChecked = true; // LED0 and RelayA are the same output pin
 }
Ejemplo n.º 13
0
 private void RelayB_Unchecked(object sender, RoutedEventArgs e)
 {
     MCP23S17.WritePin(PFDII.RelayB, Off);
     RelayBImage.Source = RelayOff.Source;
     LED0.IsChecked     = false;;
 }
Ejemplo n.º 14
0
 private void RelayB_Checked(object sender, RoutedEventArgs e)
 {
     MCP23S17.WritePin(PFDII.RelayB, On);
     RelayBImage.Source = RelayOn.Source;
     LED0.IsChecked     = true;;
 }
Ejemplo n.º 15
0
 public MCP23S17RegisterBase(int address, MCP23S17 chip)
 {
     this.address = address;
     this.chip    = chip;
 }
Ejemplo n.º 16
0
        private byte CheckLedStatus(byte led)
        {
            UInt16 Inputs = MCP23S17.ReadRegister16();

            return(((Inputs & 1 << led) != 0) ? MCP23S17.On : MCP23S17.Off);
        }
Ejemplo n.º 17
0
 public MCP23S17RegisterBit(int bit_num, int address, MCP23S17 chip)
     : base(address, chip)
 {
     this.bit_num = bit_num;
 }
Ejemplo n.º 18
0
 private void LED6_Checked(object sender, RoutedEventArgs e)
 {
     MCP23S17.WritePin(PFDII.LED6, On);
 }